openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Pinaki Poddar <ppod...@apache.org>
Subject Re: Fetchgroups recursion problem
Date Thu, 22 Oct 2009 21:32:21 GMT

Hi,
There are two attributes that control the closure of a graph as fetched by a
FetchPlan/FetchConfiguration, namely
   Recursion Depth 
   Max Fetch Depth

According to the cited use case, Max Fetch Depth is the relevant attribute
that will control depth of traversal from a root entity (s1). By default,
the max fetch depth is set to 1 and hence the immediate neighbors of s1 are
fetched and not s4 or s5 which is at depth 2 from s1. 

Recursion depth, on the other hand, controls the depth of traversal for
recursive relation on types. If s1 had a recursive relation then recursion
depth would have controlled traversal of that relation path.




calin014 wrote:
> 
> 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? 
> 


-----
Pinaki 
-- 
View this message in context: http://n2.nabble.com/Fetchgroups-recursion-problem-tp3874382p3875149.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Mime
View raw message