Solved

Hibernate composite key/FK error

Posted on 2009-05-13
2
433 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Question has a verified solution.

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

If your app took Google’s lash recently, here are the 5 most likely reasons.
Invest in your employees with these five simple steps to improve employee engagement and retention.
Using Adobe Premiere Pro, the viewer will learn how to set up a sequence with proper settings, importing pictures, rendering, and exporting the finished product.
XMind Plus helps organize all details/aspects of any project from large to small in an orderly and concise manner. If you are working on a complex project, use this micro tutorial to show you how to make a basic flow chart. The software is free when…

734 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