Composite foreign key causing "object is not an instance of declaring class"?
posted 8 years ago
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.
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 ]