Solved

Hibernate composite key/FK error

Posted on 2009-05-13
2
417 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
count11 challenge 6 47
wordlen challenge 3 46
Win 7 OS unable to install Win updates 3 85
Ransomware attacks 5 55
I previously wrote an article addressing the use of UBCD4WIN and SARDU. All are great, but I have always been an advocate of SARDU. Recently it was suggested that I go back and take a look at Easy2Boot in comparison.
A list of useful business intelligence software.
Video by: Tony
This video teaches viewers how to export a project from Adobe Premiere Pro and the various file types involved.
An overview on how to enroll an hourly employee into the employee database and how to give them access into the clock in terminal.

708 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

17 Experts available now in Live!

Get 1:1 Help Now