Boa tarde galera,
Estou desenvolvendo um sistema de gerenciamento de biblioteca, e ao tentar criar um novo UsuarioDAO surge o seguinte error:
HTTP Status 500 - Request processing failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: biblioteca] Unable to build EntityManagerFactory
type Exception report
message Request processing failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: biblioteca] Unable to build EntityManagerFactory
description The server encountered an internal error that prevented it from fulfilling this request.
exception
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: biblioteca] Unable to build EntityManagerFactory
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:979)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:869)
javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:843)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause
javax.persistence.PersistenceException: [PersistenceUnit: biblioteca] Unable to build EntityManagerFactory
org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:925)
org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:900)
org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:59)
javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:63)
javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47)
br.com.biblioteca.dao.UsuarioDao.getEntityManager(UsuarioDao.java:21)
br.com.biblioteca.dao.UsuarioDao.<init>(UsuarioDao.java:29)
br.com.biblioteca.spring.controller.LoginController.efetuaLogin(LoginController.java:20)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136)
org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:832)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:743)
org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:961)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:895)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:967)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:869)
javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:843)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause
org.hibernate.AnnotationException: @Temporal should only be set on a java.util.Date or java.util.Calendar property: br.com.biblioteca.modelo.RegistroEmprestimo.dataEntrega
org.hibernate.cfg.annotations.SimpleValueBinder.setType(SimpleValueBinder.java:172)
org.hibernate.cfg.annotations.PropertyBinder.makePropertyAndValue(PropertyBinder.java:189)
org.hibernate.cfg.annotations.PropertyBinder.makePropertyValueAndBind(PropertyBinder.java:205)
org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:2166)
org.hibernate.cfg.AnnotationBinder.processIdPropertiesIfNotAlready(AnnotationBinder.java:895)
org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:728)
org.hibernate.cfg.Configuration$MetadataSourceQueue.processAnnotatedClassesQueue(Configuration.java:3625)
org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3579)
org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1381)
org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1786)
org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:96)
org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:915)
org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:900)
org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:59)
javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:63)
javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47)
br.com.biblioteca.dao.UsuarioDao.getEntityManager(UsuarioDao.java:21)
br.com.biblioteca.dao.UsuarioDao.<init>(UsuarioDao.java:29)
br.com.biblioteca.spring.controller.LoginController.efetuaLogin(LoginController.java:20)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136)
org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:832)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:743)
org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:961)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:895)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:967)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:869)
javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:843)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
note The full stack trace of the root cause is available in the Apache Tomcat/8.0.33 logs.
Apache Tomcat/8.0.33
Meu persistence:
<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="biblioteca">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>br.com.biblioteca.modelo.Livro</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost/biblioteca" />
<property name="javax.persistence.jdbc.user" value="root" />
<property name="javax.persistence.jdbc.password" value="senha" />
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="true" />
<property name="hibernate.hbm2ddl.auto" value="update" />
</properties>
</persistence-unit>
</persistence>
Minha Classe UsuarioDAO:
package br.com.biblioteca.dao;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.NoResultException;
import javax.persistence.Persistence;
import javax.persistence.Query;
import br.com.biblioteca.modelo.Livro;
import br.com.biblioteca.modelo.Usuario;
public class UsuarioDao {
private static Usuario instance;
protected EntityManager entityManager;
private EntityManager getEntityManager() {
EntityManagerFactory factory = Persistence
.createEntityManagerFactory("biblioteca");
if (entityManager == null) {
entityManager = factory.createEntityManager();
}
return entityManager;
}
public UsuarioDao() {
entityManager = getEntityManager();
}
public void adiciona(Usuario usuario) {
entityManager.getTransaction().begin();
entityManager.persist(usuario);
entityManager.getTransaction().commit();
}
public void alterar(Usuario usuario) {
entityManager.getTransaction().begin();
entityManager.merge(usuario);
entityManager.getTransaction().commit();
}
public void remove(Usuario usuario) {
entityManager.getTransaction().begin();
entityManager.remove(usuario);
entityManager.getTransaction().commit();
}
public List<Usuario> getList() {
Query query = entityManager.createQuery("select u from Usuario as u");
return query.getResultList();
}
public Usuario carregaUsuario(long id) {
return entityManager.find(Usuario.class, id);
}
public Usuario carregaDados(Usuario usuario) {
String login= usuario.getLogin();
try {
return (Usuario) entityManager
.createQuery(
"select u from Usuario u where"
+ " u.login = :login").
setParameter("login", login).getSingleResult();
} catch (NoResultException e) {
return null;
}
}
public Usuario getUsuario(Usuario usuario) {
String login = usuario.getLogin();
String senha = usuario.getSenha();
try {
entityManager
.createQuery(
"select u from Usuario u where"
+ " u.login = :login and u.senha = :senha")
.setParameter("login", login).setParameter("senha", senha);
return usuario;
} catch (NoResultException e) {
return null;
}
}
/*
* public String verificaAcesso(Usuario usuario) { String tipo =
* usuario.getTipo(); tipo.charAt(0); switch (tipo) { case "b": return
* "bibliotecario"; case "p": return "professor"; case "a": return "aluno";
* default: return null; } };
*/
public List<Usuario> localizarUsuario(String campo, String valor){
String queryCommand = "select l from Usuario as l where "+campo+"='"+valor+"'";
Query query = entityManager.createQuery(queryCommand);
return query.getResultList();
}
}
Se alguém puder dar uma ajuda agradeço:slight_smile: