Hibernate and xDoclet

Posted: February 25th, 2004 | 1 Comment »

Pascal took some of his valuable time to explain me his use of Hibernate and xDoclet:

i use hibernate as an ORM tool. it is the bridge between my Objects and relational DB (mysql). it offers persistence for objects, as long as these objects are following some simple rules (getters, setters, … actualy you just need to write them Bean style).

hibernate creates the tables, the SQL statements (DB system dependent…just tell it you use oracle…and it will create oracle compliant SQL….at deploy time). hibernate also takes care of IDs, polymorphism and so on. just tell it to persist an object….bumm. its stored (i just signed up for my marketing career at hibernate :-) )

for hibernate to know the relations, properties, …, you need to feed it with mapping files (*.hbm.xml). writing these files by hand is a pain. thats where xDoclet comes at rescue….just add some hibernate tags to your java comments and generate everything. magic.

java source code (note the @hibernate tags in the comments):

package magnolia.model;

/**
* @hibernate.class
* table=”T_SUPER”
*/
public class Super {
private Long id;
private String superProp;
/** *
* @hibernate.id
* generator-class=”hilo”
* column=”ID”
* unsaved-value=”null”
*/
public Long getId() {
return id;
}

/**
* @param id The id to set.
*/
public void setId(Long id) {
this.id = id;
}

/**
* DOCUMENT ME!
*
* @return String The username.
*
* @hibernate.property
* column=”SUPERPROP”
*/
public String getSuperProp() {
return superProp;
}

/**
* @param superProp The superProp to set.
*/
public void setSuperProp(String superProp) {
this.superProp = superProp;
}

}

here is the Super.hbm.xml file i get from xDoclet:


One Comment on “Hibernate and xDoclet”

  1. 1 andrea said at 9:13 pm on June 15th, 2005:

    hibernate leaves to have a class without ID.
    the tag will be:

    the attribute name of the tag ‘id’ it’s optional

    how can i express this situation with xdoclet?