GeeCON Prague 2014*
The moose likes Object Relational Mapping and the fly likes How could I map this if possible? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "How could I map this if possible?" Watch "How could I map this if possible?" New topic
Author

How could I map this if possible?

Jonny Andersson
Ranch Hand

Joined: Sep 07, 2004
Posts: 87
I am rather new to Hibernate and am trying to persist and load an class with an encapsulated map. It does not work and I guess I am doing something wrong in the mapping of the two involved classes. But I think it should be easy and it would be great if someone who knows could show me how it should be mapped to save me all the time to find it out myself using trial and error.

I have two classes something like these:



When I do a session.save(aContainerObject) do I want the Container object to be saved together with all the ContObjects contained in the map with correct foreign key revision set to the id of the newly saved Container object. May that be possible and if so, how should then the two .hbm.xml-files look like? Particularly, I use the workOrder (from column orderstring) as map key but it does not work as a primary key because it may not be unique. Here is one of my tries so far ...

Container.hbm.xml



ContObject.hbm.xml



In the database do I have the columns id and create_time for a Container record and values for both columns is automatically generated in an insert which works fine. The table ContObject has the columns id, revision, orderstring and otherString. The id is an auto increment and the revision is a foreign key to a Container record through the id of that record.


Truly agile Java application developer with Extreme Programming and high quality craftsmanship
 
GeeCON Prague 2014
 
subject: How could I map this if possible?