2017  Kodetalk | Feedback | Privacy Policy | Terms | About
userimage

foreign key must have same number of columns hibernate

When I deploy my hibernate application in server getting below exception,

org.hibernate.MappingException: Foreign key (FK1E21AD3D33D6436848b1c6a0:DEBITCARD_SUBSCRIPTION [ORDERED_FROM])) must have same number of columns as the referenced primary key (BRANCH [UNIQUE_ID,INSTITUTION_ID])

at org.hibernate.mapping.ForeignKey.alignColumns(ForeignKey.java:110)

at org.hibernate.mapping.ForeignKey.alignColumns(ForeignKey.java:93)

at org.hibernate.cfg.Configuration.secondPassCompileForeignKeys(Configuration.java:1714)

at org.hibernate.cfg.Configuration.originalSecondPassCompile(Configuration.java:1637)

at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1355)

at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1737)


But still unable to find out what is wrong with my mapping file.Please suggest!

userimage

By looking into your exceptions its clearly telling that the table DEBITCARD_SUBSCRIPTION contains a foreign key on a column named ORDERED_FROM, but your referenced table, BRANCH , defines it's primary key with two columns UNIQUE_ID and INSTITUTION_ID, which by the way is very common for relationship tables.

Well, if your domain model is really correct, then you need to think about how you want to synchronize your User's FK and GroupRole's PK. For that you might:

  1. Create a PK object for your composite key or define your ID's correctly in your mappings table BRANCH;
  2. Change your PK definition in DEBITCARD_SUBSCRIPTION table.
Answer is