-->
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: Hibernate sessionFactory and JNDI
PostPosted: Fri Oct 08, 2010 5:51 pm 
Newbie

Joined: Fri Oct 08, 2010 5:35 pm
Posts: 3
hi everyone.
I have a little problem with binding Hibernate SessionFactory to JNDI.
I'm always getting that messages in Log, when i'm deploying my web-app on jBoss server (5.1).
Code:
00:25:22,049 INFO  [SettingsFactory] Named query checking : enabled
00:25:22,150 INFO  [SessionFactoryImpl] building session factory
[b]00:25:22,154 INFO  [SessionFactoryObjectFactory] Not binding factory to JNDI, no JNDI name configured[/b]
00:25:22,185 INFO  [SchemaUpdate] Running hbm2ddl schema update
00:25:22,186 INFO  [SchemaUpdate] fetching database metadata


hibernate.cfg.xml
Code:
<hibernate-configuration>
<session-factory name="java:comp:/hibernateSessionFactory">
  <property name="hibernate.connection.pool_size">10</property>
  <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
  <property name="hibernate.connection.url">jdbc:mysql://localhost/seam</property>
  <property name="hibernate.connection.username">surly</property>
  <property name="hibernate.show_sql">true</property>
  <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
  <property name="hibernate.format_sql">true</property>
  <property name="hibernate.default_entity_mode">pojo</property>
  <property name="hibernate.session_factory_name">java:comp:/hibernateSessionFactory</property>
  <property name="hibernate.connection.datasource">seam_testDatasource</property>
  <property name="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property>
  <property name="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
  <property name="hibernate.transaction.auto_close_session">false</property>
  <property name="hibernate.cache.provider_class">org.hibernate.cache.HashtableCacheProvider</property>
  <property name="hibernate.transaction.flush_before_completion">true</property>
  <property name="hibernate.hbm2ddl.auto">create</property>
  <!--  <mapping class="myentity" package="org.domain.seamtest.session"/> -->
</session-factory>


persistance.xml
Code:
<persistence-unit name="seam_test" transaction-type="JTA">
      <provider>org.hibernate.ejb.HibernatePersistence</provider>
      <jta-data-source>java:/seam_testDatasource</jta-data-source>
      <properties>
         <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/>
         <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
         <property name="hibernate.show_sql" value="true"/>
         <property name="hibernate.format_sql" value="true"/>
         <property name="jboss.entity.manager.factory.jndi.name" value="myfactory"/>
      </properties>
   </persistence-unit>


components.xml
Code:
....
<persistence:hibernate-session-factory auto-create="true"
  cfg-resource-name="hibernate.cfg.xml" name="hibernateSessionFactory"/>
<persistence:managed-hibernate-session auto-create="true"
  name="hibernateSession" session-factory-jndi-name="hibernateSessionFactory"/>
....


mysession.java, base class DAO.java, local interface
Code:
public class DAO {
   protected DAO() {
      }
      //some methods

      private static final Logger log = Logger.getAnonymousLogger();      
              //HERE IS IT!!
      @In
      public Session hibernateSession;
}

@Stateless
@Name("mysession")
public class mysession extends DAO implements mysessionLocal {
   @PostConstruct
   public void init() {
             System.out.println("INIT mysession bean");
    }
           //some methods
}
@Local
public interface mysessionLocal {
          //methods
}


I write simple web-application using SEAM framework, and i decided to use Hibernate instead JPA in my stateless EJB.
I want to INJECT (@In) Hibernate Session in every created EJB.
Tell me, what is wrong here, why i cant to inject Session to EJB?
i'm always getting this, when my EJB constructed:
Code:
00:31:10,091 ERROR [TxPolicy] javax.ejb.EJBTransactionRolledbackException: SessionFactory not found in JNDI: hibernateSessionFactory


Top
 Profile  
 
 Post subject: Re: Hibernate sessionFactory and JNDI
PostPosted: Fri Oct 08, 2010 9:53 pm 
Regular
Regular

Joined: Sun Feb 14, 2010 3:29 pm
Posts: 58
Location: USA
I suggest you reading the JBossAS ref doc.

I don't know what component.xml is. I don't recall JBoss5 server nor hibernate itself has one.

In JBoss5, you would normally create a <datasource> config inside a <myDSName>-ds.xml file in the $JBOSS_HOME/server/<profileName>/deploy directory (default is hsqldb-ds.xml). The datasource will automatically bind to JNDI. The dasource name should match to your persistence.xml with "java:" prefix.

You normally don't use <hibernate-configuration> when using JPA unless you explicitly reference so, and I don't see you doing so.

In EJB, you inject a EntityManger object by using @PersistenceContext annotation.

-Z

_________________
Zemian Deng
------------
Need a Java Scheduler? Try
http://bitbucket.org/timemachine/scheduler


Top
 Profile  
 
 Post subject: Re: Hibernate sessionFactory and JNDI
PostPosted: Sat Oct 09, 2010 8:22 am 
Newbie

Joined: Fri Oct 08, 2010 5:35 pm
Posts: 3
yes, i have seam_test-ds.xml file. it is ok.
here is it
Code:
<datasources>
      <local-tx-datasource>
      <jndi-name>seam_testDatasource</jndi-name>
      <use-java-context>true</use-java-context>
      <connection-url>jdbc:mysql://localhost:3306/seam</connection-url>
      <driver-class>com.mysql.jdbc.Driver</driver-class>
      <user-name>surly</user-name>
      <password></password>
      </local-tx-datasource>
</datasources>


components.xml - is a Seam components configuration file.

look, i don't want to use EntitiyManager object, which injected by using @PersistenceContext annotation.
I want to use Hibernate with EJB, i want to inject Hibernate Session object. But i dont know how :(
Can you help me with this problem?


Top
 Profile  
 
 Post subject: Re: Hibernate sessionFactory and JNDI
PostPosted: Sun Oct 10, 2010 9:08 am 
Regular
Regular

Joined: Sun Feb 14, 2010 3:29 pm
Posts: 58
Location: USA
I don't know about seam, but JBossAS allows you to inject a direct hibernate session in EJB with the same annot. Try

Code:
@Stateless MyBean implements LocalBean
{
    @PersisteceContxt
    org.hibernate.Session session;
    ...
}

_________________
Zemian Deng
------------
Need a Java Scheduler? Try
http://bitbucket.org/timemachine/scheduler


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.