i've got two Entities with combinded primarky keys:
@Entity
@IdClass(APK.class)
public class A {
@Id
Integer pk1;
@Id
Integer pk2;
@OneToMany(cascade = CascadeType.ALL, fetch=FetchType.EAGER,mappedBy="a")
List<B> b = new ArrayList<B>();
String name;
...
}
@Entity
@IdClass(BPK.class)
public class B {
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumns({
@JoinColumn(name = "pk1", referencedColumnName = "pk1"),
@JoinColumn(name = "pk2", referencedColumnName = "pk2")
})
@Id
private A a;
@Id
Integer additional_key_part;
}
When i load the "A" class, the List is correctly loaded eagerly, the problem is, it does not work when i load the "B" class.
The "B" class will correctly use an Join with A, but only the PK fields of A will be populated (pk1, pk2), not the rest.
The real problem comes when the entity is send to a client which has no transaction, so no lazy loading possible. The only thing that seemed to work is to call a.getName() or something to start the lazy loading before closing the transaction, but this seems not really the correct way.
So, how to make sure the entity and all its childs are loaded ?