Skip to main content

@OneToMany empty set

2 replies [Last post]
chris_lenz
Offline
Joined: 2004-07-02

ok I have three classes
Staat <1---*> Land <1---*> Bezirk

If I make the following for a specific Land

<br />
		Land l=remoteLookupLand().findById(1L, false);<br />
		System.out.println(l.getName());<br />
		System.out.println(l.getStaat().getName());<br />
		for (Bezirk b : l.getBezirks()) {<br />
			System.out.println(b.getName());<br />
		}<br />

I get a Staat but no Bezirks.

Here my annotations:
//Staat
@OneToMany(mappedBy="staat", cascade=CascadeType.MERGE,fetch=FetchType.EAGER)
public Set< Land > getLands()
//Land
@OneToMany(mappedBy="land", cascade=CascadeType.MERGE,fetch=FetchType.EAGER)
public Set< Bezirk > getBezirks()
@ManyToOne(cascade=CascadeType.MERGE,fetch=FetchType.EAGER)
public Staat getStaat()
//Bezirk
@ManyToOne(cascade=CascadeType.MERGE,fetch=FetchType.EAGER)
public Land getLand()

Thanx Chris

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
mvatkina
Offline
Joined: 2005-04-04

Hi Chris,

Did you create those instances in the same application? If yes, did you assign relationships from both sides? There are no managed relationships in JPA, and to have an application that behaves the same on all persistence providers, you need to maintain those relationships yourself (some providers might help you there).

Regards,
-marina

chris_lenz
Offline
Joined: 2004-07-02

Thanx, that was my problem :-).
Thanx a lot.

Chris