-->
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.  [ 1 post ] 
Author Message
 Post subject: Hibernate Session vs Entity Manager
PostPosted: Mon Mar 01, 2010 10:26 am 
Newbie

Joined: Mon Mar 01, 2010 9:49 am
Posts: 1
Hallo,

Bin Hibernateneuling und habe folgendes Problem:

Ich habe bei einer Anwendung Mehrere Klassen mit Hibernate Annotationen verknüpft.
Hierbei auch ein Array mit Interfaces mit einer ManyToMany, diesem Array werden ValueObjects die dieses Interface implementieren übergeben, deswegen targetEntity.

abVo:
Code:
@ManyToMany(targetEntity=xyVO.class)
@OrderColumn
public xyIf[] getAktion(){
        return (xyIf[])mAktion.get().toArray( new xyIf[ mAktion.size()]);
    }


Wenn ich HibernateUtil bzw die Hibernate Session wie im Hibernate Reference Documentation(auf Annotation abgewandelt) funktioniert dies einwandfrei.
Code:
public class HibernateUtil {
   private static SessionFactory sessionFactory;
   static {
      try {
         sessionFactory = new AnnotationConfiguration().configure()
               .buildSessionFactory();
      } catch (Throwable t) {
         throw new ExceptionInInitializerError(t);
      }
   }
   public static SessionFactory getSessionFactory() {
      return sessionFactory;
   }
   public static void shutdown() {
      getSessionFactory().close();
   }
}

hibernate.cfg.xml:
Code:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>

    <session-factory>

        <!-- Database connection settings -->
        <property name="connection.driver_class">org.hsqldb.jdbcDriver</property>
        <property name="connection.url">jdbc:hsqldb:hsql://localhost</property>
        <property name="connection.username">sa</property>
        <property name="connection.password"></property>

        <!-- JDBC connection pool (use the built-in) -->
        <property name="connection.pool_size">1</property>

        <!-- SQL dialect -->
        <property name="hibernate.dialect">org.hibernate.dialect.HSQLDialect</property>

        <!-- Enable Hibernate's current session context -->
        <property name="current_session_context_class">thread</property>

        <!-- Disable the second-level cache  -->
        <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>

        <!-- Echo all executed SQL to stdout -->
        <property name="show_sql">true</property>

        <!-- Drop and re-create the database schema on startup -->
        <property name="hbm2ddl.auto">update</property>
       
        <mapping class="data.abVo"/>
        <mapping class="data.xyVo"/>

    </session-factory>

</hibernate-configuration>


Nun sollte ich das ganze jedoch auf den in der JPA 2.0 existierenden EntityManager umstellen.
Code:
Ejb3Configuration config = new Ejb3Configuration();
config.configure("hibernate.cfg.xml");
EntityManagerFactory emf = config.buildEntityManagerFactory();
EntityManager em = emf.createEntityManager();


hierbei entsteht bei diversen CrUD-Aktionen (em.persist(t), em.merge(t)...) allerdings ein Build-Error das er xyIf erwartet, dieser Error ist bei der Lösung mit HibernateSession nicht aufgetreten. Kann mir jemand helfen?


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

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.