Adam Janz

Greenhorn
+ Follow
since Sep 19, 2008
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Adam Janz

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 ]