Iniciando com JPA

Olá pessoal,

Bom estou tentando fazer um exemplo de JPA. A inicio tentei fazer seguindo o seguinte tutorial http://www.rafaelcarneiro.org/blog/2007/05/20/iniciando-com-jpa/

Então meu Entity ficou assim:

[code]package br.com.meindica.bo;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Persistence;
import javax.persistence.PersistenceUnit;
import javax.persistence.Table;

import sun.misc.BASE64Encoder;

@Entity
@Table (name = "users")
public class Person {

@PersistenceUnit
private EntityManagerFactory factory = null;

private EntityManager manager = null;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY )
private Integer id;

@Column(name = "password", nullable = true )
private String password;

@Column(name = "username", nullable = true )
private String userName;

@Column(name = "nome", nullable = true)
private String name;

public Person(){
	factory = Persistence.createEntityManagerFactory("jpaTest");
	manager = factory.createEntityManager();
}

public Person(String userName, String password) {
	factory = Persistence.createEntityManagerFactory("jpaTest");
	manager = factory.createEntityManager();
	setUserName(userName);
	setPassword(password);
}

public void persist(){
	manager.persist(this);
	manager.close();
}

/* Getters e Setters */
}[/code]

Meu arquivo persistence.xml é o seguinte

[code]<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" 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">

<persistence-unit name="jpaTest" transaction-type="RESOURCE_LOCAL">
<provider>oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider</provider>
<class>br.com.meindica.bo.Person</class>
<properties>
<property name="toplink.logging.level" value="INFO"/>
<property name="toplink.jdbc.url" value="jdbc:mysql://127.0.0.1:3306/hibernate"/>
<property name="toplink.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="toplink.jdbc.user" value="root"/>
<property name="toplink.jdbc.password" value="123456"/>
<!-- <property name="toplink.ddl-generation" value="create-tables"/> -->
</properties>
</persistence-unit>

</persistence>[/code]

Porém ele dá um erro que eu não consigo achar nada sobre ele o Stack:

[quote]Exception in thread “main” javax.persistence.PersistenceException: No Persistence provider for EntityManager named jpaTest: Provider named oracle.toplink.essentials.PersistenceProvider threw unexpected exception at create EntityManagerFactory:
java.lang.ExceptionInInitializerError
java.lang.ExceptionInInitializerError
at java.text.RBTableBuilder.build(RBTableBuilder.java:89)
at java.text.RBCollationTables.<init>(RBCollationTables.java:65)
at java.text.RuleBasedCollator.<init>(RuleBasedCollator.java:276)
at java.text.Collator.getInstance(Collator.java:251)
at java.text.Collator.getInstance(Collator.java:207)
at sun.net.www.protocol.file.FileURLConnection.getInputStream(FileURLConnection.java:173)
at java.net.URL.openStream(URL.java:1009)
at oracle.toplink.essentials.ejb.cmp3.persistence.PersistenceUnitProcessor.createInputStreamForURL(PersistenceUnitProcessor.java:306)
at oracle.toplink.essentials.ejb.cmp3.persistence.PersistenceUnitProcessor.processJarFile(PersistenceUnitProcessor.java:146)
at oracle.toplink.essentials.ejb.cmp3.persistence.PersistenceUnitProcessor.processPersistenceArchive(PersistenceUnitProcessor.java:181)
at oracle.toplink.essentials.ejb.cmp3.persistence.PersistenceUnitProcessor.getPersistenceUnits(PersistenceUnitProcessor.java:77)
at oracle.toplink.essentials.internal.ejb.cmp3.JavaSECMPInitializer.initPersistenceUnits(JavaSECMPInitializer.java:222)
at oracle.toplink.essentials.internal.ejb.cmp3.JavaSECMPInitializer.initialize(JavaSECMPInitializer.java:240)
at oracle.toplink.essentials.internal.ejb.cmp3.JavaSECMPInitializer.initializeFromMain(JavaSECMPInitializer.java:277)
at oracle.toplink.essentials.internal.ejb.cmp3.JavaSECMPInitializer.getJavaSECMPInitializer(JavaSECMPInitializer.java:80)
at oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider.createEntityManagerFactory(EntityManagerFactoryProvider.java:118)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:110)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:83)
at br.com.meindica.bo.Person.<init>(Person.java:47)
at CalendarTestDrive.main(CalendarTestDrive.java:10)
Caused by: java.lang.RuntimeException: could not locate data
at sun.text.normalizer.NormalizerImpl.<clinit>(NormalizerImpl.java:44)
… 20 more

Provider named oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider threw unexpected exception at create EntityManagerFactory:
java.lang.NullPointerException
java.lang.NullPointerException
at oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider.createEntityManagerFactory(EntityManagerFactoryProvider.java:120)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:110)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:83)
at br.com.meindica.bo.Person.<init>(Person.java:47)
at CalendarTestDrive.main(CalendarTestDrive.java:10)

at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:154)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:83)
at br.com.meindica.bo.Person.&lt;init&gt;(Person.java:47)
at CalendarTestDrive.main(CalendarTestDrive.java:10)

[/quote]

Já não faço mais a menor ideia do que possa estar ocorrendo … Então resolvi tentar executar o exemplo do site que mencionei acima … Porem ele dá o mesmo problema.

Alguém pode me dar uma ajuda?

Muito Obrigado

Cara,

Eu acho que o problema é que o toplink e toplink-essentials.jar não está no teu classpath…

da uma olhada nisso

Fernando Rosa

Cara estão sim no classpath, verifique e ainda estão lá …

Olá dá uma olhada , se seu arquivo persistence.xml, está na pasta META-INF dentro de src.
Acho que ta faltando este arquivo

Att

Cara meu persistence.xml está sim dentro do META-INF.

Obrigado