0

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.

mgurov
  • 63
  • 3
  • 9

1 Answers1

1

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;
JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
  • class Two - is a small example of production version. Real class contains more than one field – mgurov Sep 16 '14 at 10:45
  • Then annotate it with `@Embeddable`, use a `Set` instead of a `Set`, and remove the `@Column` annotation. Your Two class may not have a field of type `One`. – JB Nizet Sep 16 '14 at 10:46
  • Sql output show incorrect column name during insert records into "Two" table: insert into Two (Two_id, property1) values (?, ?) – mgurov Sep 16 '14 at 11:13
  • I solve probjem with adding @CollectionTable(name="Two", joinColumns = @JoinColumn(name = "one_id")) and remove field parent from Two – mgurov Sep 16 '14 at 11:35