Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate mapping collection of primitives

 
Victor Balanica
Greenhorn
Posts: 5
Eclipse IDE Hibernate Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does anyone have a working example on Hibernate's mapping a collection of primitives with annotations ?
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the Hibernate Documentation


2.2.5.3.3. Collection of basic types or embeddable objects

In some simple situation, do don't need to associate two entities but simply create a collection of basic types or embeddable objects. Use the @ElementCollection in this case.

@Entity
public class User {
[...]
public String getLastname() { ...}

@ElementCollection
@CollectionTable(name="Nicknames", joinColumns=@JoinColumn(name="user_id"))
@Column(name="nickname")
public Set<String> getNicknames() { ... }
}



Mark
 
Victor Balanica
Greenhorn
Posts: 5
Eclipse IDE Hibernate Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, it has been very helpfull
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic