Mantis - Resin
Viewing Issue Advanced Details
3429 minor always 03-01-09 13:13 08-26-09 14:28
none 4.0.2  
0003429: @Service, JPA/Hibernate, and inserting
(rep by Scott Hernandez)

I want to have services (that start with the application, and runs the
length of the application lifetime) so I define a POJO with a @Service
and a method with a @PostConstruct. Everything is going well so far. I
define a persistenceunit in persistence.xml and corresponding jdbc
info in the (resin-)web.xml config. So my service looks like this:

public class InitDBService {

    protected EntityManager em;
    protected EntityManagerFactory emf;

    public void postConstruct() {
        log.log(Level.INFO, "emf=" + emf + " em=" + em);
               if (emptyDB()) insertDefaultData();

emf=AmberEntityManagerFactory[amber] em=EntityManagerProxy[amber]

So I load up my webapp and away it goes. If I use amber (the native
JPA impl) everything looks fine and the entity manager, and factory is
injected as expected, and the data is queried (and inserted if empty).

Now, if I switch to a hibernate backed persistenceunit (hbm) I get
some kind of exception no matter how I do it.

emf=null em=EntityManagerTransactionProxy[hbm,null]

I have tried using @TransactionAttributes, the UserTransaction object,
and various other attempts without any success on the hibernate

Now, later in my code, in a servlet, I have the same code and it runs
fine against the @PersistenceContext using the hibernate

I hope this makes a bit more sense and maybe someone can point me in
the right direction to get this working :)

08-26-09 14:28