title: Schema generation with Maven Hibernate3 plugin
body: <p>I'm trying to setup a simple hibernate + maven project. I'm following steps as mentioned in Chapter 2 of <a href="http://www.manning.com/bauer2/" rel="nofollow noreferrer">Java presistence with hibernate</a> (only diff is I'm maven using instead of Ant). However, while trying to generate the schema with <a href="http://mojo.codehaus.org/maven-hibernate3/hibernate3-maven-plugin/" rel="nofollow noreferrer">maven hibernate 3 plugin</a>, it seems like it is not able to create the required tables.</p>
  <h2>Code &amp; Resources</h2>
  <h3>POM.xml</h3>
  <pre class="lang-xml prettyprint-override"><code>&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
    &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
    &lt;groupId&gt;com.gs.bce&lt;/groupId&gt;
    &lt;artifactId&gt;SpringExample&lt;/artifactId&gt;
    &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
    
    &lt;properties&gt;
      &lt;maven.compiler.source&gt;1.6&lt;/maven.compiler.source&gt;
      &lt;maven.compiler.target&gt;1.6&lt;/maven.compiler.target&gt;
      &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
    &lt;/properties&gt;
    
    
    &lt;dependencies&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-core&lt;/artifactId&gt;
          &lt;version&gt;3.0.5.RELEASE&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-beans&lt;/artifactId&gt;
          &lt;version&gt;3.0.5.RELEASE&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-context&lt;/artifactId&gt;
          &lt;version&gt;3.0.5.RELEASE&lt;/version&gt;
      &lt;/dependency&gt;
    
      &lt;dependency&gt;
          &lt;groupId&gt;org.hsqldb&lt;/groupId&gt;
          &lt;artifactId&gt;hsqldb&lt;/artifactId&gt;
          &lt;version&gt;2.0.0&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
          &lt;artifactId&gt;hibernate-c3p0&lt;/artifactId&gt;
          &lt;version&gt;3.3.2.GA&lt;/version&gt;
      
      &lt;/dependency&gt;
      
  
  
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
          &lt;artifactId&gt;slf4j-log4j12&lt;/artifactId&gt;
          &lt;version&gt;1.5.8&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;javassist&lt;/groupId&gt;
          &lt;artifactId&gt;javassist&lt;/artifactId&gt;
          &lt;version&gt;3.12.1.GA&lt;/version&gt;
      &lt;/dependency&gt;
    &lt;/dependencies&gt;  
      &lt;build&gt;
      &lt;plugins&gt;
        &lt;plugin&gt;
          &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
          &lt;artifactId&gt;hibernate3-maven-plugin&lt;/artifactId&gt;
          &lt;version&gt;2.2&lt;/version&gt;
          
            &lt;executions&gt;
            &lt;execution&gt;
              &lt;phase&gt;process-classes&lt;/phase&gt;
              &lt;goals&gt;
                &lt;goal&gt;hbm2ddl&lt;/goal&gt;
              &lt;/goals&gt;
            &lt;/execution&gt;
          &lt;/executions&gt;
          
          &lt;configuration&gt;
            &lt;components&gt;
              &lt;component&gt;
                &lt;name&gt;hbm2ddl&lt;/name&gt;
                &lt;implementation&gt;jdbcconfiguration&lt;/implementation&gt;
              &lt;/component&gt;
              &lt;component&gt;
                &lt;name&gt;hbm2hbmxml&lt;/name&gt;
                &lt;outputDirectory&gt;src/main/resources&lt;/outputDirectory&gt;
              &lt;/component&gt;
            &lt;/components&gt;
            &lt;componentProperties&gt;
              &lt;drop&gt;true&lt;/drop&gt;
              &lt;configurationfile&gt;/src/main/resources/hibernate.cfg.xml&lt;/configurationfile&gt;
                 &lt;outputfilename&gt;schema.sql&lt;/outputfilename&gt;
            &lt;/componentProperties&gt;
          &lt;/configuration&gt;
           &lt;dependencies&gt;
              &lt;dependency&gt;
          &lt;groupId&gt;org.hsqldb&lt;/groupId&gt;
          &lt;artifactId&gt;hsqldb&lt;/artifactId&gt;
          &lt;version&gt;2.0.0&lt;/version&gt;
      &lt;/dependency&gt;
          &lt;/dependencies&gt;
        &lt;/plugin&gt;
      &lt;/plugins&gt;
    &lt;/build&gt;
  &lt;/project&gt;
  </code></pre>
  <p>`</p>
  <h3>Output log</h3>
  <p>Output of my mainclass, where it is trying to access MESSAGES table (as mentioned in book).</p>
  <pre><code>18:27:34,357DEBUG SQL:111 - 
      select
          max(MESSAGE_ID) 
      from
          MESSAGES Hibernate: 
      select
          max(MESSAGE_ID) 
      from
          MESSAGES 18:27:34,363DEBUG JDBCExceptionReporter:92 - could not fetch initial value for increment generator [select max(MESSAGE_ID) from MESSAGES] java.sql.SQLException: user lacks privilege or object not found: MESSAGES
  </code></pre>
  <h3>Processing output</h3>
  <p>Output for process-classes goal</p>
  <pre><code>[INFO] Scanning for projects...
  [INFO]                                                                         
  [INFO] ------------------------------------------------------------------------
  [INFO] Building SpringExample 0.0.1-SNAPSHOT
  [INFO] ------------------------------------------------------------------------
  [INFO] 
  [INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ SpringExample ---
  [INFO] Using 'UTF-8' encoding to copy filtered resources.
  [INFO] Copying 3 resources
  [INFO] 
  [INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ SpringExample ---
  [INFO] Nothing to compile - all classes are up to date
  [INFO] 
  [INFO] &gt;&gt;&gt; hibernate3-maven-plugin:2.2:hbm2ddl (default) @ SpringExample &gt;&gt;&gt;
  [INFO] 
  [INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ SpringExample ---
  [INFO] Using 'UTF-8' encoding to copy filtered resources.
  [INFO] Copying 3 resources
  [INFO] 
  [INFO] &lt;&lt;&lt; hibernate3-maven-plugin:2.2:hbm2ddl (default) @ SpringExample &lt;&lt;&lt;
  [INFO] 
  [INFO] --- hibernate3-maven-plugin:2.2:hbm2ddl (default) @ SpringExample ---
  18:30:54,300  INFO org.hibernate.cfg.Environment - Hibernate 3.3.1.GA
  18:30:54,304  INFO org.hibernate.cfg.Environment - hibernate.properties not found
  18:30:54,306  INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist
  18:30:54,308  INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
  18:30:54,346  INFO org.hibernate.cfg.Configuration - configuring from url: file:/F:/workspace/SpringExample/src/main/resources/hibernate.cfg.xml
  [INFO] Configuration XML file loaded: file:/F:/workspace/SpringExample/src/main/resources/hibernate.cfg.xml
  18:30:54,475  INFO org.hibernate.cfg.JDBCMetaDataConfiguration - Ignoring null mapping
  18:30:54,475  INFO org.hibernate.cfg.Configuration - Configured SessionFactory: null
  [INFO] No hibernate properties file loaded.
  18:30:54,489  INFO org.hibernate.connection.DriverManagerConnectionProvider - Using Hibernate built-in connection pool (not for production use!)
  18:30:54,490  INFO org.hibernate.connection.DriverManagerConnectionProvider - Hibernate connection pool size: 20
  18:30:54,490  INFO org.hibernate.connection.DriverManagerConnectionProvider - autocommit mode: false
  18:30:54,495  INFO org.hibernate.connection.DriverManagerConnectionProvider - using driver: org.hsqldb.jdbcDriver at URL: jdbc:hsqldb:hsql://localhost
  18:30:54,495  INFO org.hibernate.connection.DriverManagerConnectionProvider - connection properties: {user=sa}
  18:30:54,685  INFO org.hibernate.cfg.SettingsFactory - RDBMS: HSQL Database Engine, version: 2.0.0
  18:30:54,685  INFO org.hibernate.cfg.SettingsFactory - JDBC driver: HSQL Database Engine Driver, version: 2.0.0
  18:30:54,716  INFO org.hibernate.dialect.Dialect - Using dialect: org.hibernate.dialect.HSQLDialect
  18:30:54,745  INFO org.hibernate.transaction.TransactionFactoryFactory - Using default transaction strategy (direct JDBC transactions)
  18:30:54,746  INFO org.hibernate.transaction.TransactionManagerLookupFactory - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
  18:30:54,746  INFO org.hibernate.cfg.SettingsFactory - Automatic flush during beforeCompletion(): disabled
  18:30:54,746  INFO org.hibernate.cfg.SettingsFactory - Automatic session close at end of transaction: disabled
  18:30:54,746  INFO org.hibernate.cfg.SettingsFactory - JDBC batch size: 15
  18:30:54,746  INFO org.hibernate.cfg.SettingsFactory - JDBC batch updates for versioned data: disabled
  18:30:54,747  INFO org.hibernate.cfg.SettingsFactory - Scrollable result sets: enabled
  18:30:54,747  INFO org.hibernate.cfg.SettingsFactory - JDBC3 getGeneratedKeys(): enabled
  18:30:54,747  INFO org.hibernate.cfg.SettingsFactory - Connection release mode: auto
  18:30:54,747  INFO org.hibernate.cfg.SettingsFactory - Default batch fetch size: 1
  18:30:54,747  INFO org.hibernate.cfg.SettingsFactory - Generate SQL with comments: disabled
  18:30:54,747  INFO org.hibernate.cfg.SettingsFactory - Order SQL updates by primary key: disabled
  18:30:54,747  INFO org.hibernate.cfg.SettingsFactory - Order SQL inserts for batching: disabled
  18:30:54,747  INFO org.hibernate.cfg.SettingsFactory - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
  18:30:54,748  INFO org.hibernate.hql.ast.ASTQueryTranslatorFactory - Using ASTQueryTranslatorFactory
  18:30:54,749  INFO org.hibernate.cfg.SettingsFactory - Query language substitutions: {}
  18:30:54,749  INFO org.hibernate.cfg.SettingsFactory - JPA-QL strict compliance: disabled
  18:30:54,749  INFO org.hibernate.cfg.SettingsFactory - Second-level cache: enabled
  18:30:54,749  INFO org.hibernate.cfg.SettingsFactory - Query cache: disabled
  18:30:54,749  INFO org.hibernate.cfg.SettingsFactory - Cache region factory : org.hibernate.cache.impl.NoCachingRegionFactory
  18:30:54,749  INFO org.hibernate.cfg.SettingsFactory - Optimize cache for minimal puts: disabled
  18:30:54,749  INFO org.hibernate.cfg.SettingsFactory - Structured second-level cache entries: disabled
  18:30:54,751  INFO org.hibernate.cfg.SettingsFactory - Echoing all SQL to stdout
  18:30:54,752  INFO org.hibernate.cfg.SettingsFactory - Statistics: disabled
  18:30:54,752  INFO org.hibernate.cfg.SettingsFactory - Deleted entity synthetic identifier rollback: disabled
  18:30:54,752  INFO org.hibernate.cfg.SettingsFactory - Default entity-mode: pojo
  18:30:54,753  INFO org.hibernate.cfg.SettingsFactory - Named query checking : enabled
  18:30:54,765 DEBUG org.hibernate.cfg.reveng.dialect.JDBCMetaDataDialect - getTables(null.null.null)
  18:30:54,767  INFO org.hibernate.connection.DriverManagerConnectionProvider - cleaning up connection pool: jdbc:hsqldb:hsql://localhost
  18:30:54,773  INFO org.hibernate.dialect.Dialect - Using dialect: org.hibernate.dialect.HSQLDialect
  18:30:54,777  INFO org.hibernate.tool.hbm2ddl.SchemaExport - Running hbm2ddl schema export
  18:30:54,778  INFO org.hibernate.tool.hbm2ddl.SchemaExport - writing generated schema to file: F:\workspace\SpringExample\target\hibernate3\sql\schema.sql
  18:30:54,778  INFO org.hibernate.tool.hbm2ddl.SchemaExport - exporting generated schema to database
  18:30:54,779  INFO org.hibernate.connection.DriverManagerConnectionProvider - Using Hibernate built-in connection pool (not for production use!)
  18:30:54,779  INFO org.hibernate.connection.DriverManagerConnectionProvider - Hibernate connection pool size: 20
  18:30:54,779  INFO org.hibernate.connection.DriverManagerConnectionProvider - autocommit mode: false
  18:30:54,779  INFO org.hibernate.connection.DriverManagerConnectionProvider - using driver: org.hsqldb.jdbcDriver at URL: jdbc:hsqldb:hsql://localhost
  18:30:54,779  INFO org.hibernate.connection.DriverManagerConnectionProvider - connection properties: {user=sa}
  18:30:54,883  INFO org.hibernate.tool.hbm2ddl.SchemaExport - schema export complete
  18:30:54,885  INFO org.hibernate.connection.DriverManagerConnectionProvider - cleaning up connection pool: jdbc:hsqldb:hsql://localhost
  [INFO] ------------------------------------------------------------------------
  [INFO] BUILD SUCCESS
  [INFO] ------------------------------------------------------------------------
  [INFO] Total time: 1.675s
  [INFO] Finished at: Sat May 07 18:30:54 IST 2011
  [INFO] Final Memory: 5M/47M
  [INFO] ------------------------------------------------------------------------
  18:30:54,988  INFO org.hibernate.connection.DriverManagerConnectionProvider - cleaning up connection pool: jdbc:hsqldb:hsql://localhost
  </code></pre>
  <h3>Hibernate configuration</h3>
  <p>My hibernate.cfg.xml</p>
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;!DOCTYPE hibernate-configuration SYSTEM
  &quot;http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd&quot;&gt;
  &lt;hibernate-configuration&gt;
  &lt;session-factory&gt;
  &lt;property name=&quot;hibernate.connection.driver_class&quot;&gt;
  org.hsqldb.jdbcDriver
  &lt;/property&gt;
  &lt;property name=&quot;hibernate.connection.url&quot;&gt;
  jdbc:hsqldb:hsql://localhost
  &lt;/property&gt;
  &lt;property name=&quot;hibernate.connection.username&quot;&gt;
  sa
  &lt;/property&gt;
  
  &lt;!-- &lt;property name=&quot;hibernate.connection.username&quot;&gt;
  bceuser123
  &lt;/property&gt; --&gt;
  
  
  &lt;property name=&quot;hibernate.dialect&quot;&gt;
  org.hibernate.dialect.HSQLDialect
  &lt;/property&gt;
  &lt;!-- Use the C3P0 connection pool provider --&gt;
  &lt;property name=&quot;hibernate.c3p0.min_size&quot;&gt;5&lt;/property&gt;
  &lt;property name=&quot;hibernate.c3p0.max_size&quot;&gt;20&lt;/property&gt;
  &lt;property name=&quot;hibernate.c3p0.timeout&quot;&gt;300&lt;/property&gt;
  &lt;property name=&quot;hibernate.c3p0.max_statements&quot;&gt;50&lt;/property&gt;
  &lt;property name=&quot;hibernate.c3p0.idle_test_period&quot;&gt;3000&lt;/property&gt;
  &lt;!-- Show and print nice SQL on stdout --&gt;
  &lt;property name=&quot;show_sql&quot;&gt;true&lt;/property&gt;
  &lt;property name=&quot;format_sql&quot;&gt;true&lt;/property&gt;
  &lt;!-- List of XML mapping files --&gt;
  &lt;mapping resource=&quot;hello/Message.hbm.xml&quot;/&gt;
  &lt;/session-factory&gt;
  &lt;/hibernate-configuration&gt;
  </code></pre>