I have a problem with setting up some hibernate annotations in my entity classes.
My question is: How can I tell Hibernate, that it should store the Address, Name and Customer information in just one table. This table should have the following columns: ID, Given, Surname, Street, HouseNumber, Zip, City, Phone, Comment. At the moment Hibernate generates for each entity a single table in the mysql database. Therefore it is necessary to define an @Id in each entity class (Customer, Name, Address). But I want to keep all the information in one table with just one @Id for the customer.
How can I solve this problem?
Below you can find an extract of the Customer, the Name and the Address entity classes:
@Entity
@Table(name = "customer")
@XmlRootElement
public class Customer {
@Id
@GeneratedValue
private int id;
@OneToOne
private Name name;
@OneToOne
private Address address;
private String phone;
private String comment;
public Customer() { }
}
@Entity
@XmlRootElement
public class Name {
private String given;
private String surname;
public Name() { }
}
@Entity
@XmlRootElement
public class Address {
private String street;
private String houseNumber;
private String zip;
private String city;
public Address() { }
}