Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

How could I map this if possible?

 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I knew that guy would be trouble! Thanks tiny ad!
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic