Hi,
According to the docs, I am trying to generate the Cat.java (as given in the quickstart example) based on the mapping file.
The mapping file Cat.hbm.xml is (the only thing that I have changed is the package for the cat)
-----------------------------------------------------------------------------------
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="a.b.Cat" table="CAT">
<!-- A 32 hex character is our surrogate key. It's automatically
generated by Hibernate with the UUID pattern. -->
<id name="id" type="string" unsaved-value="null" >
<column name="CAT_ID" sql-type="char(32)" not-null="true"/>
<generator class="uuid.hex"/>
</id>
<!-- A cat has to have a name, but it shouldn' be too long. -->
<property name="name">
<column name="NAME" sql-type="varchar(16)" not-null="true"/>
</property>
<property name="sex"/>
<property name="weight"/>
</class>
</hibernate-mapping>
---------------------------------------------------------------------------
And my ant task is :
---------------------------------------------------------------------------
<target name="hbm2java" description="Generate .java from .hbm.xml files.">
<taskdef name="hbm2java" classname="net.sf.hibernate.tool.hbm2java.Hbm2JavaTask" classpathref="project.classpath"/>
<hbm2java output="${src}" classpathref="project.classpath">
<fileset dir="${src}">
<include name="**/*.hbm.xml"/>
</fileset>
</hbm2java>
</target>
---------------------------------------------------------------------------
When I generate the Cat.java, I get this:
---------------------------------------------------------------------------
package a.b;
import java.io.Serializable;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
/** @author Hibernate CodeGenerator */
public class Cat implements Serializable {
/** identifier field */
private String id;
/** full constructor */
public Cat() {
}
public String getId() {
return this.id;
}
public void setId(String id) {
this.id = id;
}
public String toString() {
return new ToStringBuilder(this)
.append("id", getId())
.toString();
}
public boolean equals(Object other) {
if ( !(other instanceof Cat) ) return false;
Cat castOther = (Cat) other;
return new EqualsBuilder()
.append(this.getId(), castOther.getId())
.isEquals();
}
public int hashCode() {
return new HashCodeBuilder()
.append(getId())
.toHashCode();
}
}
-----------------------------------------------------------------
My question is :
The get/set methods are not being created for "name" "sex" and "weight".
I am using the latest bin version 2.1 with extension version 2.0.2.
Am I missing something here.
Also, pls correct me if I am wrong but as I understand, contrary to the documentation, for SchemaExport, the code needs to be compiled first since SchemaExport needs the class along with the mapping xml to create the schema.
Therefore for middle approach, first I could hand edit the mappiung file, then run the hbm2java, and then compile the code and then only run schemaexport...right ??
Can anyone please help me!!
Thanks
Shishir
|