-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Ejb3Configuration.setDataSource is ignored
PostPosted: Thu Oct 27, 2005 4:40 am 
Regular
Regular

Joined: Thu Feb 19, 2004 4:48 am
Posts: 62
The docs for the EntityManager say, that setDatasource() on an Ejb3Configuration is ignored outside an ApplicationServer, which means that this:

Code:

Ejb3Configuration cfg = new Ejb3Configuration();
cfg.addProperties(hibernateProperties);
cfg.addAnnotatedClass(Customer.class);
cfg.addAnnotatedClass(Address.class);
cfg.addAnnotatedClass(OrderProcess.class);

cfg.setDataSource(dataSource);
      



silently fails outside an app-server.

I'm trying to use the EntityManager outside an appserver and have configured DataSources via Spring using

Code:
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
     <property name="dataSource" ref="txDataSource"/>
</bean>



So, two questions:
- I am outside of an appserver, but I have a DataSource - how can I teach hibernate to use the supplied DataSource?
- can I trick Hibernate to think that its inside an Appserver? Or more precise, how does hibernate determine if it lives inside an Appserver?

At least a message, that the setDataSource() is ignored would be nice - right now the method fails silently. It would be nice to add a warning...

cheers
stf


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 27, 2005 6:43 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
In the current implementation, you'll need to add in the properties
Code:
hibernate.connection.provider_class=f.q.c.n.InjectedDataSourceConnectionProvider


In CVS, HEM tries to set it when the datasource is set, so unless the user override this property, it should work out of the box.

PS: there is no such statement in the HEM doc. What is said is that the jta-data-source property (ie it's JNDI name) is ignored outside a container wich make sense since you don't have any JNDI and Datasource at your disposal. I've updated the JavaDoc to reflect that idea.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 27, 2005 9:54 am 
Regular
Regular

Joined: Thu Feb 19, 2004 4:48 am
Posts: 62
Thx! Using the hibernate.connection.provider_class-property, hibernate now takes the externally injected DataSource.

There is only one problem left, but this may be a Spring-Problem: We're using a org.springframework.jdbc.datasource.DataSourceTransactionManager to manage the Transactions on the injected datasource. We just make getTransaction()/commit()-calls on this TransactionManager to begin and end our transaction, but these Transactions are obviuously not enough for the EntityManager - it still complains, that no transaction is running - is it necessary to call getEntityManager().getTransaction().begin(); to get the EntityManager to recognize a running transaction or has the EM other means to find out that a transaction is already running?


[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 02, 2005 6:35 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Yes getTx().begin() is mandatory. Be careful em.getTransaction() is not the Hibernate transaction API. It only relies on the resource transaction, not the JTA one.

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.