Featured Post

Event Sourcing Video from Michael Ploed

Event Sourcing I want to share a great video I found few days ago that describes very well what Event Sourcing is.

Saturday, June 30, 2012

JPA @ElementCollection

Suppose you have an entity bean called User and this entity has a lot of nicknames. You can make the following mapping:

public class User {

   private int userId;

   private String name;

   private Set nicknames;

   public User() {
      this.nicknames = new TreeSet();


Database point of view

create table User (
        parentId integer not null,
        name varchar(255),
        primary key (parentId)
create table User_nicknames (
        User_parentId integer not null,
        nicknames varchar(255)

alter table User_nicknames 
        add constraint FKA44D16712C2B0AD9 
        foreign key (User_parentId) 
        references User

No comments :

Post a Comment