0

i have a maven project for spring and hibernate and i have done all the ssteps and the configuration .

1- i have create the entity 2- create the persistence.xml file 3- create the application-context.xml( file for beans def and configs)

but when i run my unit test the tables are not created i dont khnow why

the content of persistance.xml is :

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.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_2_0.xsd ">
    <persistence-unit name="UP_BRI_SANTE"
        transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <properties>
            <property name="hibernate.show_sql" value="true" />
            <property name="hibernate.hbm2dll.auto" value="update" />
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
        </properties>
    </persistence-unit>
</persistence>

the content of application-context is :

<?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:tx="http://www.springframework.org/schema/tx"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">



<!-- bean of data source -->
    <bean id="datasource"
        class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
        <property name="url" value="jdbc:mysql://localhost:3306/db_bri_sante"></property>
        <property name="username" value="root"></property>
        <property name="password" value=""></property>
    </bean>
    <!-- bean of persistence manager -->
    <bean id="persistenceUnitManager" class="org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager">
        <property name="defaultDataSource" ref="datasource"></property>
        <property name="persistenceXmlLocations">
            <list>
                <value>classpath*:META-INF/persistence.xml</value>
            </list>
        </property>
    </bean>
    <!-- bean definition entityManagerFactory -->
    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="persistenceUnitManager" ref="persistenceUnitManager"></property>
        <property name="persistenceUnitName" value="UP_BRI_SANTE"></property>
    </bean>
    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory"></property>
    </bean>

    <tx:annotation-driven transaction-manager="transactionManager"/>
    <context:annotation-config></context:annotation-config>
    <context:component-scan base-package="com.bri.sante"></context:component-scan>  
</beans>

i need your helps and thank's in advance

user3578199
  • 1
  • 2
  • 5
  • change `hibernate.hbm2dll.auto` setting to `create`, possible values and their usage explained here http://stackoverflow.com/questions/18077327/hibernate-hbm2ddl-auto-possible-values-and-what-they-do-any-official-explanat – Lovababu Padala Jul 20 '16 at 11:43
  • i have trying all the possible value of hibernate.hbm2dll.auto ( update, create, create-drop) and it still the same things the tables are not created – user3578199 Jul 20 '16 at 11:52
  • can you add your unit test ?? – Mohamed Nabli Jul 20 '16 at 11:56
  • ` public class TestJPA { @BeforeClass public static void setUpBeforeClass() throws Exception { } @AfterClass public static void tearDownAfterClass() throws Exception { } @Before public void setUp() throws Exception { } @Test public void test1() { ClassPathXmlApplicationContext app= new ClassPathXmlApplicationContext(new String[]{"application-context.xml"}); assertTrue(true); } }` – user3578199 Jul 20 '16 at 12:02
  • It's hbm2ddl, not hbm2dll. ddl = data definition language. dll = dynamically linked library – JB Nizet Jul 20 '16 at 12:07
  • i change it to ddl and still not working – user3578199 Jul 20 '16 at 12:11

1 Answers1

0

this is my unit test

public class TestJPA {

    @BeforeClass
    public static void setUpBeforeClass() throws Exception {
    }

    @AfterClass
    public static void tearDownAfterClass() throws Exception {
    }

    @Before
    public void setUp() throws Exception {
    }

    @Test
    public void test1() {

        ClassPathXmlApplicationContext app= new ClassPathXmlApplicationContext(new String[]{"application-context.xml"});
        assertTrue(true);

    }

}
user3578199
  • 1
  • 2
  • 5