2 Replies Latest reply on Jun 23, 2008 2:58 PM by Denis Golovin

    Auto generate database on startup

    Shervin Asgari Master

      Hello.

      I have a Seam / Ejb3 application and I want JBoss to automatically create the database if it is not present on startup.

      Any idea on how to do this?

        • 1. Re: Auto generate database on startup
          Shervin Asgari Master

          I think I found it by using persistence.xml.
          Thanks anyways

          • 2. Re: Auto generate database on startup
            Denis Golovin Master

            This can be done by adding hibernate.hbm2ddl.auto property for persistence-unit in persistence.xml file.
            It enable utomatic validation or export schema DDL to the database when the SessionFactory is created. With create-drop, the database schema will be dropped when the SessionFactory is closed explicitly.
            Available values are: validate | update | create | create-drop

            Exampe:

            <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_1_0.xsd"
             version="1.0">
             <persistence-unit name="sample">
             <jta-data-source>java:/DefaultDS</jta-data-source>
             <properties>
             <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
             <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
             </properties>
             </persistence-unit>
            </persistence>