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.
eg:
<bean id="myObjectContext" class="org.apache.cayenne.access.DataContext"
factory-method="createDataContext" scope="singleton">
<constructor-arg value="MyDomain"/>
</bean>
<!-- A data layer controller/convenience function layer -->
<bean id="dataServices" class="com.mypackage.dataservices.DataServices">
<property name="objectContext">
<ref local="myObjectContext"/>
</property>
</bean>
public class DataServices {
private ObjectContext objectContext;
public ObjectContext getObjectContext() {
return objectContext;
}
public void setObjectContext(ObjectContext objectContext) {
this.objectContext = objectContext;
}
HTH
Steve
2008/8/23 mambo <ikonicpattern..mail.com>
> 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?
>
This archive was generated by hypermail 2.0.0 : Sun Aug 24 2008 - 23:49:35 EDT