openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From calin014 <calin...@gmail.com>
Subject Fetchgroups recursion problem
Date Thu, 22 Oct 2009 19:13:22 GMT

I have the following entities:

@Entity
public class Flow implements Serializable {
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Long id;

	@Column(length = 64)
	private String name;

	@OneToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE,
CascadeType.REFRESH })
	@JoinColumn(name = "INITIAL_STATE")
	private State initialState;
}

@Entity
@FetchGroups( {
		@FetchGroup(name = "State_OutgoingTransitions", attributes = {
@FetchAttribute(name = "outgoingTransitions") }),
		@FetchGroup(name = "State_IncomingTransitions", attributes = {
@FetchAttribute(name = "incomingTransitions") }) })
public class State implements Serializable {
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Long id;

	@Column(length = 64)
	private String name;

	@OneToMany(mappedBy = "fromState", cascade = { CascadeType.PERSIST,
CascadeType.MERGE, CascadeType.REFRESH })
	private List<Transition> outgoingTransitions;

	@OneToMany(mappedBy = "toState", cascade = { CascadeType.PERSIST,
CascadeType.MERGE, CascadeType.REFRESH })
	private List<Transition> incomingTransitions;
}

@Entity
public class Transition implements Serializable {
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Long id;

	@Column(length = 64)
	private String name;

	@ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE,
CascadeType.REFRESH })
	@JoinColumn(name = "FROM_STATE_ID", referencedColumnName = "ID")
	private State fromState;

	@ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE,
CascadeType.REFRESH })
	@JoinColumn(name = "TO_STATE_ID", referencedColumnName = "ID")
	private State toState;
}

This is supposed to be the persistence model for a graph-like data
structure.

I have an issue with fetch groups when using them to load the whole data
structure from the database for cases involving recursion like the
following:

This is what is persisted to the db:
http://n2.nabble.com/file/n3874382/1.jpg 

This is what gets loaded into memory:
http://n2.nabble.com/file/n3874382/2.jpg 
Transition tr24 and tr34 get loaded with a null reference on 'toState'
field.

I can load the whole thing using lazy loading but i have to keep a user
transaction the whole request(web app).Not to mention that i have to call
some getters just to load the properties from db to use them on next
requests.

I tried setting the recursion depth to a greater value although i read it is
supposed to be infinite by default. Seems like a openjpa bug. Am i missing
something? 
-- 
View this message in context: http://n2.nabble.com/Fetchgroups-recursion-problem-tp3874382p3874382.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Mime
View raw message