2

I think it may be possible duplicate of this: schema-validation-missing-table-hibernate-sequences and schema-validation-missing-table-game and hibernate-schema-validation-missing-table but I can't find the solution. I re-created the table, added the default schema, and tried many things found on the internet but didn't find a solution yet. Should it be because of the Spring/Hibernate versions? I tried many other versions, but I get different other errors.

I use Spring 3.0.5.RELEASE, Hibernate 5.0.9.Final, the database is SQL Server. I'm trying strategy = GenerationType.IDENTITY.

The Entity:

@Entity
@Table(name = "users")
public class User extends AbstractEntity {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(nullable = false)
    private String login;

    @Column(nullable = false)
    private String password;

    protected User() {
        super();
    }

    public User(String login, String password) {
        this.login = login;
        this.password = password;
    }

    public Long getId() {
        return id;
    }

    public String getLogin() {
        return login;
    }

    public void setLogin(String login) {
        this.login = login;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
}

persistence.xml:

<persistence-unit name="all_PU" transaction-type="RESOURCE_LOCAL">
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties>
        <property name="hibernate.default_schema" value="dbo" />
        <property name="hibernate.show_sql" value="true"/>
        <property name="hibernate.format_sql" value="true"/>
        <property name="hibernate.hbm2ddl.auto" value="validate"/>
        <property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect"/>
    </properties>
</persistence-unit>

jdbc.properties:

hibernate.generate_statistics = true
jpa.showSql                   = true
jdbc.driverClassName= com.microsoft.sqlserver.jdbc.SQLServerDriver
jdbc.url = jdbc:sqlserver://localhost;databaseName=MYDBA;
jdbc.username =model2
jdbc.password =pass
jpa.database =SQL_SERVER

Spring xml config:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
       xmlns:tx="http://www.springframework.org/schema/tx" xmlns:p="http://www.springframework.org/schema/p"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
           http://www.springframework.org/schema/context
           http://www.springframework.org/schema/context/spring-context-3.0.xsd
           http://www.springframework.org/schema/tx
           http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">

    <!-- properties file for jdbc database access details /-->
    <context:property-placeholder location="classpath:jdbc.properties"/>

    <!-- enabling annotation driven configuration /-->
    <context:annotation-config/>

    <context:component-scan base-package="com.app.allapp"/>

    <tx:annotation-driven transaction-manager="transactionManager"/>
    <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>

    <bean id="dataSource"
          class="org.springframework.jdbc.datasource.DriverManagerDataSource"
          p:driverClassName="${jdbc.driverClassName}" p:url="${jdbc.url}"
          p:username="${jdbc.username}" p:password="${jdbc.password}"/>

    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"
          p:entityManagerFactory-ref="entityManagerFactory"/>

    <bean id="entityManagerFactory"
          class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
          p:dataSource-ref="dataSource" p:jpaVendorAdapter-ref="jpaAdapter">
        <property name="loadTimeWeaver">
            <bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"/>
        </property>
        <property name="persistenceUnitName" value="all_PU"/>
    </bean>

    <bean id="jpaAdapter"
          class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"
          p:database="${jpa.database}" p:showSql="${jpa.showSql}"/>

</beans>

I'm getting the following error:

11:41:11,102 ERROR [org.jboss.as.controller.management-operation] (management-handler-thread - 2) WFLYCTL0013: Operation ("deploy") failed - address: ([("deployment" => "AllApp")]) - failure description: {"WFLYCTL0080: Failed services" => {"jboss.persistenceunit.AllApp#all_PU" => "javax.persistence.PersistenceException: [PersistenceUnit: all_PU] Unable to build Hibernate SessionFactory
    Caused by: javax.persistence.PersistenceException: [PersistenceUnit: all_PU] Unable to build Hibernate SessionFactory
    Caused by: org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: missing table [dbo.users]"}}
11:41:11,103 ERROR [org.jboss.as.server] (management-handler-thread - 2) WFLYSRV0021: Deploy of deployment "AllApp.war" was rolled back with the following failure message: 
{"WFLYCTL0080: Failed services" => {"jboss.persistenceunit.AllApp#all_PU" => "javax.persistence.PersistenceException: [PersistenceUnit: all_PU] Unable to build Hibernate SessionFactory
    Caused by: javax.persistence.PersistenceException: [PersistenceUnit: all_PU] Unable to build Hibernate SessionFactory
    Caused by: org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: missing table [dbo.users]"}}

Anyone can point me to the right direction?

WDrgn
  • 521
  • 10
  • 29

0 Answers0