I have a Hibernate entity Parent
that is joined to another: Child
. In the database I have a column parent.child_id
that has a foreign
It's caused by the fact that Child
uses field access (since annotations are placed on fields), therefore Hibernate simply initializes the proxy when you call any of its methods.
If you move annotations to properies, it would work as expected.
Since JPA 2.0 (Hibernate 3.5) you can configure it in fine-grained way:
@Access(AccessType.FIELD) // Default is field access
class Child {
private Integer id;
@Column(name = "name")
private String name;
@Access(AccessType.PROPERTY) // Use property access for id
@Id @Column(name = "id", unique = true, nullable = false)
public Integer getId() { ... }
...
}