I'm working with Spring and JPA under WildFly (8.1.0.Final) and I have problem with configuration. There are only two entities: User and Role. Something like that :
Code:
@Entity
@Table(name="users", schema = "train")
public class User {
@Id
private int id;
private String username;
@Column(unique=true)
private String email;
private String password;
@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(name = "users_roles",
joinColumns = {
@JoinColumn(name = "users_id", nullable = false, updatable = true)
},
inverseJoinColumns = {
@JoinColumn(name = "roles_id", nullable = false, updatable = true) })
private Set<Role> userRoles;
}
Code:
@Entity
@Table(name="roles", schema = "train")
public class Role {
@Id
private Integer id;
private String name;
This is my persistence.xml :
Code:
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
<persistence-unit name="hibernatePersistenceUnit" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>com.marianmarian.login.entities.User</class>
<class>com.marianmarian.login.entities.Role</class>
<properties>
<property name="hibernate.hbm2ddl.auto" value="validate" />
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
</properties>
<mapping-file>META-INF/orm.xml</mapping-file>
</persistence-unit>
</persistence>
My problem is that I cant deploy my project when I use hibernate.hbm2ddl.auto = validate. Im getting this stacktrace :
Code:
08:26:29,444 INFO [org.hibernate.Version] (ServerService Thread Pool -- 3) HHH000412: Hibernate Core {4.3.5.Final}
08:26:29,446 INFO [org.hibernate.cfg.Environment] (ServerService Thread Pool -- 3) HHH000206: hibernate.properties not found
08:26:29,447 INFO [org.hibernate.cfg.Environment] (ServerService Thread Pool -- 3) HHH000021: Bytecode provider name : javassist
08:26:29,785 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-11) JBAS010404: Deploying non-JDBC-compliant driver class com.mysql.jdbc.Driver (version 5.1)
08:26:29,786 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-11) JBAS010404: Deploying non-JDBC-compliant driver class com.mysql.fabric.jdbc.FabricMySQLDriver (version 5.1)
08:26:29,811 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-7) JBAS010417: Started Driver service with driver-name = login.war_com.mysql.fabric.jdbc.FabricMySQLDriver_5_1
08:26:29,814 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-14) JBAS010417: Started Driver service with driver-name = login.war_com.mysql.jdbc.Driver_5_1
08:26:29,816 INFO [org.jboss.as.jpa] (ServerService Thread Pool -- 3) JBAS011409: Starting Persistence Unit (phase 2 of 2) Service 'login.war#hibernatePersistenceUnit'
08:26:29,876 INFO [org.hibernate.annotations.common.Version] (ServerService Thread Pool -- 3) HCANN000001: Hibernate Commons Annotations {4.0.4.Final}
08:26:30,098 INFO [org.hibernate.dialect.Dialect] (ServerService Thread Pool -- 3) HHH000400: Using dialect: org.hibernate.dialect.MySQL5InnoDBDialect
08:26:30,206 INFO [org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory] (ServerService Thread Pool -- 3) HHH000397: Using ASTQueryTranslatorFactory
08:26:30,238 INFO [org.hibernate.validator.internal.util.Version] (ServerService Thread Pool -- 3) HV000001: Hibernate Validator 5.1.0.Final
08:26:30,466 INFO [org.hibernate.tool.hbm2ddl.SchemaValidator] (ServerService Thread Pool -- 3) HHH000229: Running schema validator
08:26:30,467 INFO [org.hibernate.tool.hbm2ddl.SchemaValidator] (ServerService Thread Pool -- 3) HHH000102: Fetching database metadata
08:26:30,471 INFO [java.sql.DatabaseMetaData] (ServerService Thread Pool -- 3) HHH000262: Table not found: roles
08:26:30,471 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 3) MSC000001: Failed to start service jboss.persistenceunit."login.war#hibernatePersistenceUnit": org.jboss.msc.service.StartException in service jboss.persistenceunit."login.war#hibernatePersistenceUnit": org.hibernate.HibernateException: Missing table: roles
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:172) [wildfly-jpa-8.1.0.Final.jar:8.1.0.Final]
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:117) [wildfly-jpa-8.1.0.Final.jar:8.1.0.Final]
at java.security.AccessController.doPrivileged(Native Method) [rt.jar:1.7.0_51]
at org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:474)
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1.run(PersistenceUnitServiceImpl.java:182) [wildfly-jpa-8.1.0.Final.jar:8.1.0.Final]
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [rt.jar:1.7.0_51]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [rt.jar:1.7.0_51]
at java.lang.Thread.run(Unknown Source) [rt.jar:1.7.0_51]
at org.jboss.threads.JBossThread.run(JBossThread.java:122)
Caused by: org.hibernate.HibernateException: Missing table: roles
at org.hibernate.cfg.Configuration.validateSchema(Configuration.java:1333) [hibernate-core-4.3.5.Final.jar:4.3.5.Final]
at org.hibernate.tool.hbm2ddl.SchemaValidator.validate(SchemaValidator.java:155) [hibernate-core-4.3.5.Final.jar:4.3.5.Final]
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:525) [hibernate-core-4.3.5.Final.jar:4.3.5.Final]
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1857) [hibernate-core-4.3.5.Final.jar:4.3.5.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850) [hibernate-entitymanager-4.3.5.Final.jar:4.3.5.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:843) [hibernate-entitymanager-4.3.5.Final.jar:4.3.5.Final]
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:397) [hibernate-core-4.3.5.Final.jar:4.3.5.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:842) [hibernate-entitymanager-4.3.5.Final.jar:4.3.5.Final]
at org.jboss.as.jpa.hibernate4.TwoPhaseBootstrapImpl.build(TwoPhaseBootstrapImpl.java:44) [jipijapa-hibernate4-3-1.0.1.Final.jar:]
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:154) [wildfly-jpa-8.1.0.Final.jar:8.1.0.Final]
... 8 more
I dont understand this because I know that table "roles" is present in db schema. In addition when I change value of this property from "validate" to "none", everything automagically deploy and works! Why I must leave schema validation for working my project? Can anyone help me? Maybe I dont see something?