the python info is below.
http://code.google.com/appengine/docs/python/datastore/entitiesandmodels.html#References
the part i am interested in is called 'back references'
ReferenceProperty has another handy feature: back-references. When a
model has a ReferenceProperty to another model, each referenced entity
gets a property whose value is a Query that returns all of the
entities of the first model that refer to it.
# To fetch and iterate over every SecondModel entity that refers to
the
# FirstModel instance obj1:
for obj in obj1.secondmodel_set:
# ...
i assume that the java sdk has similar features to the python sdk. is
that correct?
-lp
On Nov 13, 5:37 pm, lp <[email protected]> wrote:
> hi there
>
> i am porting a python GAE to java but have come unstuck with self
> reference type.
> my existing data model uses the SelfReferenceProperty and it allow me
> to do a very powerful query in a simple manner.
>
> Python model
> ----------------------
> class PositionUser(db.Model):
> user = db.UserProperty()
> latitude = db.FloatProperty()
> longitude = db.FloatProperty()
> name = db.StringProperty()
> friend = db.SelfReferenceProperty( collection_name='friend_user' )
>
> Query
> -------
> userRef = Model.PositionUser.gql("where user=:1", user).get()
>
> positions = user.friend_user.filter('latitude>',minLat).filter
> ('latitude <', maxLat)
>
> However when porting to java, i am unable to achieve the 'collection
> filter' that was available in python.
>
> currently i am using the familiar JPA.
>
> i have implemented the sefReference property as a @OneToMany.
>
> my model is below
>
> JPA
> ----------
> @Entity
> public class PositionUser {
>
> �...@id
> @GeneratedValue(strategy = GenerationType.IDENTITY)
> private Key key;
> User user;
> String latitude;
> float longitude;
> @OneToMany
> Collection<PositionUser> friends ;
>
> But i am unable to achieve the same query result.
>
> PositionUser positionUser = em.find(PositionUser.class, user1.getKey
> ());
>
> but now how to filter positionUser.friends based on their latitude?
>
> any help is appreciated
> -lp
--
You received this message because you are subscribed to the Google Groups
"Google App Engine for Java" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-appengine-java?hl=.