Featured Post

NoSQL use cases

Here are a simple summary of use cases for Cassandra, MongoDB and Redis MongoDB Storing Log Data Speed is the primary perfor...

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