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.  [ 2 posts ] 
Author Message
 Post subject: hibernate wanted instead of jEE (glassfish) implemented JPA
PostPosted: Thu Dec 15, 2011 5:02 pm 
Newbie

Joined: Thu Dec 15, 2011 4:53 pm
Posts: 3
Hello there,

I use glassfish and just wanna do hibernate's criteria search.
But I only get

Code:
final org.eclipse.persistence.sessions.Session session = ((org.eclipse.persistence.internal.jpa.EntityManagerImpl) em.getDelegate()).getSession();


instead of

Code:
org.hibernate.Session session = ((org.hibernate.ejb.EntityManagerImpl) em.getDelegate()).getSession();


How can I inject the hibernate implementation?

my Service class
Code:
package de.familienschaetze.dao;

import java.io.Serializable;
import java.lang.reflect.ParameterizedType;
import java.util.List;
import java.util.Map;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Example;
import org.hibernate.criterion.Projections;

import de.familienschaetze.entities.EntityWithId;

public class GenericDaoImpl<T extends EntityWithId, ID extends Serializable> implements GenericDao<T, ID> {

   @PersistenceContext
   protected EntityManager em;

   protected List<T> findByCriteria(final Criterion... criterion) {
      // JBOSS verwendet (Session) em.getDelegate()
      // aeltere Glassfish verwendet org.hibernate.Session session = ((org.hibernate.ejb.EntityManagerImpl) em.getDelegate()).getSession();

      final org.eclipse.persistence.sessions.Session session = ((org.eclipse.persistence.internal.jpa.EntityManagerImpl) em.getDelegate()).getSession();
      final Criteria crit = session.createCriteria(getEntityClass());

      return result;
   }


hibernate versions I use:
Code:
      <dependency>
         <groupId>org.hibernate</groupId>
         <artifactId>hibernate-annotations</artifactId>
         <version>3.5.6-Final</version>
      </dependency>
      <dependency>
         <groupId>org.hibernate</groupId>
         <artifactId>hibernate-core</artifactId>
         <version>3.6.8.Final</version>
      </dependency>
      <dependency>
         <groupId>org.hibernate</groupId>
         <artifactId>hibernate-commons-annotations</artifactId>
         <version>3.3.0.ga</version>
      </dependency>
      <dependency>
         <groupId>org.hibernate</groupId>
         <artifactId>hibernate-entitymanager</artifactId>
         <version>3.6.8.Final</version>
      </dependency>


my persistence.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
   
   <persistence-unit name="myunit">
      <jta-data-source>jdbc/mysql</jta-data-source>

      <properties>
         <!-- property name="hibernate.hbm2ddl.auto" value="create"/ --><!-- (validate, update, create, create-drop) -->
         <!-- property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)"/ -->
         <!-- property name="toplink.jdbc.user" value="admin"/-->
         <!-- property name="toplink.jdbc.password" value="duke"/-->
         <!-- property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.SunONETransactionManagerLookup" /-->
         <!-- property name="toplink.platform.class.name" value="oracle.toplink.essentials.platform.database.DerbyPlatform"/-->

         <property name="hibernate.show.sql" value="true" />

         <!-- ### toplink Schema Generation ### -->
         <property name="toplink.ddl-generation" value="update-tables"/><!-- none(default), create-tables, drop-and-create-tables, update-tables -->
         <property name="toplink.application-location" value="."/>
         <property name="toplink.create-ddl-jdbc-file-name" value="create.sql"/>
         <property name="toplink.drop-ddl-jdbc-file-name" value="drop.sql"/>
         <property name="toplink.ddl-generation.output-mode" value="sql-script"/><!-- sql-script, database, both -->
      </properties>
   </persistence-unit>
</persistence>


thanks alot for help.
Your houk

ps. : The following hint doesnt work for me (but perhaps other guys with same problem):
http://stackoverflow.com/questions/4335570/accessing-hibernate-session-from-ejb-using-entitymanager

Ill get the Exception:
Caused by: javax.persistence.PersistenceException: Provider-does-not-support-the-call (There is no English translation for this message.)
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.unwrap(EntityManagerImpl.java:2504)


Top
 Profile  
 
 Post subject: Re: hibernate wanted instead of jEE (glassfish) implemented JPA
PostPosted: Fri Dec 16, 2011 11:36 am 
Newbie

Joined: Thu Dec 15, 2011 4:53 pm
Posts: 3
Ill try out if the provider entry solve my problem.

Code:
<persistence-unit ...>
      <provider>org.hibernate.ejb.HibernatePersistence</provider>

...
</persistence-unit>


edit:
I solved it: you can use the glassfish update tool to install hibernate JPA 3.5.0 Final. Now I use this core version. Later perhaps Ill update to newer versions.
After installing with the tool you have to set the provider tag in addition.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.