• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
reply
    Bookmark Topic Watch Topic
  • New Topic