Going out on a limb here ... :-)

I looked at:

http://t5cayenne.saiwai-solutions.com/apidocs/com/googlecode/tapestry5cayenne/services/ObjectContextProvider.html

It seems to me you were perhaps injecting the wrong thing into your init()?
 Maybe this instead:

@Startup
public void init(ObjectContextProvider provider) { ... }

(Don't mix DataContext with ObjectContextProvider.)

You can then say provider.newContext(), assuming it passed the correct
service in.  Then you could have:

DataContext context = provider.newContext();
context.getEntityResolver().getCallbackRegistry().addListener(new
LastModifiedListener());
context.getParentDataDomain().addFilter(new ChangeSetFilter());


I don't think you need to shutdown your runtime.

mrg


On Fri, Nov 23, 2012 at 11:04 AM, <devnull2...@gmx.de> wrote:

> Hi mrg,
>
> > I haven't used the tapestry5-cayenne module, but for initializing some
> > Cayenne (and non-Cayenne) things at application startup, you can use
> > Tapestry's @Startup annotation in your application module:
> >
> > http://tapestry.apache.org/registry-startup.html
>
> yes I tried that yesterday, but it didn't work. I used it like this in
> AppModule.java:
>
> @Startup
> public void init(@InjectService("DataContext") ObjectContextProvider
> provider) { ... }
>
> This didn't work. I got this exception:
> Error invoking service contribution method
> de.myApp.services.AppModule.init(ObjectContextProvider): Unable to delegate
> method invocation to property 'request' of <Proxy for
> RequestGlobals(org.apache.tapestry5.services.RequestGlobals)>, because the
> property is null.
>
> Don't know why it's about RequestGlobals here, but I think even though the
> TapestryCayenneModule is defined at this point, the service
> ObjectContextProvider is not defined yet.
>
> > If the tapestry5-cayenne module provides services, perhaps they are even
> > passable into your startup methods.  If not, I suppose you could still
> > initialize the Cayenne runtime there.
>
> That's what I did after reading your mail and it works :-) Thanks.
>
> Now the method looks like this:
>
> @Startup
> public void init() {
>     ServerRuntime runtime = new ServerRuntime("cayenne.xml");
>  
> runtime.getDataDomain().getEntityResolver().getCallbackRegistry().addListener(new
> LastModifiedListener());
>     runtime.getDataDomain().addFilter(new ChangeSetFilter());
> }
>
> > You mentioned that there should only be one instance of ServerRuntime.
> > You
> > can create multiple instances, but no need to do it for the same
> > configuration.  However, if you have multiple models (in the past this
> > would be multiple DataMaps in a single Cayenne model), then you'll need
> to
> > create a ServerRuntime for each.
>
> There is only one data-map in my cayenne.map.xml therefore I was under the
> impression there should be only one runtime. I don't mind a second runtime
> as long as everything works. Will the "other" runtime inside the
> TapestryCayenneModule, which is instantiated later and has all the data
> contexts I use, know about the filter and listener?
>
> Should I add
> runtime.shutdown();
> in my init method to end the first runtime which is not needed afterwards?
>
> I'm going to try some more to find out if the last modified filter
> actually works.
>

Reply via email to