-->
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.  [ 6 posts ] 
Author Message
 Post subject: Annotations, Empty DDL, a new twist?
PostPosted: Sat Dec 12, 2009 7:54 pm 
Beginner
Beginner

Joined: Fri Feb 24, 2006 1:18 pm
Posts: 25
The good news is that the problem is resolved, but in case others hit the same problem, I wanted to post this. Also, I have some questions about what I was doing wrong to make the process of exporting the simplest possible schema a bit challenging. As always thanks in advance for any assistance.

I wanted to test the simplest case of creating a class with an annotation and using SchemaExport to create the database table. Following the documentation at: https://www.hibernate.org/hib_docs/tool ... le/#d0e820, I set up the hibernateTool task definition, although it seemed that I needed many more jars that just hibernate-tools.jar, hibernate3.jar, freemarker.jar, {jdbc.driver.jar}. In particular, I needed jars for classes such as: LoggerFactory, StaticLoggerBinder, AnnotationConfiguration, TemplateLoader. I added all the necessary jars to my build.xml, but I was wondering why they weren't listed in the above url. I saw posts from others along similar lines - I wonder what we are all missing.

After fixing the above and adding my POJO classes to the "toolslib" path, I was able to run the hbm2ddl target. But the sql file that was generated was empty.

My build.xml looks like:
Code:
  <path id="toolslib9">
    <path location="${hibernate.plugin.tools.dir}/hibernate-tools.jar" />
    <path location="${hibernate.plugin.tools.dir}/freemarker.jar" />
    <path location="${hibernate.plugin.hibernate.dir}/commons-logging-1.0.4.jar" />      
    <path location="${hibernate.plugin.hibernate.dir}/hibernate3.jar" />
    <path location="${hibernate.required.lib.dir}/freemarker.jar" />
    <path location="${hibernate.annotations.dir}/hibernate-annotations.jar" />
    <fileset dir="${hibernate.annotations.lib.dir}">
      <include name="**/*.jar"/>
    </fileset>      
    <fileset dir="${hibernate.annotations.lib.test.dir}">
      <include name="**/*.jar"/>
    </fileset>
    <path location="${jdbc.driver.jar}" />
    <path location="${classes.dir}" />
  </path>
  <taskdef name="hibernatetool"
         classname="org.hibernate.tool.ant.HibernateToolTask"
         classpathref="toolslib9" />
  <target name="schemaExport">
    <hibernatetool destdir="ddl">
      <annotationconfiguration configurationfile="hibernate.cfg.xml"/>
      <hbm2ddl export="true"
        create="true"
        delimiter=";"
        format="true"
         haltonerror="true"
        outputfilename="create-tables.sql"/>
    </hibernatetool>
  </target>


My hibernate.cfg.xml is:
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.connection.driver_class">org.gjt.mm.mysql.Driver</property>
        <property name="hibernate.connection.password">x47b2lkp</property>
        <property name="hibernate.connection.url">jdbc:mysql://192.168.2.200/potluck</property>
        <property name="hibernate.connection.username">root</property>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>
        <mapping class="com.rb.potluck.Person" />
    </session-factory>
</hibernate-configuration>


And my Java class is:
Code:
package com.rb.potluck;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import org.hibernate.annotations.Entity;

@Entity
public class Person {
  private Integer id;
  private Integer version;
  private String emailAddress;
 
  @Id
  @GeneratedValue
  public Integer getId() {
    return id;
  }
  public void setId(Integer id) {
    this.id = id;
  }
  // More getters, setters removed for brevity
}


Everything seemed to be as simple as possible - but nothing in the resulting SQL file. No errors from the ant command, nothing relevant in ant -debug. No errors in the Eclipse error log.

The problem turned out to be the import statement in my Person class. Rather than using:
Code:
import org.hibernate.annotations.Entity;

I changed to:
Code:
import javax.persistence.Entity;


And then everything worked. Don't know if anyone else is likely to make the wrong import choice - but I thought I would post anyway. If anyone can help me understand the need for all the extra jars, that would be great.

One last comment - I had started by trying to "Run Schema Export" in the Hibernate Configurations view, but it didn't work, so I switched to the ant based approach above. I would start the "Run Schema Export", get the confirmation dialog box and then nothing further - no errors, no feedback, just silence. My searching indicates that this is a known problem, but I was interested in confirming that.

Thanks again!
RB


Top
 Profile  
 
 Post subject: Re: Annotations, Empty DDL, a new twist?
PostPosted: Sun Dec 13, 2009 12:14 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
first of, the hibernate annotation is *addition* to the standard JPA entity annotation. Similar to what we got for most other entities in JPA, i.e there is also a hibernate of the Table and Column annotation. These are *extras* to do more things beyond what the spec defines.

Yes, its annoying but no real good solution for it beyond having to just remember using the right annotation first.

With respect to the jars then I'm failing to see which of the jars you find "not specified" ?
The list is the minimal list of jars needed, but of course if you use hibernate annotations you need to include hibernate annotations on the classpath to have the annotations available to the tools.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Re: Annotations, Empty DDL, a new twist?
PostPosted: Sun Dec 13, 2009 1:08 pm 
Beginner
Beginner

Joined: Fri Feb 24, 2006 1:18 pm
Posts: 25
Thank you for the quick reply. In addition to the hibernate-annotations.jar (which is completely reasonable), I found that I also needed jars like the following:
log4j.jar
slf4j-log4j12.jar
dom4j.jar
commons-logging.jar
Note: The names are "approximate" as my notes aren't always that detailed and for my ultimate solution I just used all the jars in hiberate-annotations/lib and lib/test.

My results were similar to another post that said the following jars were needed:
slf4j-api-1.5.6.jar
slf4j-log4j12-1.5.6.jar
log4j-1.2.15.jar

Any insights are appreciated - thanks!


Top
 Profile  
 
 Post subject: Re: Annotations, Empty DDL, a new twist?
PostPosted: Mon Dec 14, 2009 8:38 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
So these are all hibernate dependencies - you need them for basic usage of hibernate too.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Re: Annotations, Empty DDL, a new twist?
PostPosted: Mon Dec 14, 2009 10:42 am 
Beginner
Beginner

Joined: Fri Feb 24, 2006 1:18 pm
Posts: 25
I was just thinking that if all those jars are needed for everyone, then adding the list to the documentation would save people the frustration of running into a number of ClassNotFoundExceptions, then having to find the jar that has that class, then adding that jar, only to have to run through the same cycle several times.

If those jars were just necessary in my environment, then I can see the logic in keeping the documentation to the set of core jar files needed by all.

Thanks again for your perspective.


Top
 Profile  
 
 Post subject: Re: Annotations, Empty DDL, a new twist?
PostPosted: Mon Dec 14, 2009 10:47 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
Those jars are needed/different depending on your version of Hibernate you use together with hibernate tools. That's why we simply just list "hibernate dependencies". But yes, we should make it more obvious.

_________________
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.  [ 6 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.