Hibernate version:
Hibernate 3.1beta2
Hibernate Annotations 3.1beta4
$ java -version
java version "1.5.0_03"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_03-b07)
Java HotSpot(TM) Client VM (build 1.5.0_03-b07, mixed mode, sharing)
hibernate.cfg.xml
<?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="show_sql">true</property>
<property name="dialect">net.sf.hibernate.dialect.PostgreSQLDialect</property>
<property name="hibernate.query.substitutions">true 1, false 0</property>
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.url">jdbc:postgresql://192.168.69.10/bk?useUnicode=true</property>
<property name="hibernate.connection.username">bk</property>
<property name="hibernate.connection.password">bk</property>
<!-- Mapping files -->
<mapping package="com.som.bk.server.data"/>
<mapping class="com.som.bk.server.data.CommandName"/>
</session-factory>
</hibernate-configuration>
build.xml section
<!-- javac classpath -->
<path id="classpath.default">
<fileset dir="${dir.lib}" >
<include name="**/*.jar" />
</fileset>
<pathelement path="${dir.src.java}"/>
<pathelement path="${dir.work.java}"/>
</path>
<property name="classpath.default" refid="classpath.default"/>
<!-- build tools classpath -->
<path id="classpath.build">
<fileset dir="${dir.build.lib}" >
<include name="**/*.jar" />
</fileset>
<pathelement path="${dir.build.class}"/>
<path refid="classpath.default"/>
</path>
<property name="classpath.build" refid="classpath.build"/>
<taskdef
name="hibernatetool"
classname="org.hibernate.tool.ant.HibernateToolTask"
classpathref="classpath.build"/>
<target name="dbschema" depends="init,compile" description="Generate the database schema">
<hibernatetool destdir="${dir.work.sql}">
<classpath refid="classpath.build"/>
<annotationconfiguration configurationfile="${dir.work.conf}/hibernate.cfg.xml"/>
<hbm2ddl drop="false" outputfilename="${ant.project.name}-schema.sql"/>
</hibernatetool>
</target>
CommandName.java
@Entity
public class CommandName implements Serializable
{
public static final long serialVersionUID = 1;
private static org.apache.log4j.Logger log
= org.apache.log4j.Logger.getLogger(CommandName.class);
public CommandName() {}
public CommandName(String name)
{
this.name = name;
}
@Id
public long getId() {return id;}
public void setId(long x) {id = x;}
private long id = -1;
public static final String ID = "id";
public String getName() {return name;}
public void setName(String x) {name = x;}
public static final String NAME = "name";
private String name = null;
//---------------------------------------------------------------------------- Logic
public String toString() {
return new ToStringBuilder(this)
.append("id", getId())
.append("name", getName())
.toString();
}
public boolean equals(Object other) {
if ( !(other instanceof CommandName) ) return false;
CommandName castOther = (CommandName) other;
return new EqualsBuilder()
.append(this.getId(), castOther.getId())
.isEquals();
}
public int hashCode() {
return new HashCodeBuilder()
.append(getId())
.toHashCode();
}
}
Debug level Hibernate log excerpt:
$ ant dbschema
Buildfile: build.xml
init:
compile:
dbschema:
[hibernatetool] Executing Hibernate Tool with a Hibernate Annotation/EJB3 Configuration
[hibernatetool] 1. task: hbm2ddl (Generates database schema)
[hibernatetool] 14:50:06,640 [INFO ] Environment - Hibernate 3.1 beta 2
[hibernatetool] 14:50:06,656 [INFO ] Environment - hibernate.properties not found
[hibernatetool] 14:50:06,671 [INFO ] Environment - using CGLIB reflection optimizer
[hibernatetool] 14:50:06,671 [INFO ] Environment - using JDK 1.4 java.sql.Timestamp handling
[hibernatetool] 14:50:06,859 [INFO ] Configuration - configuring from file: hibernate.cfg.xml
[hibernatetool] 14:50:06,968 [DEBUG] DTDEntityResolver - trying to locate
http://hibernate.sourceforge.net/hibern ... on-3.0.dtd in classpath under org/hibernate/
[hibernatetool] 14:50:06,984 [DEBUG] DTDEntityResolver - found
http://hibernate.sourceforge.net/hibern ... on-3.0.dtd in classpath
[hibernatetool] 14:50:07,156 [DEBUG] Configuration - show_sql=true
[hibernatetool] 14:50:07,156 [DEBUG] Configuration - dialect=net.sf.hibernate.dialect.PostgreSQLDialect
[hibernatetool] 14:50:07,156 [DEBUG] Configuration - hibernate.query.substitutions=true 1, false 0
[hibernatetool] 14:50:07,156 [DEBUG] Configuration - hibernate.connection.driver_class=org.postgresql.Driver
[hibernatetool] 14:50:07,156 [DEBUG] Configuration - hibernate.connection.url=jdbc:postgresql://192.168.69.10/bk?useUnicode=true
[hibernatetool] 14:50:07,156 [DEBUG] Configuration - hibernate.connection.username=bk
[hibernatetool] 14:50:07,171 [DEBUG] Configuration - hibernate.connection.password=bk
[hibernatetool] 14:50:07,171 [DEBUG] AnnotationConfiguration - null<-org.dom4j.tree.DefaultAttribute@cd5f8b [Attribute: name package value "com.som.bk.server.data"]
[hibernatetool] 14:50:07,171 [INFO ] AnnotationConfiguration - Mapping package com.som.bk.server.data
BUILD FAILED
java.lang.NoSuchMethodError: org.hibernate.cfg.Mappings.<init>(Ljava/util/Map;Ljava/util/Map;Ljava/util/Map;Ljava/util/Map;Ljava/util/Map;Ljava/util/Map;Ljava/util/Map;Ljava/util/List;Ljava/util/List;Lorg/hibernate/cfg/NamingStrategy;Ljava/util/Map;Ljava/util/Map;Ljava/util/Map;)V
Total time: 2 seconds
--------
Does anyone know what would cause this problem?
I think I did the same setup as in the documentation, although the annotations documentation contains errors (malformed xml and such) so I'm not sure.