This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes Map an object that has composite id containing a mapping to object that itself has composite id? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Map an object that has composite id containing a mapping to object that itself has composite id?" Watch "Map an object that has composite id containing a mapping to object that itself has composite id?" New topic
Author

Map an object that has composite id containing a mapping to object that itself has composite id?

Yaki Kumar
Greenhorn

Joined: Feb 01, 2010
Posts: 12

I have an Employee identified by employeeNo, and want Project to be identified by projectName, and startDate - starting date of project. Also I want to save information of employees on projects. Hence I made another class EmployeeProjectInfo and want it to be identified by Employee, Project and startDate - which happens to be the date on which he started on that project.

Here is my failed attempt of hibernate mapping for Project class. I want Project to be uniquely identified by projectName and startDate (Composite Keys).


Here is what I tried for mapping EmployeeProjectInfo class. This class is supposed to hold Employee and Project he has been on. I want this to be identified by Employee, Project and startDate - when he started on the particular project. Now, this mapping as it is, has a key-many-to-one element as Project which itself has a composite id. Is there some way that I can have a my EmployeeProjectInfo identified by Employee, Project and statDate (when employee started on the project). Project is identified by projectName, and startDate of Project.


I get error

org.hibernate.MappingException: Foreign key (FKC3DDB2345834AA5C:PROJECT_INFO [PROJECT_REF_NAME])) must have same number of columns as the referenced primary key (PROJECTS [PROJECT_NAME,START_DATE]) at org.hibernate.mapping.ForeignKey.alignColumns(ForeignKey.java:90) at org.hibernate.mapping.ForeignKey.alignColumns(ForeignKey.java:73) at org.hibernate.cfg.Configuration.secondPassCompileForeignKeys(Configuration.java:1263) at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1170) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1286)

I guess the problem is that I am trying to have an Project inside composite-id which itself has a composite-id.
How to get around this?
Or is this design really bad?

I am a beginner at Hibernate and ORM, so it would be nice if I can get some explanations too.

Thanks a lot.
Yaki Kumar
Greenhorn

Joined: Feb 01, 2010
Posts: 12

Solved it. Just had to add another column there.



Thanks!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Map an object that has composite id containing a mapping to object that itself has composite id?
 
Similar Threads
Foreig key must have same number of columns as the referenced primary key
Foreign key in hibernate
An association from the table "dependent" refers to an unmapped class: "Independent"
Problem with Hibernate composite key mapping
left outer join *= how make compitible in HQL