cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joe Baldwin <>
Subject Re: cayenne wicket unit test => Current thread has no bound ObjectContext
Date Thu, 22 Apr 2010 14:41:39 GMT

The recommendation has been to transition to using the BaseContext in place of the older DataContext
class methods.  (Ironically, it appears that the Cayenne 3.x docs have not all been updated
and so in some places they show examples of BaseContext and some show examples of DataContext.
This can be confusing.)

The proper method for initializing your ObjectContext depends on whether you are intending
to create a stand-alone app, or you are creating a web app (i.e. a ServletContainer).  I am
assuming from the error message that you have created a stand-alone app.  If so, then you
should do the following:

1. Instantiate a DataContext.
2. Bind it using BaseContext.
3. Access later via the BaseContext class method
4. Execute queries using the returned objectContext (which in this case is really a DataContext

Create some SelectQuery here

ObjectContext oc = BaseContext.getThreadObjectContext();
List list = oc.performQuery(query);

Please refer one of my previous emails to you and you will see an example of using the BaseContext.

Try this out, I think you will get better results.

On Apr 22, 2010, at 10:00 AM, Arnaud Garcia wrote:

> Hello,
> I am working on a Wicket Cayenne application and when I launch the tests I
> have an error when the DataContext is initialized:
> This line, DataContext ctxt = (DataContext)
> DataContext.getThreadObjectContext();  throws an
> java.lang.IllegalStateException: Current thread has no bound ObjectContext
> Well, any ideas to set up correctly the tests ?
> thanks
> Arnaud

View raw message