-->
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: EntityManager and bootstraping under jboss
PostPosted: Tue Mar 20, 2007 6:06 pm 
Beginner
Beginner

Joined: Wed May 05, 2004 12:45 pm
Posts: 21
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.2.0.CR1

I am having a problem obtaining EntityManager in JBoss. I specified my persistence.xml file


Code:
<persistence 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_1_0.xsd"
   version="1.0">
   <persistence-unit name="hibernateUnit" transaction-type="JTA">
      <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <jta-data-source>java:/OracleDS</jta-data-source>
      <class>StatusInfo</class>
      <properties> 
         <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
          <property name="hibernate.transaction.factory_class" value="org.hibernate.transaction.JTATransactionFactory"/>
        <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle9Dialect"/>
        <property name="hibernate.connection.driver_class" value="oracle.jdbc.driver.OracleDriver"/>
        <property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider"/>
      </properties>
   </persistence-unit>
</persistence>



The following code I used to obtain the EntityManager

Code:
configOverrides.put("hibernate.connection.url", "jdbc:oracle:thin:@host:1521:instance");
configOverrides.put("hibernate.connection.username", "myuser");
configOverrides.put("hibernate.connection.password", "pass");
      
      EntityManagerFactory programmaticEmf =
          Persistence.createEntityManagerFactory("hibernateUnit", configOverrides);
      em = programmaticEmf.createEntityManager();



Now when I try to run my ejb component I will get an exception

--- MBEANS THAT ARE THE ROOT CAUSE OF THE PROBLEM ---
ObjectName: jboss.jca:name=OracleDS,service=ManagedConnectionFactory
State: NOTYETINSTALLED
Depends On Me:
persistence.units:ear=harvest.ear,jar=ejb.harvest.jar,unitName=hibernateUnit

Only after I configure a dataSource in my oracle-ds.xml file with the same jndi-name will the code work.

My use cases requires me to get connectionUrl, userName and password as params from the client and then obtain a connection and do some db logic. I haven't been able to figure out how to do this properly without first initializing a datasource. I thought that simply by passing in Map with my jdbc properties as mentioned above would do the trick.

Any help would be appreciated,

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 20, 2007 11:57 pm 
Beginner
Beginner

Joined: Wed May 05, 2004 12:45 pm
Posts: 21
I guess I am lost. I tried to change from a JTA transaction to a locally managed transaction

Code:
<persistence 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_1_0.xsd"
   version="1.0">
   <persistence-unit name="hibernateUnit" transaction-type="RESOURCE_LOCAL">
      <provider>org.hibernate.ejb.HibernatePersistence</provider>
      <class>StatusInfo</class>
      <properties> 
       <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/> 
          <property name="hibernate.transaction.factory_class" value="org.hibernate.transaction.JDBCTransactionFactory"/>
        <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle9Dialect"/>
        <property name="hibernate.connection.driver_class" value="oracle.jdbc.driver.OracleDriver"/>
        <property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider"/>
      </properties>
   </persistence-unit>
</persistence>


According to the referece
http://www.hibernate.org/hib_docs/entitymanager/reference/en/html_single/#setup-configuration

jta-data-source, non-jta-data-source

This is the JNDI name of where the javax.sql.DataSource is located. When running without a JNDI available Datasource, you must specify JDBC connections with Hibernate specific properties

It seems that it is possible not to specify neither jta-data-source nor non-jta-data-source. However when I don't provide them it always defaults to a JTA transaction and fails due to a missing jta-data-source

Reason: java.lang.RuntimeException: You have not defined a jta-data-source for a JTA enabled persistence context named: hibernateUnit


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.