This content has been marked as final.
Show 7 replies
-
1. Re: Mixing Hibernate & EJB3
gavin.king Jul 27, 2006 8:25 AM (in response to mschmidke)Yes, of course it is possible, straightforward in fact. Just
(1) install a Seam-managed session in components.xml
(2) inject it using @In(create=true) mySessionComponentName -
2. Re: Mixing Hibernate & EJB3
mschmidke Jul 27, 2006 8:34 AM (in response to mschmidke)Yes ... but which sessionFactoryJndiName do I have to use in components.xml? Where do I have to configure the "counterpart" (since, of course, I don't have a hibernate.cfg.xml file)?
Perhaps ... I'll try leaving out the sessionFactoryJndiName property ... maybe there is an automatic default?
Marcus. -
3. Re: Mixing Hibernate & EJB3
gavin.king Jul 27, 2006 8:52 AM (in response to mschmidke)You _will_ need a hibernate.cfg.xml, of course!
-
4. Re: Mixing Hibernate & EJB3
mschmidke Jul 27, 2006 9:23 AM (in response to mschmidke)"gavin king" wrote:
You _will_ need a hibernate.cfg.xml, of course!
Will I? But ... until now, I never needed one. persistence.xml was all I had.
Ok, when I create one, will I only have to put this session-factory entry into it? Or will I have to move configuration parameters from persistence.xml into hibernate.cfg.xml?
persistence.xml:<?xml version="1.0" encoding="UTF-8"?> <persistence> <persistence-unit name="LeistungserfassungEntityManager"> <jta-data-source>java:/LeistungserfassungDS</jta-data-source> <properties> <property name="hibernate.hbm2ddl.auto" value=""/> <property name="hibernate.show_sql" value="true"/> <property name="hibernate.dialect" value="org.hibernate.dialect.OracleDialect" /> <property name="hibernate.max_fetch_depth" value="0" /> <property name="hibernate.default_batch_fetch_size" value="100" /> <property name="hibernate.use_sql_comments" value="true" /> <property name="hibernate.bytecode.use_reflection_optimizer" value="false" /> </properties> </persistence-unit> </persistence>
-
5. Re: Mixing Hibernate & EJB3
robjellinghaus Jul 28, 2006 1:34 AM (in response to mschmidke)Personally I am doing it this way:
/** * Tiny sugar class for getting the hibernate session from an EntityManager. */ public class GetHibernateSession { // wow, cool idiom! private static final Logger log = Logger.getLogger(new Throwable().getStackTrace()[0].getClass()); private GetHibernateSession () { } public static Session get (EntityManager entityManager) { Session delegate = (Session)entityManager.getDelegate(); return delegate; } }
Use like so:GetHibernateSession.get(entityManager).enableFilter("priorChangeset") .setParameter("changeset_id", changeset.getId());
Works for me :-) And no need for hibernate.cfg.xml when I already have a persistence.xml....
Cheers!
Rob -
6. Re: Mixing Hibernate & EJB3
mschmidke Jul 28, 2006 2:31 AM (in response to mschmidke)Great ...
Did not know that Hibernate Session is that simply available.
Works great! This is the right solution for such small-brained people like me.
Thank you very much!
Marcus. -
7. Re: Mixing Hibernate & EJB3
gavin.king Jul 28, 2006 9:17 PM (in response to mschmidke)Personally I am doing it this way:
Even better, do that stuff in an @Unwrap method on a Seam component, and you can inject the wrapped Hibernate session using @In.