-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Cant generate Schema using annotations with hibernate tools
PostPosted: Fri Nov 13, 2009 9:59 pm 
Newbie

Joined: Fri Nov 13, 2009 8:58 pm
Posts: 4
Hi guys, this is my first post here, i hope that you can help me out.
Here´s the thing:
I am trying to generate my database schema from Annotations, I am using Hibernate Tools ant task in order to accomplish it. Although there are virtually no errors, somehow the tables doesnt get created. I am posting my hibernate.cfg.xml, the build_hibernate.xml file, the ant logs and my model object.

hibernate.cfg.xml:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
      "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
      "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <property name="hibernate.hbm2ddl.auto">create</property>
        <property name="hibernate.cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
      <property name="hibernate.connection.autoReconnect">true</property>
      <property name="hibernate.connection.autoReconnectForPools">true</property>
      <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
      <property name="hibernate.connection.is-connection-validation-required">true</property>
      <property name="hibernate.connection.username">desafio</property>
       <property name="hibernate.connection.password">desafio</property>
      <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/desafio</property>
       <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
      
       <mapping class="Deporte" />
      
    </session-factory>
</hibernate-configuration>



Here is my build_hibernate.xml:

Under project.class.path the following the required jars are stored:
hibernate-tools.jar
hibernate3.jar
hibernate-annotations.jar
hibernate-commons-annotations.jar
freemarker.jar

hibernate-tools, hibernate-annotations, and hibernate-common-annotations were extracted from the hibernate tools 3.2.4.GA distribution.

Code:

<?xml version="1.0" encoding="UTF-8"?>
<project name="HibernateAnt" basedir=".">
   <property name="src.dir" location="src" />
   <property name="lib.dir" location="WebContent/WEB-INF/lib" />
   <property name="bin.dir" location="build/hibernate" />

   <path id="project.class.path">
      <path>
         <pathelement location="${lib.dir}/hibernate3.jar" />
         <fileset dir="${lib.dir}">
            <include name="**/*.jar" />
         </fileset >
         <pathelement path="${bin.dir}" />
      </path>
   </path>

   <!-- Compile the java source of the project -->
   <target name="compile"  description="Compiles all Java classes">
      <javac srcdir="${src.dir}" destdir="${bin.dir}" debug="on" optimize="off" deprecation="on">
         <classpath refid="project.class.path" />
      </javac>
   </target>

   <target name="annotations" description="Update Schema">
       <taskdef name="hibernatetool"
       classname="org.hibernate.tool.ant.HibernateToolTask"
       classpathref ="project.class.path" />   
            
      <hibernatetool destdir="${bin.dir}">
       <classpath>
        <path location="${bin.dir}/classes"/>
       </classpath>
   
      <annotationconfiguration configurationfile="${src.dir}/hibernate.cfg.xml"/>
      <hbm2ddl export="true" outputfilename="dump.sql"/>      
      </hibernatetool>
   </target>
</project>




Here is the log for the ant task in Eclipse, the task is clean it does not throws any errors.
Code:

Buildfile: H:\Proyecto\WorkspaceDT2\BackOfficeDT\build_hibernate.xml
annotations:
[hibernatetool] Executing Hibernate Tool with a Hibernate Annotation/EJB3 Configuration
[hibernatetool] 1. task: hbm2ddl (Generates database schema)
[hibernatetool] 0 [main] INFO annotations.Version  - Hibernate Annotations 3.3.0.GA
[hibernatetool] 31 [main] INFO cfg.Environment  - Hibernate 3.2.5
[hibernatetool] 31 [main] INFO cfg.Environment  - hibernate.properties not found
[hibernatetool] 47 [main] INFO cfg.Environment  - Bytecode provider name : cglib
[hibernatetool] 47 [main] INFO cfg.Environment  - using JDK 1.4 java.sql.Timestamp handling
[hibernatetool] 219 [main] INFO cfg.Configuration  - configuring from file: hibernate.cfg.xml
[hibernatetool] 406 [main] INFO cfg.Configuration  - Configured SessionFactory: null
[hibernatetool] 906 [main] INFO cfg.AnnotationConfiguration  - Hibernate Validator not found: ignoring
[hibernatetool] 1719 [main] INFO tool.Version  - Hibernate Tools 3.2.4.GA
[hibernatetool] 1859 [main] INFO dialect.Dialect  - Using dialect: org.hibernate.dialect.MySQLDialect
[hibernatetool] 2125 [main] INFO cfg.AnnotationConfiguration  - Hibernate Validator not found: ignoring
[hibernatetool] 2125 [main] INFO cfg.AnnotationConfiguration  - Hibernate Validator not found: ignoring
[hibernatetool] 2140 [main] INFO hbm2ddl.SchemaExport  - Running hbm2ddl schema export
[hibernatetool] 2140 [main] INFO hbm2ddl.SchemaExport  - writing generated schema to file: H:\Proyecto\WorkspaceDT2\BackOfficeDT\build\hibernate\dump.sql
[hibernatetool] 2140 [main] INFO hbm2ddl.SchemaExport  - exporting generated schema to database
[hibernatetool] 2156 [main] INFO connection.DriverManagerConnectionProvider  - Using Hibernate built-in connection pool (not for production use!)
[hibernatetool] 2156 [main] INFO connection.DriverManagerConnectionProvider  - Hibernate connection pool size: 20
[hibernatetool] 2156 [main] INFO connection.DriverManagerConnectionProvider  - autocommit mode: false
[hibernatetool] 2312 [main] INFO connection.DriverManagerConnectionProvider  - using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost:3306/desafio
[hibernatetool] 2312 [main] INFO connection.DriverManagerConnectionProvider  - connection properties: {is-connection-validation-required=true, autoReconnect=true, user=desafio, password=****, autoReconnectForPools=true}
[hibernatetool] 4609 [main] INFO hbm2ddl.SchemaExport  - schema export complete
[hibernatetool] 4609 [main] INFO connection.DriverManagerConnectionProvider  - cleaning up connection pool: jdbc:mysql://localhost:3306/desafio
BUILD SUCCESSFUL
Total time: 5 seconds




Finally, a sample class with a simple annotation to be generated. Just by declaring the @Entity annotation over the class, the table should be generated, right??

Code:

package com.desafiodt.model;

import java.io.Serializable;
import org.hibernate.annotations.Entity;
import org.hibernate.annotations.Table;


@Entity
@Table(appliesTo="Deporte")
public class Deporte implements Serializable{
   /**
    *
    */
   private static final long serialVersionUID = 1L;
   
   private String nombre;
   private long id;

   /**
    * @param id the id to set
    */
   public void setId(long id) {
      this.id = id;
   }

   /**
    * @return the id
    */
   public long getId() {
      return id;
   }
   public String getNombre() {
      return nombre;
   }

   public void setNombre(String nombre) {
      this.nombre = nombre;
   }
}




Like I said, the operations are clean of any errors, however nor the tables in the database are updated, neither the dump.sql file is filled with the create statetments.
Hope I´ve made myself clear, any help will be really appretiated.
Thanks in advance.
Regards


Top
 Profile  
 
 Post subject: Re: Cant generate Schema using annotations with hibernate tools
PostPosted: Tue Nov 17, 2009 12:43 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
you are using annotationconfiguration which does not automatically scan for annotations.
You have to use jpaconfiguration instead which uses the JPA standard scanning mechanism.

_________________
Max
Don't forget to rate


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.