Don't do annotation based injection in an EntityListener. Last time I checked, the lifecycle of the object is not controlled by Seam.
Component.getInstance("entityManager");//where entityManager is the name of the entityManager in your components.xml
Thats great works well.
Is this a good design pattern or should i be using seams event model and raising prePersist events?
I dont want to use the prePersist annotation in my entity as i need to access the db for get a specific value at point of persist.
Hmmm...I suppose it depends on what kind of logic will be executing in prepersist. If its simply a matter of putting some audit information somewhere...just use a prepersist. But if you need to do something really crazy, I would probably look at using seam events. Unfortunately, there's a million way to skin this cat.
I tried this with:
identity = (Identity)Component.getInstance("identity");
also tried the more verbose variety:
identity = (Identity)Component.getInstance("org.jboss.seam.security.identity");
and identity comes up null. It does get into the method ok. Any ideas?
This is an old thread, but I came across it while looking for a solution, and wanted to post back how I eventually solved it.
Identity identity = (Identity)Component.getInstance(Identity.class);
works to manually inject the identity component, while the string identifier does not.