I got classes:
@Entity
@Table(name="users")
public class User{
private Integer id;
private String name;
private Address address;
}
and:
@Entity
@Table(name="adress")
public class Adress{
private Integer id;
private String street;
(...)
}
Any way how to map relation @ManyToOne (many users can have the same adres), BUT I don't want to have property List< User > users in my Address class?
Many-To-One relation between entities: Where one entity (column or set of columns) is/are referenced with another entity (column or set of columns) which contain unique values. In relational databases these relations are applicable by using foreign key/primary key between tables.
According to book Pro JPA 2 the main difference between unidirectional @ManyToOne and @OneToOne is that in @OneToOne: Only one instance of the source entity can refer to the same target entity instance. In other words, the target entity instance is not shared among the source entity instances.
Add the annotation @ManyToOne
to the address field. Problem solved. For details on how this can be customized, see the Hibernate reference manual. Typically you would use
@ManyToOne
@JoinColumn(name = "addressId")
private Address address;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With