Hi!
Just letting you know that I now has implemented support for the <meta>
attribute in Hibernate hbm.xml.
My local codegenerator does now support the following <meta attributes>
tags.
"description" - Text that will be included as an javadoc comment
"extends" - name of the class the entity class should extend. Is ignored in
subclass and joined-subclass.
"implements" - name of an interface the entity class should implement. Can
be repeated N times.
"generated-class" - name that the codegenerator should use instead of the
actual mapped class. This class would then be extended by the actual mapped
class (done by the user)
A fullblown example could be as follows:
<class name="codegen.test.Person">
<meta attribute="extends">codegen.test.AbstractPersistent</meta>
<meta attribute="implements">codegen.test.IVersionable</meta>
<meta attribute="implements">codegen.test.IAuditable</meta>
<meta attribute="generated-class">codegen.test.AutoPerson</meta>
<meta attribute="description">
AutoPerson is a simple class, which illustrates the possibilities of the
Hibernate meta tag.
@author Zim Zala Bim
</meta>
<id name="id" type="string"><generator class="assigned"/></id>
<one-to-one name="myUser" class="codegen.test.User"/>
<property name="name" type="string">
<meta attribute="description">A javadoc comment for the field name...</meta>
</property>
</class>
And this currently gives the following code:
package codegen.test;
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;
/**
* AutoPerson is a simple class, which illustrates the possibilities of the
Hibernate meta tag.
* @author Zim Zala Bim
*/
abstract public class AutoPerson extends codegen.test.AbstractPersistent
implements Serializable, codegen.test.IVersionable, codegen.test.IAuditable
{
/** identifier field */
private String id;
/**
* A javadoc comment for the field name...
*/
private String name;
/** nullable persistent field */
private codegen.test.User myUser;
/** full constructor */
public AutoPerson(java.lang.String id, java.lang.String name,
codegen.test.User myUser) {
this.id = id;
this.name = name;
this.myUser = myUser;
}
/** default constructor */
public AutoPerson() {
}
/** minimal constructor */
public AutoPerson(java.lang.String id) {
this.id = id;
}
public java.lang.String getId() {
return this.id;
}
public void setId(java.lang.String id) {
this.id = id;
}
public java.lang.String getName() {
return this.name;
}
public void setName(java.lang.String name) {
this.name = name;
}
public codegen.test.User getMyUser() {
return this.myUser;
}
public void setMyUser(codegen.test.User myUser) {
this.myUser = myUser;
}
public String toString() {
return ToStringBuilder.reflectionToString(this);
}
public boolean equals(Object other) {
if ( !(other instanceof AutoPerson) ) return false;
AutoPerson castOther = (AutoPerson) other;
return new EqualsBuilder().append(this.id, castOther.id).isEquals();
}
public int hashCode() {
return new HashCodeBuilder().append(id).toHashCode();
}
}
I'll work a little more with regards to adding support for these meta-tags
for composites, and all the collection types (if at all reasonable) + a wiki
page describing the capabilities of the codegenerator.
Hope you like it :) I welcome any comments :)
/max
p.s. A side question: Does anyone have an "Good Code Example" for which code
you would like to be generated for add and remove methods for bi-directional
collections ?
|