cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrus Adamchik <and...@objectstyle.org>
Subject Re: Getting null instead of the actual value
Date Fri, 16 Sep 2011 09:14:00 GMT

On Sep 16, 2011, at 11:22 AM, Christian Grobmeier wrote:

> 
> ObjectContext ctx = // get context
> 
> User user = ctx.newObject(User.class);
> 
> ObjectContext ctx = // get another context (from ThreadLocal - should
> be the same?)

If this whole piece of code is from the same request, and the first context is obtained from
ThreadLocal, then the contexts should be the same. (A potential race condition - how did the
context got into ThreadLocal in the first place? If it comes from the session, multiple request
threads can get the same context, if the user clicks quickly or there's lots of AJAX calls
on the pages).

> After your explaination my guess is that I am not allowed to call this:
> BaseContext.getThreadObjectContext();
> twice before I commit. Does this make sense?

No, you can call getThreadObjectContext as many times as you need. You get the same context
within request, which is probably what you want.


> <query name="getUserRole"
> factory="org.apache.cayenne.map.SelectQueryBuilder" root="obj-entity"
> root-name="Role">
> 	<property name="cayenne.SelectQuery.distinct" value="true"/>
> 	<property name="cayenne.GenericSelectQuery.cacheStrategy"
> value="SHARED_CACHE"/>
> 	<qualifier><![CDATA[name = "user"]]></qualifier>
> </query>

This query fetches Roles, not UserRoles. From your earlier messages, you were actually looking
for UserRoles, and then traversing relationships to Roles from them, no?

Andrus
Mime
View raw message