posted 11 years ago
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.