I'm a total noob who's having trouble getting off the ground with Hibernate. I'm trying to use XDoclet for the first time and I'm having a problem.
I've got Ant 1.5.4 installed on my desktop. I've added 7 JARs to my ANT_HOME/lib: commons-collections-2.0.jar, commons-logging.jar, xjavadoc-1.0.jar, xdoclet-xdoclet-module-1.2b4.jar, xdoclet-hibernate-module-1.2b4.jar, and xdoclet-1.2b4.jar. I've got a build.xml that's tried and true - I've used it many times. I added the following new task to generate *.hbm.xml for me:
Code:
<target name="generate" depends="compile" description="run auto-generate tools">
<taskdef name="hibernate-xdoclet"
classname="xdoclet.modules.hibernate.HibernateDocletTask"
classpath="project.class.path"/>
<hibernate-xdoclet destdir="${output}"
excludedtags="@version,@author,@todo"
force="true"
mergedir="${output}"
verbose="false">
<fileset dir="${src.java}">
<include name="**/*.java"/>
</fileset>
</hibernate-xdoclet>
<!-- Upgrade grammar from Hibernate1 to Hibernate2 -->
<replace dir="${output}">
<include name="**/*.hbm.xml"/>
<replacefilter token="readonly=" value="inverse="/>
<replacefilter token="role=" value="name="/>
<replacefilter token="hibernate-mapping.dtd" value="hibernate-mapping-2.0.dtd"/>
</replace>
</target>
I've added Hibernate XDoclet tags to the classes from "Introduction to Hibernate" by Nick Heudecker [url]http://www.systemmobile.com/articles/IntroductionToHibernate.html#The%20Source%20Files
[/url]
Here's one of them:
Code:
package example;
import java.io.Serializable;
import java.util.Date;
/**
* Sample from TSS "Intro to Hibernate" article
* @author Michael O. Duffy Wed 17-Dec-2003
* @hibernate.class table="players"
*/
public class Player implements Comparable, Serializable
{
/** Open bracket around instance in String representation */
public static final String OPEN_BRACKET = "{";
/** Close bracket around instance in String representation */
public static final String CLOSE_BRACKET = "}";
/** Separator between fields in String representation */
public static final String SEPARATOR = ",";
/** Unique database id */
private long id;
/** Player first name */
private String firstName;
/** Player family name */
private String lastName;
/** Draft date */
private Date draftDate;
/** Annual salary (ought to be a money type) */
private float annualSalary;
/** Jersey number (why not a String for "00"?) */
private int jerseyNumber;
/** Parent team instance */
private Team team;
/**
* Copy constructor
* @param Player instance to copy
*/
public Player(Player p)
{
this.id = p.id;
this.firstName = p.firstName;
this.lastName = p.lastName;
this.draftDate = new Date(p.draftDate.getTime());
}
/**
* Read access to the annualSalary
* @hibernate.property column="annual_salary" type="float"
* @return the annualSalary.
*/
public float getAnnualSalary()
{
return this.annualSalary;
}
/**
* Write access to the annualSalary
* @param new value for the annualSalary
*/
public void setAnnualSalary(float annualSalary)
{
this.annualSalary = annualSalary;
}
/**
* Read access to the draftDate
* @hibernate.property column="draft_date" type="date"
* @return the draftDate.
*/
public Date getDraftDate()
{
return this.draftDate;
}
/**
* Write access to the draftDate
* @param new value for the draftDate
*/
public void setDraftDate(Date draftDate)
{
this.draftDate = draftDate;
}
/**
* Read access to the firstName
* @hibernate.property column="first_name" type="string" length="15"
* @return the firstName.
*/
public String getFirstName()
{
return this.firstName;
}
/**
* Write access to the firstName
* @param new value for the firstName
*/
public void setFirstName(String firstName)
{
this.firstName = firstName;
}
/**
* Read access to the id
* @hibernate.id column="id" type="long" unsaved-value="any" generator-class="sequence"
* @return the id.
*/
public long getId()
{
return this.id;
}
/**
* Write access to the id
* @param new value for the id
*/
public void setId(long id)
{
this.id = id;
}
/**
* Read access to the jerseyNumber
* @hibernate.property column="jersey_number" type="integer" length="1" non-null="true"
* @return the jerseyNumber.
*/
public int getJerseyNumber()
{
return this.jerseyNumber;
}
/**
* Write access to the jerseyNumber
* @param new value for the jerseyNumber
*/
public void setJerseyNumber(int jerseyNumber)
{
this.jerseyNumber = jerseyNumber;
}
/**
* Read access to the lastName
* @hibernate.property column="last_name" type="string" length="15" not-null="true"
* @return the lastName.
*/
public String getLastName()
{
return this.lastName;
}
/**
* Write access to the lastName
* @param new value for the lastName
*/
public void setLastName(String lastName)
{
this.lastName = lastName;
}
/**
* Read access to the team
* @hibernate.many-to-one name="team" class="example.Team" column="id"
* @return the team.
*/
public Team getTeam()
{
return this.team;
}
/**
* "Deep equals" for a Player
* @param instance to compare to the target
* @return true if the parameter is equal to the target; false otherwise
*/
public boolean equals(Object o)
{
if (this == o)
return true;
if (!(o instanceof Player))
return false;
Player p = (Player)o;
boolean sameId = (this.id == p.id);
return sameId;
}
/**
* Generate a unique hash code for a Team
* @return unique hash code for this Team
*/
public int hashCode()
{
int value = 7;
value = 11*value + 13*(int)(this.id ^ (this.id >>> 32));
return value;
}
/**
* String representation of a Team
* @return string representation of a Team
*/
public String toString()
{
String value
= OPEN_BRACKET
+ this.id
+ SEPARATOR
+ this.firstName
+ SEPARATOR
+ this.lastName
+ SEPARATOR
+ this.draftDate
+ SEPARATOR
+ this.annualSalary
+ SEPARATOR
+ this.team
+ SEPARATOR
+ this.team
+ CLOSE_BRACKET;
return value;
}
/**
* Comparable for sorting Players - sorts by id.
* @param instance of Player to compare to the target
* @return -1, 0, +1 if the instance id is less than, equal to,
* or treater than the target id.
* @throws ClassCastException if the parameter is not an instance
* of Player
*/
public int compareTo(Object o)
{
Player p = (Player)o;
return (int)(p.id - this.id);
}
}
When I run Ant I can see the [generate] task being called, but I don't get anything in the ${output} directory. There are no .hbm.xml files to be had anywhere, and no error messages. Ant runs to completion without complaining.
What have I done wrong? Hints are most appreciated. Thanks - MOD