Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate simple Country mapping

 
Rene Forgues
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,

I'm trying to do something really simple. Let be a table MusicBand, a table ShowEvent and a table Country (populated with all the countries in the world). The table are defined like this :

I have set up a little jsf page (with PrimeFaces) where I have a simple form allowing me to add ShowEvent for an alerady existing MusicBand. The ShowDate is selected from a PrimeFaces calendar component and the ShowCountry is selected from a PrimeFaces oneSelectMenu. The oneSelectMenu lists all the countries in the table Country (itemLabel = Country.CountryName and itemValue = Country.idCountry).

The ShowEvents added with this form are collected through a PrimeFaces collector component (see http://www.primefaces.org/showcase/ui/collector.jsf). This PrimeFaces object requires a List and an Object, respectively a variable List<ShowEvent> showEvents and a variable ShowEvent showEvent. I later have a Save button to save all the collected showEvents to the database (it saves the ShowEvent collection for an already specified MusicBand)

How should I map a relation like this with Hibernate if I wand to avoid something like :

Main goal is to be able to intialize the ShowCountry without loading a Country class. In fact, I would like to use the itemValue from the oneSelectMenu directly.


Thank you for reading!

Rene
 
Bill Gorder
Bartender
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe I am misunderstanding something here. Since you are using session.load, you are not going to hit the database unless you try to access one of the accessors on the country object (other than id) and then only if you don't have the object in your cache, so I am unclear what you mean by 'without loading a Country class'

Anyway I will also add this the JSF forum. I am not a JSF expert but maybe someone there can provide you with a better way to do things.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic