Just in case anybody else needs it...

---------- Forwarded message ----------
From: Jose Gonzalez Gomez <[EMAIL PROTECTED]>
Date: 06-jul-2006 8:40
Subject: Re: [m2] Frustration getting Maven 2 and Hibernate working together
To: Paul Kuykendall <[EMAIL PROTECTED]>

Ok, here we go...

First of all, add this to settings.xml (in your .m2 directory) in order to
be able to download plugins from the mojo repository:

<settings>
 <!-- Proxy, servers, whatever you have here -->
 <!-- Access to mojo.codehaus.org plugins -->
 <profiles>
   <profile>
     <id>Snapshots</id>

    <pluginRepositories>
      <pluginRepository>
        <id>Maven Snapshots</id>
        <url>http://snapshots.maven.codehaus.org/maven2/</url>
        <snapshots>
          <enabled>true</enabled>
        </snapshots>
        <releases>
          <enabled>false</enabled>
        </releases>
      </pluginRepository>
    </pluginRepositories>
   </profile>
 </profiles>
 <activeProfiles>
   <activeProfile>Snapshots</activeProfile>
 </activeProfiles>
</settings>

Now, declare some dependencies in your pom, including the plugin
configuration and your desired JDBC driver (PostgreSQL in this case):


<?xml version="1.0" encoding="UTF-8"?>
 [...]

 <build>
   <plugins>
     <plugin>
       <groupId>org.codehaus.mojo</groupId>
       <artifactId>hibernate3-maven-plugin</artifactId>

       <version>1.0-SNAPSHOT</version>
       <configuration>
         <hibernate>

<configurationFile>/src/main/resources/hibernate.cfg.xml</configurationFile>

         </hibernate>
         <outputDirectory>
           <hbm2cfgxml>src/main/resources</hbm2cfgxml>
         </outputDirectory>
       </configuration>
     </plugin>
   </plugins>
   <extensions>
     <extension>
       <groupId>postgresql</groupId>
       <artifactId>postgresql</artifactId>
       <version>8.1-407.jdbc3 </version>
     </extension>
   </extensions>
 </build>
 <!-- =============== HIBERNATE PLUGIN =============== -->
 <dependencies>
   [...]
   <dependency>
     <groupId>javax.persistence</groupId>
     <artifactId>persistence-api</artifactId>

   </dependency>
   <dependency>
     <groupId>org.hibernate</groupId>
     <artifactId>hibernate-annotations</artifactId>
     <version>3.2.0.cr1</version>
     <exclusions>
       <exclusion>
         <groupId>javax.persistence </groupId>
         <artifactId>ejb</artifactId>
       </exclusion>
     </exclusions>
   </dependency>
 </dependencies>
</project>

Comments on this: first of all, I have no version declared for
persistence-api because I have a parent pom with dependency management (I
will include hibernate-annotations there once I have an stable
configuration); you must include hibernate-annotations as a dependency in
your project only if you want to use hibernate propietary annotations; if
you do include hibernate-annotations you must exclude the
javax.persistence:ejb dependency, as it uses and old draft version I've been
unable to find on the Internet.

Finally you must create your /src/main/resources/hibernate.cfg.xml,
something like this:

<?xml version=' 1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
   "-//Hibernate/Hibernate Configuration DTD//EN"
   " http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd";>

<hibernate-configuration>
 <!-- a SessionFactory instance listed as /jndi/name -->
 <session-factory name="java:hibernate/SessionFactory">
   <!-- properties -->
   <property name="connection.driver_class">org.postgresql.Driver
</property>
   <property 
name="connection.url">jdbc:postgresql://your.server/yourDatabase</property>

   <property name="connection.username">yourUser</property>
   <property name="connection.password">yourPassword</property>
   <property name="dialect"> org.hibernate.dialect.PostgreSQLDialect
</property>
   <property name="show_sql">false</property>
   <property name="transaction.factory_class">
org.hibernate.transaction.JTATransactionFactory </property>
   <property name="jta.UserTransaction
">java:comp/UserTransaction</property>

   <!-- mapping files -->
   <!-- <mapping package="org.surveyforge.classification " /> -->
   <mapping class="org.surveyforge.classification.Family" />
 </session-factory>
</hibernate-configuration>

I was testing a single class, I guess if you have a full package you may use
the commented line to include all the classes. Once I did this, I run mvn
hibernate3:hbm2ddl and the plugin connected to my database and created the
table. I think I don't miss anything...

HTH, best regards
Jose

2006/7/5, Paul Kuykendall <[EMAIL PROTECTED]>:

I would be more appreciative than you can ever imagine if you could send
that information.

Thanks!

/Paul

Reply via email to