Re: [Resin-interest] Using Hibernate as EntityManager in Resin 4

2009-03-31 Thread Scott Hernandez
Yeah, I tracked it down the the start method of
EnvironmentClassLoader. When walking through the EnvironmentListener[]
list the webbeans (and @ApplicationScope @Service) are init'd before
the EJB system. The EntityManagerFactory exists in the AmberContainer
but it is still in the _pendingFactory list (and not in the wbManager
it seems) until the startPersistenceUnits method is called for
AmberContainer.

The list of listeners is in this order:
InjectManager
OsgiLoader
InjectManager (osgi)
DBPoolImpl
EjbContainer
AmberContainer
WeakStopListener (@Stateless EJB instance)

Basically the @Service @PostConstruct is called during the first
InjectManager, and the Amber/Ejb Container isn't good till much later
(at the end).

Well, that is what it seems to be. I think I should be able to find a
workaround since it seems that there are events that fire after all
this that I can hook into. Not the most elegant way, but should work
for now (I can take care of re-initialization in case it changes
behavior). I don't know enough about the internals of resin to know if
this a problem, or fixable, but if I can help let me know :)


On Tue, Mar 31, 2009 at 3:25 PM, Scott Ferguson  wrote:
> On Mar 31, 2009, at 12:51 PM, Scott Hernandez wrote:
> I've added a bug report for this at http://bugs.caucho.com/view.php?id=3429
>
> I didn't quite understand the situation.  The environment might not be
> properly setup at the @PostConstruct time for some reason.


___
resin-interest mailing list
resin-interest@caucho.com
http://maillist.caucho.com/mailman/listinfo/resin-interest


Re: [Resin-interest] Using Hibernate as EntityManager in Resin 4

2009-03-31 Thread Scott Ferguson

On Mar 31, 2009, at 12:51 PM, Scott Hernandez wrote:

> Let me try this again from the beginning...
>
> 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:

I've added a bug report for this at http://bugs.caucho.com/view.php?id=3429

I didn't quite understand the situation.  The environment might not be  
properly setup at the @PostConstruct time for some reason.

-- Scott

>
>
> @Service
> public class InitDBService {
>
>   @PersistenceContext
>   protected EntityManager em;
>   
>   @PersistenceUnit
>   protected EntityManagerFactory emf;
>
>   @PostConstruct
>   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
> persistenceunit.
>
> Now, later in my code, in a servlet, I have the same code and it runs
> fine against the @PersistenceContext using the hibernate
> persistenceunit.
>
> I hope this makes a bit more sense and maybe someone can point me in
> the right direction to get this working :)
>
> Thanks in advance,
> Scott
>
>
> ___
> resin-interest mailing list
> resin-interest@caucho.com
> http://maillist.caucho.com/mailman/listinfo/resin-interest



___
resin-interest mailing list
resin-interest@caucho.com
http://maillist.caucho.com/mailman/listinfo/resin-interest


Re: [Resin-interest] Using Hibernate as EntityManager in Resin 4

2009-03-31 Thread Scott Hernandez
Let me try this again from the beginning...

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:

