-->
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: EntityManager -Connection details
PostPosted: Thu Jul 15, 2010 7:50 am 
Newbie

Joined: Sat Nov 17, 2007 9:24 am
Posts: 5
Hi,
I was just trying to make one J2SE program to test the capabilities of the EntityManager with respect to normal HibernateAnnotations.
I followed the reference manual to do the setup configuration. What i found that the connection details given in persistence.xml is not found by hibernate.
The persistence.xml file is file is pasted below.

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_2_0.xsd"
   version="2.0">
   <persistence-unit name="manager1" transaction-type="RESOURCE_LOCAL">
      <class>com.infotech.sample.hibernate.pojo.User</class>
      <properties>
         <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" />
         <property name="javax.persistence.jdbc.driver" value="oracle.jdbc.driver.OracleDriver" />
         <property name="javax.persistence.jdbc.url" value="jdbc:oracle:thin:@00.0.00.000:1521:orcl" />
         <property name="javax.persistence.jdbc.user" value="live29" />
         <property name="javax.persistence.jdbc.password" value="live29_8apr" />
      </properties>

   </persistence-unit>



</persistence>

   




Now if i run the following program the get exception for connection.
Code:
package com.infotech.sample.hibernate;

import java.util.HashMap;
import java.util.Map;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;

import com.infotech.sample.hibernate.pojo.User;

public class BootStrap {

   public static void main(String[] args) {

      Map<String, Object> configOverrides = new HashMap<String, Object>();
      EntityManagerFactory emf = Persistence.createEntityManagerFactory("manager1", configOverrides);
      EntityManager em = emf.createEntityManager();
      EntityTransaction etx = em.getTransaction();

      etx.begin();
   
      etx.commit();
      em.close();
      emf.close();
   }

}



The i get the following exception.
Quote:
Exception in thread "main" java.lang.UnsupportedOperationException: The user must supply a JDBC connection
at org.hibernate.connection.UserSuppliedConnectionProvider.getConnection(UserSuppliedConnectionProvider.java:54)
at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:446)
at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:167)
at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:142)
at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:85)
at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1353)
at org.hibernate.ejb.TransactionImpl.begin(TransactionImpl.java:38)
at com.infotech.sample.hibernate.BootStrap.main(BootStrap.java:28)





But if i give all the connection deatils programatically then every thing just work fine.

Code:
package com.infotech.sample.hibernate;

import java.util.HashMap;
import java.util.Map;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;

import com.infotech.sample.hibernate.pojo.User;

public class BootStrap {

   public static void main(String[] args) {

      Map<String, Object> configOverrides = new HashMap<String, Object>();
      configOverrides.put("hibernate.connection.url", "jdbc:oracle:thin:@10.1.46.000:1521:orcl");
      configOverrides.put("hibernate.connection.driver_class", "oracle.jdbc.driver.OracleDriver");
      configOverrides.put("hibernate.connection.username", "live29");
      configOverrides.put("hibernate.connection.password", "live29");
      configOverrides.put("hibernate.dialect", "org.hibernate.dialect.Oracle10gDialect");

      EntityManagerFactory emf = Persistence.createEntityManagerFactory("manager1", configOverrides);
      EntityManager em = emf.createEntityManager();
      EntityTransaction etx = em.getTransaction();

      etx.begin();
      
      etx.commit();
      em.close();
      emf.close();
   }

}



The above code works properly.
Can any one tell me wats wrong with xml setup configuration?


Thanks,
Pushpendra Singh Baghel


Top
 Profile  
 
 Post subject: Re: EntityManager -Connection details
PostPosted: Thu Jul 22, 2010 4:48 am 
Newbie

Joined: Sat Nov 17, 2007 9:24 am
Posts: 5
I guess property names are issue. it's not taking javax.persistence.* . rather it's working well with hibernate.connection.* names.

Code:
         <property name="javax.persistence.jdbc.driver" value="oracle.jdbc.driver.OracleDriver" />
         <property name="javax.persistence.jdbc.url" value="jdbc:oracle:thin:@10.1.46.220:1521:orcl" />
         <property name="javax.persistence.jdbc.user" value="live29_8apr_1apr_copy" />
         <property name="javax.persistence.jdbc.password" value="live29_8apr_1apr_copy" />



This makes it non portable across the JPA provider.
Any clue?


Top
 Profile  
 
 Post subject: Re: EntityManager -Connection details
PostPosted: Sat Jul 24, 2010 8:09 am 
Newbie

Joined: Sat Jul 24, 2010 8:07 am
Posts: 1
standard property names come in JPA2
http://agoncal.wordpress.com/2009/07/05 ... tence-xml/


Top
 Profile  
 
 Post subject: Re: EntityManager -Connection details
PostPosted: Sat Jul 24, 2010 9:54 am 
Newbie

Joined: Sat Jul 24, 2010 9:50 am
Posts: 1
You can also visit the planetsourcecode if you want to see the actual program with the script that was used.

floor tape


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.