Re: [5.4] hibernate events

2013-12-18 Thread Lance Java
Great! Note, you could reduce the verbosity by getting rid of the
interface, NOT registering a service and using @Autobuild

Ie:

@Startup
public static void initHibernateEventListener(@Autobuild
HibernateInitializerImpl hi) {
  hi.initialize();
}


Re: [5.4] hibernate events

2013-12-17 Thread Matthias

Thanks Lance, got it working.

public interface HibernateInitializer {
public void initialize();
}

public class HibernateInitializerImpl implements HibernateInitializer {

@Inject
SolrIndexer solrIndexer;

@Inject
private HibernateSessionSource hss;

@Override
public void initialize() {
EventListenerRegistry registry = ((SessionFactoryImpl) 
hss.getSessionFactory()).getServiceRegistry().getService(

EventListenerRegistry.class);
registry.getEventListenerGroup(EventType.PERSIST).appendListener(new 
MyPersistEventListener(solrIndexer));

}

}

in AppModule
public static void bind(ServiceBinder binder) {
  //...
  binder.bind(HibernateInitializer.class, HibernateInitializerImpl.class);
}

@Startup
public static void initHibernateEventListener(Logger logger, 
HibernateInitializer hi) {

  hi.initialize();
}

Not sure if this the best way to go, but it works :).


On 17.12.2013 11:03, Lance Java wrote:

I'm not convinced you should be doing this in a HibernateConfigurer since
you need the SessionSource. HibernateConfigurers are executed before the
SessionFactory exists.

Can you add the listener in a @Startup method or some @EagerLoad service?




-
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org



Re: [5.4] hibernate events

2013-12-17 Thread Lance Java
I'm not convinced you should be doing this in a HibernateConfigurer since
you need the SessionSource. HibernateConfigurers are executed before the
SessionFactory exists.

Can you add the listener in a @Startup method or some @EagerLoad service?


Re: [5.4] hibernate events

2013-12-16 Thread Matthias

Thanks Thiago, sometimes its to easy :).

Now I've got everything injected, but my 
EventListenerHibernateConfigurer still don't work:


java.lang.RuntimeException: Exception constructing service 
'ValueEncoderSource': Error invoking service contribution method 
org.apache.tapestry5.hibernate.modules.HibernateModule.contributeValueEncoderSource(MappedConfiguration,
 boolean, HibernateSessionSource, Session, TypeCoercer, PropertyAccess, 
LoggerSource): Exception constructing service 'HibernateSessionSource': Error 
invoking constructor public 
org.apache.tapestry5.internal.hibernate.HibernateSessionSourceImpl(org.slf4j.Logger,java.util.List):
 Exception constructing service 'HibernateSessionSource': Construction of 
service 'HibernateSessionSource' has failed due to recursion: the service 
depends on itself in some way. Please check 
org.apache.tapestry5.internal.hibernate.HibernateSessionSourceImpl(Logger, 
List) (at HibernateSessionSourceImpl.java:36) via 
org.apache.tapestry5.hibernate.modules.HibernateCoreModule.bind(ServiceBinder) 
(at HibernateCoreModule.java:43) for references to another service that is 
itself dependent on service 'HibernateSessionSource'.
at 
org.apache.tapestry5.ioc.internal.services.JustInTimeObjectCreator.obtainObjectFromCreator(JustInTimeObjectCreator.java:75)

It looks like I can't inject the HibernateSessionSource because my 
Configurer is called from there (maybe a circular dependency?):
public HibernateSessionSourceImpl(Logger logger, 
List hibernateConfigurers)  {

l// ...
for (HibernateConfigurer configurer : hibernateConfigurers)
configurer.configure(configuration);
// ...
}

I don't see another way of getting the HibernateSessionSource or the 
SessionFactory.



On 16.12.2013 13:30, Thiago H de Paula Figueiredo wrote:
On Sun, 15 Dec 2013 12:08:53 -0200, Matthias  
wrote:



in AppModule
 public static void 
contributeHibernateSessionSource(OrderedConfiguration 
config) {
 config.add("EventListener", new 
EventListenerHibernateConfigurer());

 }


If you use the 'new' keyword directly, no injection is done. The 
shortest way is to use config.addInstance("EventListener", 
EventListenerHibernateConfigurer.class). That will instantiate your 
class and do injections as if it was a service.






-
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org



Re: [5.4] hibernate events

2013-12-16 Thread Thiago H de Paula Figueiredo
On Sun, 15 Dec 2013 12:08:53 -0200, Matthias   
wrote:



in AppModule
 public static void  
contributeHibernateSessionSource(OrderedConfiguration  
config) {
 config.add("EventListener", new  
EventListenerHibernateConfigurer());

 }


If you use the 'new' keyword directly, no injection is done. The shortest  
way is to use config.addInstance("EventListener",  
EventListenerHibernateConfigurer.class). That will instantiate your class  
and do injections as if it was a service.


--
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br

-
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org



[5.4] hibernate events

2013-12-15 Thread Matthias
Hi, today I tried to add some hibernate event listeners to my 
application. This was my first naive approach:


in AppModule
public static void 
contributeHibernateSessionSource(OrderedConfiguration 
config) {
config.add("EventListener", new 
EventListenerHibernateConfigurer());

}

my EventListener
  public class EventListenerHibernateConfigurer implements 
HibernateConfigurer {


@Inject
SolrIndexer solrIndexer;

@Inject
private HibernateSessionSource hss;

@Override
public void configure(Configuration configuration) {
EventListenerRegistry registry = ((SessionFactoryImpl) 
hss.getSessionFactory()).getServiceRegistry().getService(

EventListenerRegistry.class);
registry.getEventListenerGroup(EventType.PERSIST).appendListener(new 
MyPersistEventListener(solrIndexer));

}
  }

First of all I found no way of register an event only with the 
configuration object 
(http://stackoverflow.com/questions/8616146/eventlisteners-using-hibernate-4-0-with-spring-3-1-0-release).
Second the injection does not work. But how do I get my SolrIndexer into 
the my event listener?


Thanks in advance
Matthias

-
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org