cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Steve Wells" <>
Subject Re: Current thread has no bound DataContext (zk integration)
Date Mon, 25 Aug 2008 03:48:53 GMT
The way I seem (seem as I am yet to *fully* test this) to have solved that
is to use Spring to create the ObjectContext and then you inject that in to
whatever else you want.  This will not be Thread bound but Singleton, I
guess in Spring you could write (or copy) a Thread bound scope if required.
  <bean id="myObjectContext" class="org.apache.cayenne.access.DataContext"
  factory-method="createDataContext" scope="singleton">
  <constructor-arg value="MyDomain"/>
<!-- A data layer controller/convenience function layer -->
<bean id="dataServices" class="com.mypackage.dataservices.DataServices">
  <property name="objectContext">
  <ref local="myObjectContext"/>
public class DataServices {
  private ObjectContext objectContext;

  public ObjectContext getObjectContext() {
  return objectContext;

  public void setObjectContext(ObjectContext objectContext) {
  this.objectContext = objectContext;

2008/8/23 mambo <>

> I've been looking through the mailing list and I can't find a definite
> answer. I'm using ZK, I have added:
> <filter>
>           <filter-name>CayenneFilter</filter-name>
> <filter-class>org.apache.cayenne.conf.WebApplicationContextFilter</filter-class>
>             </filter>
>       <filter-mapping>
>            <filter-name>CayenneFilter</filter-name>
>            <url-pattern>/*</url-pattern>
>  </filter-mapping>
> to my web.xml. When I try "DataContext context  =
> DataContext.getThreadDataContext();" I get an exception that says "Current
> thread has no bound DataContext". I'm figuring this is because ZK is multi
> threaded. I'm pretty new to Java so I'm not really comfortable trying to
> hack the cayanne source to get things to run. Is there a solution for this?
> If i created a new Datacontext with each Database request, how badly would
> that affect performance of my web app?

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message