Olá pessoal estou com problemas ao executar os testes na classe USER, não estou conseguindo fazer nenhuma operacao CRUD alguém pode me ajudar?
obrigado.
segue todas as classe, persistence e o erro
classe USER
package br.com.mycompletejpawebapp.entity;
import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
/**
*
* @author Administrador
*/
@Entity
@Table(name=Users)
public class User implements Serializable{
@Id
@Column(name=id)
private Integer id;
@Column(name=nome)
private String name;
@Column(name=age)
private Integer age;
@OneToMany(mappedBy=vendor, cascade=CascadeType.ALL)
private List<Sell> sellsOfUsers = new LinkedList<Sell>();
public User() {
}
public User(Integer id) {
this.id = id;
}
public User(Integer id, String name, Integer age, List<Sell> sellsOfUsers) {
this.id = id;
this.name = name;
this.age = age;
this.sellsOfUsers = sellsOfUsers;
}
public void addSell(Sell sell){
this.sellsOfUsers.add(sell);
sell.setVendor(this);
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final User other = (User) obj;
if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) {
return false;
}
return true;
}
@Override
public int hashCode() {
int hash = 5;
hash = 43 * hash + (this.id != null ? this.id.hashCode() : 0);
return hash;
}
public List<Sell> getSellsOfUsers() {
return sellsOfUsers;
}
public void setSellsOfUsers(List<Sell> sellsOfUsers) {
this.sellsOfUsers = sellsOfUsers;
}
}
CLASSE PRODUCT
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package br.com.mycompletejpawebapp.entity;
import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
/**
*
* @author Administrador
*/
@Entity
@Table(name=product)
public class Product implements Serializable{
@Id
@Column(name=id)
private Integer id;
@Column(name=name)
private String name;
@OneToMany(mappedBy=produtc, cascade=CascadeType.ALL)
private List<Sell> sellsOfProduts = new LinkedList<Sell>();
public Product() {
}
public Product(Integer id) {
this.id = id;
}
public Product(Integer id, String name, List<Sell> sellsOfProduts) {
this.id = id;
this.name = name;
this.sellsOfProduts = sellsOfProduts;
}
public void addSell(Sell sell){
this.addSell(sell);
sell.setProduct(this);
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Product other = (Product) obj;
if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) {
return false;
}
return true;
}
@Override
public int hashCode() {
int hash = 7;
hash = 97 * hash + (this.id != null ? this.id.hashCode() : 0);
return hash;
}
public List<Sell> getSellsofproduts() {
return sellsOfProduts;
}
public void setSellsofproduts(List<Sell> sellsofproduts) {
this.sellsOfProduts = sellsofproduts;
}
}
CLASSE SELL
/*
- To change this template, choose Tools | Templates
- and open the template in the editor.
*/
package br.com.mycompletejpawebapp.entity;
import java.io.Serializable;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Version;
/**
*
* @author Administrador
*/
@Entity
@Table(name=sell)
public class Sell implements Serializable {
public Sell() {
}
public Sell(Integer id) {
this.id = id;
}
public Sell(Integer id, Product product, User vendor, int numberofitens, int version) {
this.id = id;
this.product = product;
this.vendor = vendor;
this.numberofitens = numberofitens;
this.version = version;
}
@Id
@Column(name=id)
private Integer id;
@JoinColumn(name=id_product, referencedColumnName=id)
@ManyToOne(cascade=CascadeType.ALL, optional=false, fetch=FetchType.LAZY)
private Product product;
@JoinColumn(name=id_vendor, referencedColumnName=id)
@ManyToOne(cascade=CascadeType.ALL, optional=false, fetch=FetchType.LAZY)
private User vendor;
@Column(name=numberofitens)
private int numberofitens;
@Column(name=version)
@Version
private int version;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public int getNumberofitens() {
return numberofitens;
}
public void setNumberofitens(int numberofitens) {
this.numberofitens = numberofitens;
}
public Product getProduct() {
return product;
}
public void setProduct(Product product) {
this.product = product;
}
public User getVendor() {
return vendor;
}
public void setVendor(User vendor) {
this.vendor = vendor;
}
public int getVersion() {
return version;
}
public void setVersion(int version) {
this.version = version;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Sell other = (Sell) obj;
if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) {
return false;
}
return true;
}
@Override
public int hashCode() {
int hash = 5;
hash = 29 * hash + (this.id != null ? this.id.hashCode() : 0);
return hash;
}
}
[b]
CLASSE USERDAO
[/b]
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package br.com.mycompletejpawebapp.dao;
import br.com.mycompletejpawebapp.entity.User;
import br.com.mycompletejpawebapp.util.JPAUtil;
import java.util.List;
import javax.persistence.EntityManager;
/**
*
* @author Administrador
*/
public class UserDAO {
public UserDAO() {
}
public Integer addUser(User usr){
EntityManager em = JPAUtil.getInstance().getEntityManager();
em.persist(usr);
em.getTransaction().commit();
em.close();
return usr.getId();
}
public void updateUser(User usr){
EntityManager em = JPAUtil.getInstance().getEntityManager();
em.merge(usr);
em.getTransaction().commit();
em.close();
}
public User getUser(int idUser){
return JPAUtil.getInstance().getEntity(User.class, idUser);
}
public void removeUser(User usr){
EntityManager em = JPAUtil.getInstance().getEntityManager();
em.remove(usr);
em.getTransaction().commit();
em.close();
}
public void removeById(int idUser){
EntityManager em = JPAUtil.getInstance().getEntityManager();
em.remove(em.find(User.class, idUser));
em.getTransaction().commit();
em.close();
}
public List<User> getAllUsers(){
return JPAUtil.getInstance().getList(User.class, select usr from User usr);
}
}
[b]
PERSISTENCE.XML
[/b]
<?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=exemploCompletoJPAPU transaction-type=RESOURCE_LOCAL>
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>br.com.mycompletejpawebapp.entity.Product</class>
<class>br.com.mycompletejpawebapp.entity.Sell</class>
<class>br.com.mycompletejpawebapp.entity.User</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name=hibernate.dialect value=org.hibernate.dialect.MySQLDialect/>
<property name=hibernate.connection.driver_class value=com.mysql.jdbc.Driver/>
<property name=hibernate.connection.username value=root/>
<property name=hibernate.connection.password value=root/>
<property name=hibernate.connection.url value=jdbc:mysql://localhost:3306/jpacompleteexample/>
<property name=hibernate.max_fetch_depth value=3/>
<property name=hibernate.format_sql value=true/>
<property name=hibernate.use_sql_comments value=false/>
<property name=hibernate.hbm2ddl.auto value=update/>
<property name=hibernate.show_sql value=true/>
<property name=hibernate.jdbc.batch_size value=50/>
</properties>
</persistence-unit>
</persistence>
[b]
erro ao fazer os testes:
Testcase: testAddUser(br.com.mycompletejpawebapp.dao.UserDAOTest): Caused an ERROR
[PersistenceUnit: exemploCompletoJPAPU] Unable to configure EntityManagerFactory
javax.persistence.PersistenceException: [PersistenceUnit: exemploCompletoJPAPU] Unable to configure EntityManagerFactory
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:265)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:125)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:52)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:34)
at br.com.mycompletejpawebapp.util.JPAUtil.(JPAUtil.java:26)
at br.com.mycompletejpawebapp.util.JPAUtil.getInstance(JPAUtil.java:31)
at br.com.mycompletejpawebapp.dao.UserDAO.addUser(UserDAO.java:24)
at br.com.mycompletejpawebapp.dao.UserDAOTest.testAddUser(UserDAOTest.java:53)
Caused by: org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: br.com.mycompletejpawebapp.entity.Sell.produtc in br.com.mycompletejpawebapp.entity.Product.sellsOfProduts
at org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:578)
at org.hibernate.cfg.annotations.CollectionBinder$1.secondPass(CollectionBinder.java:543)
at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:66)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1163)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:329)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1148)
at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1226)
at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:173)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:854)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:191)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:253)
Testcase: testUpdateUser(br.com.mycompletejpawebapp.dao.UserDAOTest): Caused an ERROR
[PersistenceUnit: exemploCompletoJPAPU] Unable to configure EntityManagerFactory
javax.persistence.PersistenceException: [PersistenceUnit: exemploCompletoJPAPU] Unable to configure EntityManagerFactory
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:265)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:125)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:52)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:34)
at br.com.mycompletejpawebapp.util.JPAUtil.(JPAUtil.java:26)
at br.com.mycompletejpawebapp.util.JPAUtil.getInstance(JPAUtil.java:31)
at br.com.mycompletejpawebapp.dao.UserDAO.updateUser(UserDAO.java:33)
at br.com.mycompletejpawebapp.dao.UserDAOTest.testUpdateUser(UserDAOTest.java:68)
Caused by: org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: br.com.mycompletejpawebapp.entity.Sell.produtc in br.com.mycompletejpawebapp.entity.Product.sellsOfProduts
at org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:578)
at org.hibernate.cfg.annotations.CollectionBinder$1.secondPass(CollectionBinder.java:543)
at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:66)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1163)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:329)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1148)
at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1226)
at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:173)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:854)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:191)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:253)
Testcase: testGetUser(br.com.mycompletejpawebapp.dao.UserDAOTest): Caused an ERROR
[PersistenceUnit: exemploCompletoJPAPU] Unable to configure EntityManagerFactory
javax.persistence.PersistenceException: [PersistenceUnit: exemploCompletoJPAPU] Unable to configure EntityManagerFactory
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:265)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:125)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:52)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:34)
at br.com.mycompletejpawebapp.util.JPAUtil.(JPAUtil.java:26)
at br.com.mycompletejpawebapp.util.JPAUtil.getInstance(JPAUtil.java:31)
at br.com.mycompletejpawebapp.dao.UserDAO.getUser(UserDAO.java:41)
at br.com.mycompletejpawebapp.dao.UserDAOTest.testGetUser(UserDAOTest.java:81)
Caused by: org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: br.com.mycompletejpawebapp.entity.Sell.produtc in br.com.mycompletejpawebapp.entity.Product.sellsOfProduts
at org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:578)
at org.hibernate.cfg.annotations.CollectionBinder$1.secondPass(CollectionBinder.java:543)
at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:66)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1163)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:329)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1148)
at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1226)
at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:173)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:854)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:191)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:253)
Testcase: testRemoveUser(br.com.mycompletejpawebapp.dao.UserDAOTest): Caused an ERROR
[PersistenceUnit: exemploCompletoJPAPU] Unable to configure EntityManagerFactory
javax.persistence.PersistenceException: [PersistenceUnit: exemploCompletoJPAPU] Unable to configure EntityManagerFactory
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:265)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:125)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:52)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:34)
at br.com.mycompletejpawebapp.util.JPAUtil.(JPAUtil.java:26)
at br.com.mycompletejpawebapp.util.JPAUtil.getInstance(JPAUtil.java:31)
at br.com.mycompletejpawebapp.dao.UserDAO.removeUser(UserDAO.java:45)
at br.com.mycompletejpawebapp.dao.UserDAOTest.testRemoveUser(UserDAOTest.java:96)
Caused by: org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: br.com.mycompletejpawebapp.entity.Sell.produtc in br.com.mycompletejpawebapp.entity.Product.sellsOfProduts
at org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:578)
at org.hibernate.cfg.annotations.CollectionBinder$1.secondPass(CollectionBinder.java:543)
at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:66)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1163)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:329)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1148)
at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1226)
at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:173)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:854)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:191)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:253)
Testcase: testRemoveById(br.com.mycompletejpawebapp.dao.UserDAOTest): Caused an ERROR
[PersistenceUnit: exemploCompletoJPAPU] Unable to configure EntityManagerFactory
javax.persistence.PersistenceException: [PersistenceUnit: exemploCompletoJPAPU] Unable to configure EntityManagerFactory
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:265)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:125)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:52)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:34)
at br.com.mycompletejpawebapp.util.JPAUtil.(JPAUtil.java:26)
at br.com.mycompletejpawebapp.util.JPAUtil.getInstance(JPAUtil.java:31)
at br.com.mycompletejpawebapp.dao.UserDAO.addUser(UserDAO.java:24)
at br.com.mycompletejpawebapp.dao.UserDAOTest.testRemoveById(UserDAOTest.java:114)
Caused by: org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: br.com.mycompletejpawebapp.entity.Sell.produtc in br.com.mycompletejpawebapp.entity.Product.sellsOfProduts
at org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:578)
at org.hibernate.cfg.annotations.CollectionBinder$1.secondPass(CollectionBinder.java:543)
at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:66)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1163)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:329)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1148)
at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1226)
at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:173)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:854)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:191)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:253)
Testcase: testGetAllUsers(br.com.mycompletejpawebapp.dao.UserDAOTest): Caused an ERROR
[PersistenceUnit: exemploCompletoJPAPU] Unable to configure EntityManagerFactory
javax.persistence.PersistenceException: [PersistenceUnit: exemploCompletoJPAPU] Unable to configure EntityManagerFactory
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:265)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:125)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:52)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:34)
at br.com.mycompletejpawebapp.util.JPAUtil.(JPAUtil.java:26)
at br.com.mycompletejpawebapp.util.JPAUtil.getInstance(JPAUtil.java:31)
at br.com.mycompletejpawebapp.dao.UserDAO.getAllUsers(UserDAO.java:59)
at br.com.mycompletejpawebapp.dao.UserDAOTest.testGetAllUsers(UserDAOTest.java:129)
Caused by: org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: br.com.mycompletejpawebapp.entity.Sell.produtc in br.com.mycompletejpawebapp.entity.Product.sellsOfProduts
at org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:578)
at org.hibernate.cfg.annotations.CollectionBinder$1.secondPass(CollectionBinder.java:543)
at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:66)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1163)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:329)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1148)
at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1226)
at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:173)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:854)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:191)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:253)
Test br.com.mycompletejpawebapp.dao.UserDAOTest FAILED
C:\devmedia\jpacompleteexaple\nbproject\build-impl.xml:967: Some tests failed; see details above.
FALHA NA CONSTRUÇÃO (tempo total: 8 segundos)