JPA hibernate OneToOne mapping
- by Stupidfrog
enviroment:
hibernate 4.1.6.final
spring 3.1.2.release
spring jpa 1.1.0.release
postgresql 9.1-901-1.jdbc4
there is 2 table
public A
{
private Long id;
private Long name;
}
public B
{
private Long id;
private Long table_a_id;
}
the A.id and B.id is sequential, unique , but no related.(means they are separately id for their own table).
how to do mapping?
i have tried some method, however the result is not i wanted, because it bind wrong.
for example:
public A
{
....
@OneToOne
@JoinColumn(name = "id")
private B table_b
}
public B
{
...
@JsonIgnore
@OneToOne(mappedBy = "table_b")
private A table_a;
}
when i query A the result is
{
"id":5,
"table_b":{
"id":5,
"table_a_id":4
}
}
obviously the data join by using their id but not joining using table_a_id.
what i expect is
{
"id":4,
"table_b":{
"id":5,
"table_a_id":4
}
}
so can somebody teach me that, how to map this 2 table by using table b table_a_id(foregin key)