Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jpa

 
trinath babu
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="three">
<class>three.Address</class>
<class>three.Man</class>
<properties>
<property name="hibernate.connection.username" value="shiva"/>
<property name="hibernate.connection.password" value="shiva"/>
<property name="hibernate.connection.url" value="jdbcracle:thin:@localhost:1521:xe"/>
<property name="hibernate.connection.driver_class" value="oracle.jdbc.OracleDriver"/>
</properties>
</persistence-unit>
</persistence>


main class
public class OneToOne {

public static void main(String[] args) {


Persistence persistence=new Persistence();
EntityManagerFactory entityManagerFactory=persistence.createEntityManagerFactory("three");
EntityManager entityManager=entityManagerFactory.createEntityManager();

Man man=entityManager.find(Man.class,222L);

/*Address address =entityManager.find(Address.class,222L);*/
Address address=man.getAddress();
/*Man man=address.getMan(); */


System.out.println("asid:=>"+man.getAsid());
System.out.println("ajob:=>"+man.getAjob());

System.out.println();
System.out.println("aid:=>"+address.getAid());
System.out.println("city:=>"+address.getCity());
System.out.println("name:=>"+address.getName());
System.out.println("fname:=>"+address.getFname());
System.out.println("contry:=>"+address.getContry());


}

}


so i want to connect a one to one realation table names like man, address
but it gives the below error so please help me

Sep 11, 2014 12:21:50 PM org.hibernate.ejb.HibernatePersistence logDeprecation
WARN: HHH015016: Encountered a deprecated javax.persistence.spi.PersistenceProvider [org.hibernate.ejb.HibernatePersistence]; use [org.hibernate.jpa.HibernatePersistenceProvider] instead.
Sep 11, 2014 12:21:50 PM org.hibernate.ejb.HibernatePersistence logDeprecation
WARN: HHH015016: Encountered a deprecated javax.persistence.spi.PersistenceProvider [org.hibernate.ejb.HibernatePersistence]; use [org.hibernate.jpa.HibernatePersistenceProvider] instead.
Sep 11, 2014 12:21:50 PM org.hibernate.ejb.HibernatePersistence logDeprecation
WARN: HHH015016: Encountered a deprecated javax.persistence.spi.PersistenceProvider [org.hibernate.ejb.HibernatePersistence]; use [org.hibernate.jpa.HibernatePersistenceProvider] instead.
Sep 11, 2014 12:21:50 PM org.hibernate.jpa.boot.internal.PersistenceXmlParser doResolve
INFO: HHH000318: Could not find any META-INF/persistence.xml file in the classpath
Sep 11, 2014 12:21:50 PM org.hibernate.jpa.boot.internal.PersistenceXmlParser doResolve
INFO: HHH000318: Could not find any META-INF/persistence.xml file in the classpath
Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named three
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:61)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)
at OneToOne.main(OneToOne.java:17)
 
trinath babu
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how to work with oracle database in different machine by using ip address
please provide steps for this
 
da dooms
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi trinath,

I know it's an old post, but just in case some other person have the same problem.
Your persistance.xml is incomplet, you have to fill the persistance-unit field like this :

<?xml version="1.0" encoding="UTF-8"?>
<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="MYPU" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<properties>
<property name="hibernate.connection.autocommit" value="true" />
<property name="hibernate.hbm2ddl.auto" value="validate" />
<property name="hibernate.connection.datasource" value="java:comp/env/jdbc/myconnection" />
<property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" />
</properties>
</persistence-unit>
</persistence>

In my cas I use a conection calling myconnection in the tomcat's server.xml. I'm connected to an Oracle 10g Database.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic