my dog learned polymorphism*
The moose likes Object Relational Mapping and the fly likes Composite foreign key causing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Composite foreign key causing "object is not an instance of declaring class"?" Watch "Composite foreign key causing "object is not an instance of declaring class"?" New topic
Author

Composite foreign key causing "object is not an instance of declaring class"?

Adam Janz
Greenhorn

Joined: Sep 19, 2008
Posts: 1
I am using hibernate mapping files to map a couple of classes - twice. I have 2 classes: Event and SubEvent. SubEvent is a child of Event. I am having an issue with the mappings that are using a composite foreign key. When attempting to persist, I am consistently getting an exception with the message: "object is not an instance of declaring class" -- More information provided below.

My java classes look like this:



and SubEvent:



I have two mapping files for the Event class:

Event.xml:




And the other mapping file:
EventHistory.xml:



SubEvent also has two mappings:

SubEvent.xml:



And SubEventHistory.xml:



I am persisting events (with children subevents) and event histories (with children subevent histories) using 2 sessions.

I'm using the hibernate entity manager for persistence. My persistence.xml looks like this:


My persistence code looks similar to this:



As noted above, the line "em2.persist(event)" is throwing an exception. The stack is posted below:



As I said above, I really think this has something to do with the fact that the EventHistory.xml and SubEventHistory.xml uses a composite foreign key. When I removed the composite foreign key and simply used eventId as the foreign key, the code worked as expected. If anyone has any advice for me on what could be causing this I would greatly appreciate it, or if there is a better way to accomplish this same result. I'm not very familiar with using the hibernate mapping files. I was able to successfully use a composite foreign key as described above using JPA annotations (using @OneToMany and @ManyToOne annotations) and now that I am trying to switch over to hibernate mapping files I cannot get past this issue. Oh and before I forget, I am using hibernate-entitymanager-3.4.0.GA. Thanks in advance!
[ September 19, 2008: Message edited by: Adam Janz ]

Adam Janz
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Composite foreign key causing "object is not an instance of declaring class"?
 
Similar Threads
Hibernate Repeated column mapping problem
Please suggest on this Mapping
Please explain me the hibernate generated sql queries in console
Mapping Exception
Collection of values question