estou tendando rodar um programa que utiliza o banco derbi, utilizando uma classe entidade e jpa, mas está dando errado.
Este é o código…
// a classe entidade que criei
package Domain;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
/**
*
-
@author Sidnei
*/
@Entity
public class Livro implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String titulo;
private String autor;
private String isbn;
private int numPaginas;public String getAutor() {
return autor;
}public void setAutor(String autor) {
this.autor = autor;
}public String getIsbn() {
return isbn;
}public void setIsbn(String isbn) {
this.isbn = isbn;
}public int getNumPaginas() {
return numPaginas;
}public void setNumPaginas(int numPaginas) {
this.numPaginas = numPaginas;
}public String getTitulo() {
return titulo;
}
public void setTitulo(String titulo) {
this.titulo = titulo;
}public Long getId() {
return id;
}public void setId(Long id) {
this.id = id;
}@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Livro other = (Livro) obj;
if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) {
return false;
}
if ((this.titulo == null) ? (other.titulo != null) : !this.titulo.equals(other.titulo)) {
return false;
}
if ((this.autor == null) ? (other.autor != null) : !this.autor.equals(other.autor)) {
return false;
}
if ((this.isbn == null) ? (other.isbn != null) : !this.isbn.equals(other.isbn)) {
return false;
}
if (this.numPaginas != other.numPaginas) {
return false;
}
return true;
}@Override
public int hashCode() {
int hash = 7;
hash = 53 * hash + (this.id != null ? this.id.hashCode() : 0);
hash = 53 * hash + (this.titulo != null ? this.titulo.hashCode() : 0);
hash = 53 * hash + (this.autor != null ? this.autor.hashCode() : 0);
hash = 53 * hash + (this.isbn != null ? this.isbn.hashCode() : 0);
hash = 53 * hash + this.numPaginas;
return hash;
}@Override
public String toString() {
return “Domain.Livro[id=” + id + “]”;
}
}
// a classe aplicacao
package Apl;
/**
*
-
@author Sidnei
*/
import Domain.Livro;
import Banco.LivroJpaController;
import java.util.List;
public class Aplicacao {
public static void main(String[] args) throws Exception {
Livro obj = new Livro();
obj.setAutor("Deitel");
obj.setIsbn("874999000");
obj.setNumPaginas(1100);
obj.setTitulo("Programar em java");
LivroJpaController jpa = new LivroJpaController();
jpa.create(obj);
List <Livro> lista = jpa.findLivroEntities();
for(Livro l : lista){
System.out.println("Livro: " + l.getId() + l.getAutor() + l.getTitulo() +
l.getIsbn() + l.getNumPaginas());
}
obj.setAutor("Deitel & Deitel");
jpa.edit(obj);
lista = jpa.findLivroEntities();
for(Livro l : lista){
System.out.println("Livro: " + l.getId() + l.getAutor() + l.getTitulo() +
l.getIsbn() + l.getNumPaginas());
jpa.destroy(l.getId());
}
lista = jpa.findLivroEntities();
for(Livro l : lista){
System.out.println("Livro: " + l.getId() + l.getAutor() + l.getTitulo() +
l.getIsbn() + l.getNumPaginas());
}
}
}
A mensagem de erro
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 Banco.LivroJpaController.getEntityManager(LivroJpaController.java:32)
at Banco.LivroJpaController.create(LivroJpaController.java:38)
at Apl.Aplicacao.main(Aplicacao.java:29)
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)
por favor me ajudem, pois eu conseguindo resolver este problema eu conseguirei fazer o trabalho para p2 na faculdade.
desde já eu agradeço!!!