@Service
public class InitDBService {

@PersistenceContext
protected EntityManager em;

@PersistenceUnit
protected EntityManagerFactory emf;

@PostConstruct
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
persistenceunit.

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

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

Thanks in advance,
Scott


___
resin-interest mailing list
resin-interest@caucho.com
http://maillist.caucho.com/mailman/listinfo/resin-interest


Re: [Resin-interest] Using Hibernate as EntityManager in Resin 4

2009-03-31 Thread Scott Hernandez
Let me try this again from the beginning...

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:

@Service
public class InitDBService {

@PersistenceContext
protected EntityManager em;

@PersistenceUnit
protected EntityManagerFactory emf;

@PostConstruct
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
persistenceunit.

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

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

Thanks in advance,
Scott


___
resin-interest mailing list
resin-interest@caucho.com
http://maillist.caucho.com/mailman/listinfo/resin-interest


Re: [Resin-interest] Using Hibernate as EntityManager in Resin 4

2009-03-31 Thread Scott Ferguson

On Mar 30, 2009, at 9:32 PM, Scott Hernandez wrote:

> Well, I have configured a test app to use hibernate and I have a few
> problems (and a bit of success):
>
> I was able to get the same code working from a servlet, but when
> trying to get data I get an exception when running from a @Service (in
> the @PostConstruct method):
>
> [21:26:06.430] {main} java.lang.IllegalStateException:
> EntityManagerTransactionProxy[test,null]: @PersistenceContext
> EntityManager may not be used outside of a transaction
> [21:26:06.430] {main}   at

>
> trying to use entityManager.getTransaction().begin got me this  
> exception:
> java.lang.IllegalStateException: Container-manager @PersistenceContext
> may not use getTransaction.
>
> I'm guessing that the problem is that the @Service post construction
> is happened too soon, maybe.

It's a different issue, I believe.  The EntityManager is intended to  
be used inside a UserTransaction, i.e. a container-managed  
transaction.  The JavaEE model is that you're running inside a Session  
bean, although that's not strictly necessary as long as it's inside a  
transaction.

If you're managing transactions with the EntityManager, you need to  
use EntityManagerFactory, not EntityManager.  (It's been a little  
while since I've read that part of the spec, though.)

-- Scott

>
>
> [snip]
>
>
> ___
> resin-interest mailing list
> resin-interest@caucho.com
> http://maillist.caucho.com/mailman/listinfo/resin-interest



___
resin-interest mailing list
resin-interest@caucho.com
http://maillist.caucho.com/mailman/listinfo/resin-interest


Re: [Resin-interest] Using Hibernate as EntityManager in Resin 4

2009-03-30 Thread Scott Hernandez
Well, I have configured a test app to use hibernate and I have a few
problems (and a bit of success):

I was able to get the same code working from a servlet, but when
trying to get data I get an exception when running from a @Service (in
the @PostConstruct method):

[21:26:06.430] {main} java.lang.IllegalStateException:
EntityManagerTransactionProxy[test,null]: @PersistenceContext
EntityManager may not be used outside of a transaction
[21:26:06.430] {main}   at
com.caucho.amber.manager.EntityManagerTransactionProxy.getCurrent(EntityManagerTransactionProxy.java:408)
[21:26:06.430] {main}   at
com.caucho.amber.manager.EntityManagerTransactionProxy.createQuery(EntityManagerTransactionProxy.java:193)
[21:26:06.430] {main}   at
test2.services.InitDBService.checkDBandInit(InitDBService.java:47)
[21:26:06.430] {main}   at
test2.services.InitDBService.postConstruct(InitDBService.java:36)
[21:26:06.430] {main}   at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[21:26:06.430] {main}   at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[21:26:06.430] {main}   at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[21:26:06.430] {main}   at java.lang.reflect.Method.invoke(Method.java:597)
[21:26:06.430] {main}   at
com.caucho.config.j2ee.PostConstructProgram.inject(PostConstructProgram.java:121)
[21:26:06.430] {main}   at
com.caucho.config.inject.ComponentImpl.init(ComponentImpl.java:344)
[21:26:06.430] {main}   at
com.caucho.config.inject.SimpleBean.create(SimpleBean.java:421)
[21:26:06.430] {main}   at
com.caucho.config.scope.ScopeContext.get(ScopeContext.java:90)
[21:26:06.430] {main}   at
com.caucho.config.inject.InjectManager.getInstanceRec(InjectManager.java:1331)
[21:26:06.430] {main}   at
com.caucho.config.inject.InjectManager.getInstance(InjectManager.java:1288)
[21:26:06.430] {main}   at
com.caucho.config.inject.InjectManager.getInstance(InjectManager.java:1345)
[21:26:06.430] {main}   at
com.caucho.server.webbeans.ResinWebBeansProducer.serviceStartup(ResinWebBeansProducer.java:167)
[21:26:06.430] {main}   at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[21:26:06.430] {main}   at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[21:26:06.430] {main}   at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[21:26:06.430] {main}   at java.lang.reflect.Method.invoke(Method.java:597)
[21:26:06.430] {main}   at
com.caucho.config.event.ObserverImpl.notify(ObserverImpl.java:191)
[21:26:06.430] {main}   at
com.caucho.config.inject.ObserverMap.fireEvent(ObserverMap.java:82)
[21:26:06.430] {main}   at
com.caucho.config.inject.InjectManager.fireEventImpl(InjectManager.java:1559)
[21:26:06.430] {main}   at
com.caucho.config.inject.InjectManager.fireEventImpl(InjectManager.java:1540)
[21:26:06.430] {main}   at
com.caucho.config.inject.InjectManager.fireEventImpl(InjectManager.java:1540)
[21:26:06.430] {main}   at
com.caucho.config.inject.InjectManager.fireEventImpl(InjectManager.java:1540)
[21:26:06.430] {main}   at
com.caucho.config.inject.InjectManager.fireEventImpl(InjectManager.java:1540)
[21:26:06.430] {main}   at
com.caucho.config.inject.InjectManager.fireEvent(InjectManager.java:1534)
[21:26:06.430] {main}   at
com.caucho.config.inject.InjectManager.registerBean(InjectManager.java:2066)
[21:26:06.430] {main}   at
com.caucho.config.inject.InjectManager.registerBean(InjectManager.java:2044)
[21:26:06.430] {main}   at
com.caucho.config.inject.InjectManager.registerBean(InjectManager.java:2047)
[21:26:06.430] {main}   at
com.caucho.config.inject.InjectManager.startServices(InjectManager.java:2013)
[21:26:06.430] {main}   at
com.caucho.config.inject.InjectManager.environmentStart(InjectManager.java:1993)
[21:26:06.430] {main}   at
com.caucho.loader.EnvironmentClassLoader.start(EnvironmentClassLoader.java:703)
[21:26:06.430] {main}   at
com.caucho.server.webapp.WebApp.start(WebApp.java:2021)
[21:26:06.430] {main}   at
com.caucho.server.deploy.DeployController.startImpl(DeployController.java:678)
[21:26:06.430] {main}   at
com.caucho.server.deploy.StartAutoRedeployAutoStrategy.startOnInit(StartAutoRedeployAutoStrategy.java:72)
[21:26:06.430] {main}   at
com.caucho.server.deploy.DeployController.startOnInit(DeployController.java:549)
[21:26:06.430] {main}   at
com.caucho.server.deploy.DeployContainer.start(DeployContainer.java:160)
[21:26:06.430] {main}   at
com.caucho.server.webapp.WebAppContainer.startImpl(WebAppContainer.java:681)
[21:26:06.430] {main}   at com.caucho.server.host.Host.startImpl(Host.java:496)
[21:26:06.430] {main}   at
com.caucho.server.webapp.WebAppContainer.start(WebAppContainer.java:661)
[21:26:06.430] {main}   at
com.caucho.server.deploy.DeployController.startImpl(DeployController.java:678)
[21:26:06.430] {main}   at
com.caucho.server.deploy.StartAutoRedeployAutoStrategy.startOnInit(StartAutoRedeployAutoStrategy.java:72)
[21:26:06.430] {main}  

Re: [Resin-interest] Using Hibernate as EntityManager in Resin 4

2009-03-25 Thread Scott Hernandez
No problem, I should have something to report in a few hours.

Also, is there a way to annotate the persistence units (for
EntityManager injection) like there was for the JMS stuff? Since the
persistence stuff is in persistence.xml, will it too become a bean
config driven system?

for example, let us say that I want two persistence units.


java:jdbc/test1



org.hibernate.ejb.HibernatePersistence
java:/jdbc/test
   ...

But I get this error (of course) since I can't distinguish between the
two without annotating them (or maybe I could  write a @Producer?).


Can't find a component for 'javax.persistence.EntityManager' because
no enabled beans match the bindings [...@javax.inject.current(),
@com.caucho.config.Name(value=test)]
.
Enabled beans:
SingletonBean[EntityManagerProxy, {...@name('test1'),
@javax.inject.Current()}, @Production, name=test1]
PersistenceContextComponent[EntityManager, {...@javax.inject.current()},
@Production, name=test]

On Wed, Mar 25, 2009 at 2:08 PM, Scott Ferguson  wrote:

[snip]
>> Are there any additional issues I should worry about?
>
> Well, we haven't gotten to the compatibility testing yet for Resin 4,
> and the Config/DI rewrite might have messed up the Hibernate
> integration.
>
> In other words, it should work, but if it doesn't we'll need to file a
> bug report on Resin 4.
[snip]


___
resin-interest mailing list
resin-interest@caucho.com
http://maillist.caucho.com/mailman/listinfo/resin-interest


Re: [Resin-interest] Using Hibernate as EntityManager in Resin 4

2009-03-25 Thread Scott Ferguson

On Mar 25, 2009, at 1:51 PM, Scott Hernandez wrote:

> It is always the moment after you send the email that you find the
> answer: http://wiki.caucho.com/Hibernate
>
> I will try that method.
>
> Are there any additional issues I should worry about?

Well, we haven't gotten to the compatibility testing yet for Resin 4,  
and the Config/DI rewrite might have messed up the Hibernate  
integration.

In other words, it should work, but if it doesn't we'll need to file a  
bug report on Resin 4.

-- Scott

>
>
> Sorry for the spam,
> Scott
>
> On Wed, Mar 25, 2009 at 1:47 PM, Scott Hernandez
>  wrote:
>> I'd like to replace Amber with Hibernate. We are migrating an app  
>> from
>> JBoss (Hibernate EntityManager) and there are lots of Hibernate
>> annotations used for validation, and to hint for database
>> optimizations. In the first pass getting things going we would like  
>> to
>> just drop in (as best as we can) the current entities and be able to
>> let Hibernate manage them as before. Later we may cut back on
>> Hibernate, and use Amber (but so far it seems to lack some of the
>> features in Hibernate).
>>
>> Is there a way to replace Amber with Hibernate?
>>
>
>
> ___
> resin-interest mailing list
> resin-interest@caucho.com
> http://maillist.caucho.com/mailman/listinfo/resin-interest



___
resin-interest mailing list
resin-interest@caucho.com
http://maillist.caucho.com/mailman/listinfo/resin-interest


Re: [Resin-interest] Using Hibernate as EntityManager in Resin 4

2009-03-25 Thread Scott Hernandez
It is always the moment after you send the email that you find the
answer: http://wiki.caucho.com/Hibernate

I will try that method.

Are there any additional issues I should worry about?

Sorry for the spam,
Scott

On Wed, Mar 25, 2009 at 1:47 PM, Scott Hernandez
 wrote:
> I'd like to replace Amber with Hibernate. We are migrating an app from
> JBoss (Hibernate EntityManager) and there are lots of Hibernate
> annotations used for validation, and to hint for database
> optimizations. In the first pass getting things going we would like to
> just drop in (as best as we can) the current entities and be able to
> let Hibernate manage them as before. Later we may cut back on
> Hibernate, and use Amber (but so far it seems to lack some of the
> features in Hibernate).
>
> Is there a way to replace Amber with Hibernate?
>


___
resin-interest mailing list
resin-interest@caucho.com
http://maillist.caucho.com/mailman/listinfo/resin-interest