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