Reputation: 53
I have 2 simple tables in database. They look like:
T1 T2
ID NUMBER Primary key ID NUMBER Primary key & Foreign key from T1
Value VARCHAR Value VARCHAR
How does hibernate entity for T2 look like? I tried to do it with @Embeddable class containing T1 mapped-class object but this doesn't work. Thanks.
UPD: the full use case when I need such a structure is below: I have business entities tables, containing some data for specific business users, and Company table with Id and value fields too, and I want to create CompanyToBEntity table, containing data about what company can access what object.(objects are any row of bus.entities).
So I think this structure fits this case.
pic describing it better:
Upvotes: 2
Views: 8162
Reputation: 6158
You can try Unidirectional one-to-one association vi primary key association
something like -
T1 Mapping
@Id
@Column(name="ID")
private Integer ID;
T2 Mapping
@OneToOne(cascade=CascadeType.ALL)
@PrimaryKeyJoinColumn
private T1 t1;
For more reference you visit here, the example is based on hbm.xml
Upvotes: 1