Hello,
I have a class Person that i want to persist via hibernate.
The class has several attributes like name, firstname, and so on.
Code:
@Entity
@Table(name = "PERSON")
public class Person {
/**
* serial id
*/
private static final long serialVersionUID = 8924573169941152854L;
private final static transient String SIMPLE_NAME = Person.class.getSimpleName();
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long uuid;
@OneToOne(optional = false, cascade = CascadeType.ALL)
@JoinTable(name = "PERSON_TO_NAME")
private StringModelItem name = new StringModelItem();
@OneToOne(optional = false, cascade = CascadeType.ALL)
@JoinTable(name = "PERSON_TO_FIRST_NAME")
private StringModelItem firstName = new StringModelItem();
@Column(name = "GENDER", nullable = false, unique = false)
private GenderType gender;
@Column(name = "FAMILY_STATUS", nullable = false, unique = false)
private FamilyStatusTyp familyStatus;
@Column(name = "DATE_OF_BIRTH", nullable = false, unique = false)
private Date dateOfBirth;
....
};
I am using for name and firstname a class StringModelItem that holdes besides the name value as String,
several transient meta data.
Code:
@Entity
@Table(name = "STRING_MODEL_ITEMS")
public class StringModelItem {
/**
* serialVersionUID
*/
private static final long serialVersionUID = -1;
@Column(name = "VALUE", nullable = false, length = 20, unique = false)
private String value;
...
};
I need this structure for several reasons. But i do not like the jointable assignment for that attributes.
Best would be to configure hibernate in a way, that the attribute name will be stored in the PERSON-table
and the jointable will not be needed. It is not important using Annotations or a config file.
I just need the StringModelItem class as attribute type and want to store a value from that class in the Person-table.
Loading from that table should also work.
Is this possible?? Anyone can help??