Estou estudando percistência no netbeans e estou fazendo um pequeno exemplo, porém está me dando um erro… alguém poderia me dar uma ajuada??
/*
- Aluno.java
- Created on 10/10/2007, 14:05:32
- To change this template, choose Tools | Templates
- and open the template in the editor.
*/
package lib.database;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
/**
*
-
@author valdomiro */ @Entity @Table(name = “ALUNO”) @NamedQueries({@NamedQuery(name = “Aluno.findById”, query = “SELECT a FROM Aluno a WHERE a.id = :id”), @NamedQuery(name = “Aluno.findByMatricula”, query = “SELECT a FROM Aluno a WHERE a.matricula = :matricula”), @NamedQuery(name = “Aluno.findByNome”, query = “SELECT a FROM Aluno a WHERE a.nome = :nome”)}) public class Aluno implements Serializable { @Id @Column(name = “ID”, nullable = false) private Integer id; @Column(name = “MATRICULA”, nullable = false) private int matricula; @Column(name = “NOME”) private String nome;
public Aluno() {
}public Aluno(Integer id) { this.id = id; }public Aluno(Integer id, int matricula) { this.id = id; this.matricula = matricula; }public Integer getId() { return id; }
public void setId(Integer id) { this.id = id; }public int getMatricula() { return matricula; }
public void setMatricula(int matricula) { this.matricula = matricula; }public String getNome() { return nome; }
public void setNome(String nome) { this.nome = nome; }<a class="mention" href="/u/override">@Override</a> public int hashCode() { int hash = 0; hash += (id != null ? id.hashCode() : 0); return hash; }
<a class="mention" href="/u/override">@Override</a> public boolean equals(Object object) { // TODO: Warning - this method won’t work in the case the id fields are not set if (!(object instanceof Aluno)) { return false; } Aluno other = (Aluno) object; if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) { return false; } return true; }
<a class="mention" href="/u/override">@Override</a> public String toString() { return “lib.database.Aluno[id=” + id + “]”; }
}
/*
- TestaPersistencia.java
- Created on 10/10/2007, 14:07:37
- To change this template, choose Tools | Templates
- and open the template in the editor.
*/
package teste.lib;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import lib.database.Aluno;
/**
*
-
@author valdomiro
*/
public class TestaPersistencia {
public static void main (String args[]){
javax.persistence.EntityManagerFactory emf = javax.persistence.Persistence.createEntityManagerFactory(“AlunoGUIPU”);
javax.persistence.EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
try {
EntityTransaction tx = em.getTransaction();
tx.begin();
Aluno aluno = new Aluno();
aluno.setId(3);
aluno.setMatricula(45645);
aluno.setNome(“Alex”);
em.persist(aluno);
tx.commit();
} catch (Exception e) {
e.printStackTrace();
em.getTransaction().rollback();
} finally {
em.close();
emf.close();
}
}
}
Erro:
Exception in thread “main” Local Exception Stack:
Exception [TOPLINK-4003] (Oracle TopLink Essentials - 2.0 (Build b58g-fcs (09/07/2007))): oracle.toplink.essentials.exceptions.DatabaseException
Exception Description: Configuration error. Class [org.apache.derby.jdbc.ClientDriver] not found.
at oracle.toplink.essentials.exceptions.DatabaseException.configurationErrorClassNotFound(DatabaseException.java:101)
at oracle.toplink.essentials.sessions.DefaultConnector.loadDriver(DefaultConnector.java:183)
at oracle.toplink.essentials.sessions.DefaultConnector.connect(DefaultConnector.java:98)
at oracle.toplink.essentials.sessions.DatasourceLogin.connectToDatasource(DatasourceLogin.java:184)
at oracle.toplink.essentials.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:582)
at oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:280)
at oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:229)
at oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:93)
at oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:126)
at oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:120)
at oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:91)
at teste.lib.TestaPersistencia.main(TestaPersistencia.java:25)