cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mike Kienenberger <mkien...@gmail.com>
Subject Re: Different DataContext
Date Wed, 22 Jul 2009 12:39:44 GMT
If you know that Person is not in a modified state, you can make a
local copy of Person in your nameObj's data context.   (If person is
modified, then you will lose those changes in the nameObj dataContext,
which still may not be a problem unless person is in a NEW state)  I
don't remember if there's a convenience method for it in 2.0, but for
1.1 the code was:

       localPerson = getLocalObject(nameObj.getDataContext(), person);

	public static DataObject getLocalObject(DataContext context, DataObject obj)
	{
		if (null == obj)  return null;
		
		if (obj.getDataContext() != context)
		{
			List localObjectList = context.localObjects(Arrays.asList(new
Object[] { obj } ));
			return (DataObject)localObjectList.get(0);
		}
		return obj;
	}


http://cayenne.apache.org/doc20/api/cayenne/org/apache/cayenne/access/DataContext.html#localObjects(java.util.List)

http://cayenne.apache.org/doc20/api/cayenne/org/apache/cayenne/access/DataContext.html#localObject(org.apache.cayenne.ObjectId,%20org.apache.cayenne.Persistent)

Glancing through the 2.0 api docs, it looks like you can use the above
localObject() and create modified and new state objects as well.
However, I don't recommend doing so because having the object marked
as modified or new in two separate contexts is going to cause problems
when you commit the second context.  As long as you know that person
is not a new object, localObjects() is still your best bet -- or
localObject() with a null prototype.



On Wed, Jul 22, 2009 at 7:42 AM, Emanuele Maiarelli<evvdrak@yahoo.it> wrote:
> I think the problem is there:
>
>    DataContext mycontext = Databinder.getContext();
>    person = ObjectFactory.getInstance().getPerson(parameters.getInt("personid"),
> mycontext);
>
> 'mycontext' isn't the same context of the one ObjectFactory is using , u should share
the same context between
> Wicket and your Singleton.
>
> I hope this will solve,
>
>
>
>
>
>
>
>
> ________________________________
> Da: Reinout van Schouwen <reinout@gmail.com>
> A: user@cayenne.apache.org
> Inviato: Mercoledì 22 luglio 2009, 13:32:29
> Oggetto: Re: Different DataContext
>
> Hello Emanuele,
>
> Thanks for your reply.
>
> 2009/7/22 Emanuele Maiarelli <evvdrak@yahoo.it>:
>
>>  i'm not an apache Wicket expert, but the Exception its obiusvly casted by
>> the fact that ur application is casting objects into different DataContexts.
>
> Yes, but I have no idea how that could happen.
>
>>  What happen if u steps into
> (...)
>
> This part of the code works fine. It's the 'else' case that causes the
> exception.
>
> Regards,
>
> --
> Reinout van Schouwen
> http://vanschouwen.info/
>
>
>
>

Mime
View raw message