-
1. Re: Problrms getting Datasource connection whith DAO and EJB
swjackson May 10, 2007 10:46 AM (in response to cdmunoz)If you are using EJB3 I recommend using a persistence.xml file.
such as...
<persistence-unit name="metadata">
<jta-data-source>java:/it</jta-data-source>
org.hibernate.ejb.HibernatePersistence
</persistence-unit>
In your ejb instead of trying to create a jdbc connection use the annotation in your ejb
@PersistanceUnit(unit="metadata")
EntityManagerFactory factory
in your method you can access the query object such as
EntityManager em = factory.createEntityManager
Query query = em.whatYouNeedToDo...
Or if you need more advance features of the Hibernate Query object
//in your ejb or where you need it.
private EntityManagerFactory factory = new HibernatePersistence().createEntityManagerFactory(GUI, new HashMap());
in your method
Session session = session = ((HibernateEntityManagerFactory)factory).getSessionFactory().getCurrentSession();
HTH -
2. Re: Problrms getting Datasource connection whith DAO and EJB
swjackson May 10, 2007 10:48 AM (in response to cdmunoz)my persistence xml file didn't make it...
<persistence> <persistence-unit name="metadata"> <jta-data-source>java:/it</jta-data-source> <provider>org.hibernate.ejb.HibernatePersistence</provider> <properties> <property name="hibernate.dialect" value="org.hibernate.dialect.SybaseDialect"/> <property name="hibernate.show_sql" value="true"/> <property name="hibernate.current_session_context_class" value="org.hibernate.context.JTASessionContext"/> <property name="hibernate.transaction.factory_class" value="org.hibernate.transaction.CMTTransactionFactory"/> <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/> </properties> </persistence-unit> </persistence>