java - Hibernate Many to one Mapping with different Number of columns -


hi have 2 tables below

table1:

      +-------------------+     | id  lob col1 col2 |     +-------------------+  

primary key (id , lob)

table2:

      +-----------------+     | sk id col3 col4 |     +-----------------+  

primary key (sk)

i need give many 1 relation table 2 table1, since table1 has compositeprimarykey(id , lob) table2 not have any column related lob. unable provide mapping. please on this.

edit have tried hibernate mapping table2:

<many-to-one name="class1obj" class="com.acs.enterprise.common.class1"              lazy="proxy" insert="false" update="false">     <column name="id" />     <column name="lob" /> </many-to-one> 

the above not working. while fetching record tries fetch lob code table2 not @ exist in table1

assuming table2.sk fk table1.id , there no table1 entries having same id, write mapping follows:

@manytoone @joincolumn(name = "id", insertable = false, updatable = false) private class1 class1obj; 

if there more table1 rows same id, mapping fail because child matched multiple parents.

so, proper many-to-one association need fk parent column that's unique.


Comments