-->
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.  [ 3 posts ] 
Author Message
 Post subject: hbm2jav - facing problem
PostPosted: Tue Jan 20, 2004 5:35 pm 
Regular
Regular

Joined: Fri Jan 16, 2004 4:48 am
Posts: 56
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


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 20, 2004 7:26 pm 
Regular
Regular

Joined: Fri Jan 16, 2004 4:48 am
Posts: 56
Aha....found the glitch. Is this a bug or a feature or something that I may have missed in the documentation ?

When I changed the way the properties were defined to:
----------------------------------------------------------------------------------
<property name="name" column="name" type="string" length="16" not-null="true"/>
<property name="sex" column="sex" type="char" length="1"/>
<property name="weight" column="weight" type="string" length="10"/>
----------------------------------------------------------------------------------

the schema got created correctly.


The following definition as mentioned in the quickstart maping html for name, sex and weight caused hbm2java to either error out or skip generation of the get/set property:

---------------------------------------------------------------------------------
<property name="name">
<column name="NAME" sql-type="varchar(16)" not-null="true"/>
</property>

<property name="sex"/>
<property name="weight"/>

--------------------------------------------------------------------------------

I can understand about "sex" and "weight", but "name" should have been okay. Seems the column tag is not supported. Is this a documented limitation , or again, am I wrong somewhere ??

Thanks
Shishir


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 21, 2004 9:45 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Please submit to jira

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.