Search code examples
javahibernateembeddable

Hibernate embeddable list


I have two ready tables:

Table "One"
id numeric (PK);
name varchar(100); 

Table "Two"
property1 varchar(100);
one_id long;

I want map two classes for it tables:

class One 
{
long id;
String name;
}

Two
{
  One parent;
  String property1;
}

If I add List<Two> properties into One class, what annotations I must add to it? Class 'Two' marks as Embeddable. Modification of tables is deprecated.


Solution

  • You don't need a class Two at all. What you need in class One is

    @ElementCollection
    @Column(name = "property1")
    @JoinColumn(name = "one_id")
    private Set<String> properties;