Solved

Hibernate composite key/FK error

Posted on 2009-05-13
2
420 Views
Last Modified: 2015-01-05
I ended up with this error and couldn't figure out why..need some ideas to solve this..

 org.hibernate.MappingException: Foreign key (FKC4944AB4EC08D0E:CP_PROJ_CAND_USID [candidates_PROJ_NO_SEQ,candidates_SLT_USIDIDENTITY])) must have same number of columns as the referenced primary key (CP_PROJ_CAND_USID [PROJ_NO_SEQ,candidates_PROJ_NO_SEQ,candidates_SLT_USIDIDENTITY])


 <composite-id class="com.xxx.yyy.zzz.CpProjCandUsid$CompositeId"  name="compositeId">
      <key-property type="java.lang.Long" column="PROJ_NO_SEQ" length="10" name="projNoSeq"/>
      <key-property type="java.lang.Long" column="SLT_USIDIDENTITY" length="10" name="usid"/>
    </composite-id>
<many-to-one not-null="true" name="project" class="com.xxx.yyy.zzz.Project" insert="false" update="false">
0
Comment
Question by:praveen009
2 Comments
 
LVL 2

Accepted Solution

by:
jocafi earned 500 total points
ID: 24384798
What are u trying to do? A Bilateral-Association between 2 tables ?

I read the Hibernate manual and they say it is a bad strategy to use <composite-id>. Therefore, if you can design better your database model you are lucky.

I understood that you want a table that has the user ID and project ID, correct ?

Try to use Uni-Directional Association or Bi-Directional Association. In the hbm file of the user you write:

    <set name="userProjects" table="UserProjects">
      <key column="SLT_USIDIDENTITY"/>
      <many-to-many class="com.xxx.yyy.zzz.Project" column="PROJ_NO_SEQ"/>
    </set>

It creates automtically a new table called UserProjects that has the user id and project id as primary key.

If you want a bi-directional association do the same in the hbm file of the project:

    <set name="userProjects" table="UserProjects">
      <key column="PROJ_NO_SEQ"/>
      <many-to-many class="com.xxx.yyy.zzz.User" column="SLT_USIDIDENTITY"/>
    </set>

More info under:
http://www.guruja.co.cc/index.php/Hibernate#Mapping_associations
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A list of useful business intelligence software.
Developer portfolios can be a bit of an enigma—how do you present yourself to employers without burying them in lines of code?  A modern portfolio is more than just work samples, it’s also a statement of how you work.
Viewers will learn how to use the Hootsuite Dashboard.
The viewer will learn how to successfully download and install the SARDU utility on Windows 8, without downloading adware.

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now