Solved

Hibernate composite key/FK error

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
throw exception 21 69
Veriface disable 2 39
Is there any tracking software that would create a report how long the user spent on applications? 3 39
moto 4g plus phone apps 5 51
A list of useful business intelligence software.
This guide will walk you through the essential considerations and tech stack for building scalable websites. Know how to grow your business the smart way!
This video demonstrates basic masking and how to edit the mask to reveal the desired image.
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…

726 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