Hello all,
Here is simplified version of what i have:
Code:
class A {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@ManyToOne(optional=false)
private B b;
@Column
private String label;
}
class B {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column
private String name;
}
DAO:
...
public void create(final T entity) {
this.getCurrentSession().persist(entity);
}
public void update(final T entity) {
this.getCurrentSession().merge(entity);
}
...
Basically i have a REST service and often i get A instances populated with B, and B has id only (no B name field):
Assume that in DB i got B.id=1 and B.name="testname";Code:
// A instance
{
label: "test",
b: {
id: 1
}
}
After that i call dao.create method on the backend and return saved a instance (in service layer)
Here is what i got as result:
Code:
// A instance that returned after dao.create
{
id: 11,
label: "test",
b: {
id: 1,
name: null
}
}
So my question is how to force hibernate populate other B information (B name field in this example)?
Excpected:
Code:
// A instance that returned after dao.create
{
id: 11,
label: "test",
b: {
id: 1,
name: "testname"
}
}