1
I have 2 tables of my software that are not being generated correctly. SQL is generated, but when checking in Mysql, not the encounters.
If I change the tag to: <property name="hibernate.hbm2ddl.auto" value="validate"/>
or <property name="hibernate.hbm2ddl.auto" value="update"/>
, the first presents me the error that there is no ban table, and in the second, it gives a create in the ban tables and disabled.
Stack:
Type Exception Report
Message A MultiException has 2 exceptions. They are:
Description The server encountered an unexpected condition that prevented it from fulfilling the request.
Exception
javax.servlet.ServletException: A MultiException has 2 exceptions. They are:
1. javax.persistence.PersistenceException: [PersistenceUnit: persistence_unit_juntos] Unable to build Hibernate SessionFactory
2. java.lang.IllegalStateException: Unable to perform operation: create on br.com.felipejunges.juntos.controller.PessoaController
org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:487)
org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:425)
org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:383)
org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:336)
org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:223)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
Root Cause
A MultiException has 2 exceptions. They are:
1. javax.persistence.PersistenceException: [PersistenceUnit: persistence_unit_juntos] Unable to build Hibernate SessionFactory
2. java.lang.IllegalStateException: Unable to perform operation: create on br.com.felipejunges.juntos.controller.PessoaController
org.jvnet.hk2.internal.ClazzCreator.create(ClazzCreator.java:391)
org.jvnet.hk2.internal.SystemDescriptor.create(SystemDescriptor.java:471)
org.glassfish.jersey.process.internal.RequestScope.findOrCreate(RequestScope.java:162)
org.jvnet.hk2.internal.Utilities.createService(Utilities.java:2072)
org.jvnet.hk2.internal.ServiceLocatorImpl.internalGetService(ServiceLocatorImpl.java:767)
org.jvnet.hk2.internal.ServiceLocatorImpl.getService(ServiceLocatorImpl.java:706)
org.glassfish.jersey.internal.inject.Injections.getOrCreate(Injections.java:172)
org.glassfish.jersey.server.model.MethodHandler$ClassBasedMethodHandler.getInstance(MethodHandler.java:284)
org.glassfish.jersey.server.internal.routing.PushMethodHandlerRouter.apply(PushMethodHandlerRouter.java:74)
org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:109)
org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:112)
org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:112)
org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:112)
org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:112)
org.glassfish.jersey.server.internal.routing.RoutingStage.apply(RoutingStage.java:92)
org.glassfish.jersey.server.internal.routing.RoutingStage.apply(RoutingStage.java:61)
org.glassfish.jersey.process.internal.Stages.process(Stages.java:197)
org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:318)
org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)
org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)
org.glassfish.jersey.internal.Errors.process(Errors.java:315)
org.glassfish.jersey.internal.Errors.process(Errors.java:297)
org.glassfish.jersey.internal.Errors.process(Errors.java:267)
org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317)
org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:305)
org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1154)
org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:471)
org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:425)
org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:383)
org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:336)
org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:223)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
Root Cause
javax.persistence.PersistenceException: [PersistenceUnit: persistence_unit_juntos] Unable to build Hibernate SessionFactory
org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.persistenceException(EntityManagerFactoryBuilderImpl.java:954)
org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:884)
org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:58)
javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)
javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)
br.com.felipejunges.juntos.repository.PessoaRepository.<init>(PessoaRepository.java:20)
br.com.felipejunges.juntos.controller.PessoaController.<init>(PessoaController.java:21)
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
java.lang.reflect.Constructor.newInstance(Unknown Source)
org.glassfish.hk2.utilities.reflection.ReflectionHelper.makeMe(ReflectionHelper.java:1350)
org.jvnet.hk2.internal.ClazzCreator.createMe(ClazzCreator.java:271)
org.jvnet.hk2.internal.ClazzCreator.create(ClazzCreator.java:365)
org.jvnet.hk2.internal.SystemDescriptor.create(SystemDescriptor.java:471)
org.glassfish.jersey.process.internal.RequestScope.findOrCreate(RequestScope.java:162)
org.jvnet.hk2.internal.Utilities.createService(Utilities.java:2072)
org.jvnet.hk2.internal.ServiceLocatorImpl.internalGetService(ServiceLocatorImpl.java:767)
org.jvnet.hk2.internal.ServiceLocatorImpl.getService(ServiceLocatorImpl.java:706)
org.glassfish.jersey.internal.inject.Injections.getOrCreate(Injections.java:172)
org.glassfish.jersey.server.model.MethodHandler$ClassBasedMethodHandler.getInstance(MethodHandler.java:284)
org.glassfish.jersey.server.internal.routing.PushMethodHandlerRouter.apply(PushMethodHandlerRouter.java:74)
org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:109)
org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:112)
org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:112)
org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:112)
org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:112)
org.glassfish.jersey.server.internal.routing.RoutingStage.apply(RoutingStage.java:92)
org.glassfish.jersey.server.internal.routing.RoutingStage.apply(RoutingStage.java:61)
org.glassfish.jersey.process.internal.Stages.process(Stages.java:197)
org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:318)
org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)
org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)
org.glassfish.jersey.internal.Errors.process(Errors.java:315)
org.glassfish.jersey.internal.Errors.process(Errors.java:297)
org.glassfish.jersey.internal.Errors.process(Errors.java:267)
org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317)
org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:305)
org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1154)
org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:471)
org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:425)
org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:383)
org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:336)
org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:223)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
Root Cause
org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: missing table [ban]
org.hibernate.tool.schema.internal.SchemaValidatorImpl.validateTable(SchemaValidatorImpl.java:130)
org.hibernate.tool.schema.internal.SchemaValidatorImpl.performValidation(SchemaValidatorImpl.java:100)
org.hibernate.tool.schema.internal.SchemaValidatorImpl.doValidation(SchemaValidatorImpl.java:67)
org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.java:184)
org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaManagementToolCoordinator.java:64)
org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:458)
org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:465)
org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:881)
org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:58)
javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)
javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)
br.com.felipejunges.juntos.repository.PessoaRepository.<init>(PessoaRepository.java:20)
br.com.felipejunges.juntos.controller.PessoaController.<init>(PessoaController.java:21)
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
java.lang.reflect.Constructor.newInstance(Unknown Source)
org.glassfish.hk2.utilities.reflection.ReflectionHelper.makeMe(ReflectionHelper.java:1350)
org.jvnet.hk2.internal.ClazzCreator.createMe(ClazzCreator.java:271)
org.jvnet.hk2.internal.ClazzCreator.create(ClazzCreator.java:365)
org.jvnet.hk2.internal.SystemDescriptor.create(SystemDescriptor.java:471)
org.glassfish.jersey.process.internal.RequestScope.findOrCreate(RequestScope.java:162)
org.jvnet.hk2.internal.Utilities.createService(Utilities.java:2072)
org.jvnet.hk2.internal.ServiceLocatorImpl.internalGetService(ServiceLocatorImpl.java:767)
org.jvnet.hk2.internal.ServiceLocatorImpl.getService(ServiceLocatorImpl.java:706)
org.glassfish.jersey.internal.inject.Injections.getOrCreate(Injections.java:172)
org.glassfish.jersey.server.model.MethodHandler$ClassBasedMethodHandler.getInstance(MethodHandler.java:284)
org.glassfish.jersey.server.internal.routing.PushMethodHandlerRouter.apply(PushMethodHandlerRouter.java:74)
org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:109)
org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:112)
org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:112)
org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:112)
org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:112)
org.glassfish.jersey.server.internal.routing.RoutingStage.apply(RoutingStage.java:92)
org.glassfish.jersey.server.internal.routing.RoutingStage.apply(RoutingStage.java:61)
org.glassfish.jersey.process.internal.Stages.process(Stages.java:197)
org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:318)
org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)
org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)
org.glassfish.jersey.internal.Errors.process(Errors.java:315)
org.glassfish.jersey.internal.Errors.process(Errors.java:297)
org.glassfish.jersey.internal.Errors.process(Errors.java:267)
org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317)
org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:305)
org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1154)
org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:471)
org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:425)
org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:383)
org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:336)
org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:223)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
Note The full stack trace of the root cause is available in the server logs.
Models with error: Ban class:
package br.com.felipejunges.juntos.entity;
import java.math.BigInteger;
import java.sql.Timestamp;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
@Entity
@Table(name="ban")
public class Ban {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="id")
private BigInteger id;
@Column(name="banInicio")
private Timestamp banInicio;
@Column(name="banFim")
private Timestamp banFim;
@ManyToOne
@JoinColumn(name="usuario_id")
private Pessoa usuario_id;
@ManyToOne
@JoinColumn(name="admin_id")
private Pessoa admin_id;
@Column(name="reativado")
private Timestamp reativado;
public Ban(){
}
public Ban(BigInteger id, Timestamp banInicio, Timestamp banFim, Pessoa usuario_id,
Pessoa admin_id, Timestamp reativado){
super();
this.id = id;
this.banInicio = banInicio;
this.banFim = banFim;
this.usuario_id= usuario_id;
this.admin_id = admin_id;
this.reativado = reativado;
}
public BigInteger getId() {
return id;
}
public void setId(BigInteger id) {
this.id = id;
}
public Timestamp getBanInicio() {
return banInicio;
}
public void setBanInicio(Timestamp banInicio) {
this.banInicio = banInicio;
}
public Timestamp getBanFim() {
return banFim;
}
public void setBanFim(Timestamp banFim) {
this.banFim = banFim;
}
public Pessoa getUsuario_id() {
return usuario_id;
}
public void setUsuario_id(Pessoa usuario_id) {
this.usuario_id = usuario_id;
}
public Pessoa getAdmin_id() {
return admin_id;
}
public void setAdmin_id(Pessoa admin_id) {
this.admin_id = admin_id;
}
public Timestamp getReativado() {
return reativado;
}
public void setReativado(Timestamp reativado) {
this.reativado = reativado;
}
}
Class Disabled:
package br.com.felipejunges.juntos.entity;
import java.math.BigInteger;
import java.sql.Timestamp;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
@Entity
@Table(name="desativado")
public class Desativado {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="id")
private BigInteger id;
@Column(name="desativadoEm")
private Timestamp desativadoEm;
@ManyToOne
@JoinColumn(name="evento_id")
private Evento evento_id;
@ManyToOne
@JoinColumn(name="admin_id")
private Pessoa admin_id;
@Column(name="reativadoEm")
private Timestamp reativadoEm;
public Desativado(){}
public Desativado(BigInteger id, Timestamp desativadoEm, Evento evento_id,
Pessoa admin_id, Timestamp reativadoEm){
super();
this.id = id;
this.desativadoEm = desativadoEm;
this.evento_id = evento_id;
this.admin_id = admin_id;
this.reativadoEm = reativadoEm;
}
public BigInteger getId() {
return id;
}
public void setId(BigInteger id) {
this.id = id;
}
public Timestamp getDesativadoEm() {
return desativadoEm;
}
public void setDesativadoEm(Timestamp desativadoEm) {
this.desativadoEm = desativadoEm;
}
public Evento getEvento_id() {
return evento_id;
}
public void setEvento_id(Evento evento_id) {
this.evento_id = evento_id;
}
public Pessoa getAdmin_id() {
return admin_id;
}
public void setAdmin_id(Pessoa admin_id) {
this.admin_id = admin_id;
}
public Timestamp getReativadoEm() {
return reativadoEm;
}
public void setReativadoEm(Timestamp reativadoEm) {
this.reativadoEm = reativadoEm;
}
}
And a working model:
Classe Pessoa:
package br.com.felipejunges.juntos.entity;
import java.sql.Timestamp;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
@Entity
@Table(name="pessoa")
public class Pessoa {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="id")
private int id;
@Column(name="nome")
private String nome;
@Column(name="sobrenome")
private String sobrenome;
@Column(name="email")
private String email;
@Column(name="senha")
private String senha;
@Column(name="telefone")
private String telefone;
@ManyToOne(targetEntity=Cep.class)
@JoinColumn(name="cep")
private Cep cep;
@Column(name="login")
private Timestamp login;
@Column(name="registro")
private Timestamp registro;
@ManyToOne
@JoinColumn(name="gacesso_id")
private Permissao gacesso_id;
@Column(name="banAtivo")
private boolean banAtivo;
@ManyToOne
@JoinColumn(name="localizacaoAtual")
private Localizacao localizacaoAtual;
public Pessoa() {
}
public Pessoa(int id, String nome, String sobrenome, String email, String senha,
String telefone, Cep cep, Timestamp login, Timestamp registro,
Permissao gacesso_id, boolean banAtivo, Localizacao localizacaoAtual) {
super();
this.id = id;
this.nome = nome;
this.sobrenome = sobrenome;
this.email = email;
this.senha = senha;
this.telefone = telefone;
this.cep = cep;
this.login = login;
this.registro = registro;
this.gacesso_id = gacesso_id;
this.banAtivo = banAtivo;
this.localizacaoAtual = localizacaoAtual;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getSobrenome() {
return sobrenome;
}
public void setSobrenome(String sobrenome) {
this.sobrenome = sobrenome;
}
public String getSenha() {
return senha;
}
public void setSenha(String senha) {
this.senha = senha;
}
public String getTelefone() {
return telefone;
}
public void setTelefone(String telefone) {
this.telefone = telefone;
}
public Cep getCep() {
return cep;
}
public void setCep(Cep cep) {
this.cep = cep;
}
public Timestamp getLogin() {
return login;
}
public void setLogin(Timestamp login) {
this.login = login;
}
public Timestamp getRegistro() {
return registro;
}
public void setRegistro(Timestamp registro) {
this.registro = registro;
}
public Permissao getGacesso_id() {
return gacesso_id;
}
public void setGacesso_id(Permissao gacesso_id) {
this.gacesso_id = gacesso_id;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public Localizacao getLocalizacaoAtual() {
return localizacaoAtual;
}
public void setLocalizacaoAtual(Localizacao localizacaoAtual) {
this.localizacaoAtual = localizacaoAtual;
}
public boolean isBanAtivo() {
return banAtivo;
}
public void setBanAtivo(boolean banAtivo) {
this.banAtivo = banAtivo;
}
}
Project link in Git: https://github.com/felipeejunges/juntos
Test with
<property name="hibernate.hbm2ddl.auto" value="create"/>
– Raul José Chaves