0

I have problem with composite primary key and Foreign key having the same column name.

Example

Table A PK (ID , NEW_ID)

Table B PK (ID, NEW_ID) FK (A_ID, NEW_ID)

I have the relationship of Entity B mapped to A in this way

@ManyToOne
@JoinColumns({@JoinColumn(name = "A_ID", referencedColumnName = "ID"),
    @JoinColumn(name = "NEW_ID", referencedColumnName = "NEW_ID")})

When I try to save B. I am getting an error of invalid Index.

So I am guessing it was also trying to set NEW_ID two times and getting this error.

I have no option to set one column as insertable and updatable as false.

Can any one help me in this

mohan
  • 239
  • 2
  • 3
  • 11

1 Answers1

0

One tip i can share is make the hibernate.hbm2ddl.auto=create and see what hibernate is doing , this will help you to debug , moreover make the show_sql=true , you will surely understand what this configuration will result into.

Please refer to http://docs.jboss.org/hibernate/annotations/3.5/reference/en/html/entity.html for details about annotation usage

Thanks Abhi

abhi
  • 621
  • 1
  • 6
  • 17