Two options for fetching data are possible: FetchType.EAGER and FetchType.LAZY. Collections are loaded EAGER when they are fetched fully at the time their parent is fetched. That is, with nested classes the whole class hierarchy is fetched, even if all the subentities (children) are not needed.
With the LAZY option, data is loaded on-demand, e.g. when a certain entity is requested explicitly. Thus, when the parent entity is loaded with the lazy option, the children entities are not loaded per default. Only in case they are really needed (e.g. a certain method was called via GUI).
Here is an example how entities are marked to be loaded lazily:
@Entity
public class Parent {
@Id
private String id;
private String name;
@OneToMany(fetch = FetchType.LAZY)
private List children;
// etc.
}
the thread does not see the record because the test runs inside a transaction that is not committed yet. since the transaction is bound to the executing thread the task that is forked does not use the same transaction. in order for this to work the insert must run in a method that is annotated with @Transactional(propagation = REQUIRES_NEW). please note that transactional rollback will not work then though
Actually it seems that I was working with an outdated version of Hibernate. In a new release from summer 2008 (Hibernate Entity Manager 3.4.0) they solved the problem, that entities could not be found when the path contained whitepaces, along with some other problems. Therefore the easy solution is to update your current Hibernate version to at least version 3.4.x.