Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate mapping List<Integer>

 
Bala Gangadhar
Ranch Hand
Posts: 104
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends,

Can somebody help with hibernate mapping file to map List<Integer>

Example :

Calss Game
int gameId;
String gameName;
List<Integer> playDays;

Tables:
GAME TABLE
GAMEID INT(4)
GAMENAME VARCHAR(10)
....
....
AND PRIMARY KEY IS GAMEID

GAME_DAYS TABLE
GAMEID(4)
PLAYDAY INT(1)

GAMEID,PLAYDAY Together primary key
GAMEID forighn KEY

I know how to map list<objects> like list<student> etc.. but not sure how to map list<String> or list<Integer> can somebody help me...

Thanks
 
Jelle Klap
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could use JPA's ElementCollection annotation for that purpose. There's an example in the API documentation I linked to.
 
Bala Gangadhar
Ranch Hand
Posts: 104
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply. I saw that one. I have been using xml configuration rather than annotations.

Can you we achieve similar mapping using xml configuration.
 
Jelle Klap
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, with <element-collection> in orm.xml. There's an example in the EclipseLink (JPA 2 reference implementation) documentation here.
Oh, and if you're using Hibernate specific .hbm.xml files you can use the <element> mapping.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic