Basically from the hbm files I want the following code generated
1) a pojo java class that extends a base pojo java class. That way if I have custome attributes I can put those in the user overridable pojo java class.
i.e:
Code:
package com.xxx.olbmaint.business.domain;
import com.xxx.olbmaint.business.domain.base.BaseCoveragePackageCode;
/**
* This is the object class that relates to the COVERAGE_PACKAGE_CODE table.
* Any customizations belong here.
*/
public class CoveragePackageCode extends BaseCoveragePackageCode {
/*[CONSTRUCTOR MARKER BEGIN]*/
public CoveragePackageCode () {
super();
}
/**
* Constructor for primary key
*/
public CoveragePackageCode (java.lang.String _coveragePackageCode) {
super(_coveragePackageCode);
}
/**
* Constructor for required fields
*/
public CoveragePackageCode (
java.lang.String _coveragePackageCode,
java.lang.String _benLimitUr) {
super (
_coveragePackageCode,
_benLimitUr);
}
/*[CONSTRUCTOR MARKER END]*/
}
Code:
package com.xxx.olbmaint.business.domain.base;
import java.io.Serializable;
/**
* This class has been automatically generated by Hibernate Synchronizer.
* For more information or documentation, visit The Hibernate Synchronizer page
* at http://www.binamics.com/hibernatesync or contact Joe Hudson at joe@binamics.com.
*
* This is an object that contains data related to the COVERAGE_PACKAGE_CODE table.
* Do not modify this class because it will be overwritten if the configuration file
* related to this class is modified.
*
* @hibernate.class
* table="COVERAGE_PACKAGE_CODE"
*/
public abstract class BaseCoveragePackageCode implements Serializable {
public static String PROP_COVERAGE_PACKAGE_CODE = "coveragePackageCode";
public static String PROP_END_DATE = "endDate";
public static String PROP_CONTAINED_IN_OLB = "containedInOlb";
public static String PROP_BEN_LIMIT_UR = "benLimitUr";
public static String PROP_EFFECTIVE_DATE = "effectiveDate";
private int hashCode = Integer.MIN_VALUE;
// primary key
private java.lang.String _coveragePackageCode;
// fields
private java.util.Date _effectiveDate;
private java.lang.String _benLimitUr;
private java.lang.String _containedInOlb;
private java.util.Date _endDate;
// collections
private java.util.Set _planPackageOdometers;
// constructors
public BaseCoveragePackageCode () {
initialize();
}
/**
* Constructor for primary key
*/
public BaseCoveragePackageCode (java.lang.String _coveragePackageCode) {
this.setCoveragePackageCode(_coveragePackageCode);
initialize();
}
/**
* Constructor for required fields
*/
public BaseCoveragePackageCode (
java.lang.String _coveragePackageCode,
java.lang.String _benLimitUr) {
this.setCoveragePackageCode(_coveragePackageCode);
this.setBenLimitUr(_benLimitUr);
initialize();
}
protected void initialize () {}
/**
* Return the unique identifier of this class
* @hibernate.id
* generator-class="uuid.hex"
* column="COVERAGE_PACKAGE_CODE"
*/
public java.lang.String getCoveragePackageCode () {
return _coveragePackageCode;
}
/**
* Set the unique identifier of this class
* @param _coveragePackageCode the new ID
*/
public void setCoveragePackageCode (java.lang.String _coveragePackageCode) {
this._coveragePackageCode = _coveragePackageCode;
this.hashCode = Integer.MIN_VALUE;
}
/**
* Return the value associated with the column: EFFECTIVE_DATE
*/
public java.util.Date getEffectiveDate () {
return _effectiveDate;
}
/**
* Set the value related to the column: EFFECTIVE_DATE
* @param _effectiveDate the EFFECTIVE_DATE value
*/
public void setEffectiveDate (java.util.Date _effectiveDate) {
this._effectiveDate = _effectiveDate;
}
/**
* Return the value associated with the column: BEN_LIMIT_UR
*/
public java.lang.String getBenLimitUr () {
return _benLimitUr;
}
/**
* Set the value related to the column: BEN_LIMIT_UR
* @param _benLimitUr the BEN_LIMIT_UR value
*/
public void setBenLimitUr (java.lang.String _benLimitUr) {
this._benLimitUr = _benLimitUr;
}
/**
* Return the value associated with the column: CONTAINED_IN_OLB
*/
public java.lang.String getContainedInOlb () {
return _containedInOlb;
}
/**
* Set the value related to the column: CONTAINED_IN_OLB
* @param _containedInOlb the CONTAINED_IN_OLB value
*/
public void setContainedInOlb (java.lang.String _containedInOlb) {
this._containedInOlb = _containedInOlb;
}
/**
* Return the value associated with the column: END_DATE
*/
public java.util.Date getEndDate () {
return _endDate;
}
/**
* Set the value related to the column: END_DATE
* @param _endDate the END_DATE value
*/
public void setEndDate (java.util.Date _endDate) {
this._endDate = _endDate;
}
/**
* Return the value associated with the column: planPackageOdometers
*/
public java.util.Set getPlanPackageOdometers () {
return this._planPackageOdometers;
}
/**
* Set the value related to the column: planPackageOdometers
* @param _planPackageOdometers the planPackageOdometers value
*/
public void setPlanPackageOdometers (java.util.Set _planPackageOdometers) {
this._planPackageOdometers = _planPackageOdometers;
}
public void addToPlanPackageOdometers (Object obj) {
if (null == this._planPackageOdometers) this._planPackageOdometers = new java.util.HashSet();
this._planPackageOdometers.add(obj);
}
public boolean equals (Object obj) {
if (null == obj) return false;
if (!(obj instanceof com.bcbsma.olbmaint.business.domain.base.BaseCoveragePackageCode)) return false;
else {
com.bcbsma.olbmaint.business.domain.base.BaseCoveragePackageCode mObj = (com.bcbsma.olbmaint.business.domain.base.BaseCoveragePackageCode) obj;
if (null == this.getCoveragePackageCode() || null == mObj.getCoveragePackageCode()) return false;
else return (this.getCoveragePackageCode().equals(mObj.getCoveragePackageCode()));
}
}
public int hashCode () {
if (Integer.MIN_VALUE == this.hashCode) {
if (null == this.getCoveragePackageCode()) return super.hashCode();
else {
String hashStr = this.getClass().getName() + ":" + this.getCoveragePackageCode().hashCode();
this.hashCode = hashStr.hashCode();
}
}
return this.hashCode;
}
public String toString () {
return super.toString();
}
}
2) I would like to generate a spring/hibernate/dao structure. This was accomplishable using templates in synchronizer.
i.e:
Code:
:Modified=true
:ResourceType=C
:Description=Dao Impl
-
#set ($package = $class.ValueObjectPackage.replaceAll(".domain",".service.dao"))
package ${package}.hibernate;
import ${package}.${class.DAOClassName};
import ${package}.hibernate.base.Base${class.DAOClassName}Impl;
/*
* ${class.DAOClassName}Impl.java
*
* Copyright 2004 by Electronic Data Systems
* Corporation. All rights reserved.
*
* An unpublished work created Aug 23, 2004, 2004. This work is a
* trade secret of EDS and unauthorized use or copying
* is prohibited.
*
*/
public class ${class.DAOClassName}Impl extends Base${class.DAOClassName}Impl implements ${class.DAOClassName} {
// Add methods overriding base class here
}
:Modified=true
:ResourceType=C
:Description=Dao Impl Base
-
#set ($package = $class.ValueObjectPackage.replaceAll(".domain",".service.dao"))
package ${package}.hibernate.base;
import ${class.AbsoluteValueObjectClassName};
import ${package}.base.Base${class.DAOClassName};
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import java.util.List;
/*
* ${class.DAOClassName}Impl.java
*
* Copyright 2004 by Electronic Data Systems
* Corporation. All rights reserved.
*
* An unpublished work created Aug 23, 2004, 2004. This work is a
* trade secret of EDS and unauthorized use or copying
* is prohibited.
*
*/
public class Base${class.DAOClassName}Impl extends HibernateDaoSupport implements Base${class.DAOClassName} {
#if ($class.ParentRoot.Id)
public final ${class.ValueObjectClassName} load(${class.ParentRoot.Id.Property.AbsoluteSignatureClassName} key)
{
${class.ValueObjectClassName} obj = (${class.ValueObjectClassName}) getHibernateTemplate().load(${class.ValueObjectClassName}.class, key);
getHibernateTemplate().initialize(obj);
return obj;
}
/**
* Persist the given transient instance, first assigning a generated identifier. (Or using the current value
* of the identifier property if the assigned generator is used.)
* @param ${class.VarName} a transient instance of a persistent class
* @return the class identifier
*/
public final ${class.ParentRoot.Id.Property.ObjectClass} save(${class.ValueObjectClassName} ${class.VarName})
{
return (${class.ParentRoot.Id.Property.ObjectClass}) getHibernateTemplate().save(${class.VarName});
}
#end
public final void refresh(${class.ValueObjectClassName} ${class.VarName})
{
getHibernateTemplate().refresh(${class.VarName});
}
public final ${class.ValueObjectClassName} saveOrUpdateCopy(${class.ValueObjectClassName} ${class.VarName})
{
return (${class.ValueObjectClassName}) getHibernateTemplate().merge(${class.VarName});
}
/**
* Either save() or update() the given instance, depending upon the value of its identifier property. By default
* the instance is always saved. This behaviour may be adjusted by specifying an unsaved-value attribute of the
* identifier property mapping.
* @param ${class.VarName} a transient instance containing new or updated state
*/
public final void saveOrUpdate(${class.ValueObjectClassName} ${class.VarName})
{
getHibernateTemplate().saveOrUpdate(${class.VarName});
}
/**
* Update the persistent state associated with the given identifier. An exception is thrown if there is a persistent
* instance with the same identifier in the current session.
* @param ${class.VarName} a transient instance containing updated state
*/
public final void update(${class.ValueObjectClassName} ${class.VarName})
{
getHibernateTemplate().update(${class.VarName});
}
/**
* Remove a persistent instance from the datastore. The argument may be an instance associated with the receiving
* Session or a transient instance with an identifier associated with existing persistent state.
* @param ${class.VarName} the instance to be removed
*/
public final void delete(${class.ValueObjectClassName} ${class.VarName})
{
getHibernateTemplate().delete(${class.VarName});
}
/**
* Remove a persistent instance from the datastore. The argument may be an instance associated with the receiving
* Session or a transient instance with an identifier associated with existing persistent state.
* @param ${class.VarName} the instance to be removed
*/
public final List loadAll()
{
String orderBy = "";
if (null != getDefaultOrderProperty())
{
orderBy = "order by lower(theRow." + getDefaultOrderProperty() + ") asc";
}
return (List) getHibernateTemplate().find(
" select theRow from ${class.ValueObjectClassName} as theRow " +
orderBy);
}
/**
* Return the property of the class you would like to use for default ordering
* @return the property name
*/
public String getDefaultOrderProperty () {
return null;
}
}
:Modified=true
:ResourceType=C
:Description=Dao Interface
-
#set ($package = $class.ValueObjectPackage.replaceAll(".domain",".service.dao"))
package $package;
import ${package}.base.Base${class.DAOClassName};
/*
* ${class.DAOClassName}.java
*
* Copyright 2004 by Electronic Data Systems
* Corporation. All rights reserved.
*
* An unpublished work created Aug 23, 2004, 2004. This work is a
* trade secret of EDS and unauthorized use or copying
* is prohibited.
*
*/
public interface ${class.DAOClassName} extends Base${class.DAOClassName}{
// Add new methods here
}
:Modified=true
:ResourceType=C
:Description=Dao Interface Base
-
#set ($package = $class.ValueObjectPackage.replaceAll(".domain",".service.dao"))
package ${package}.base;
import ${class.AbsoluteValueObjectClassName};
import java.util.List;
/*
* ${class.DAOClassName}.java
*
* Copyright 2004 by Electronic Data Systems
* Corporation. All rights reserved.
*
* An unpublished work created Aug 23, 2004, 2004. This work is a
* trade secret of EDS and unauthorized use or copying
* is prohibited.
*
*/
public interface Base${class.DAOClassName} {
#if ($class.ParentRoot.Id)
${class.ValueObjectClassName} load(${class.ParentRoot.Id.Property.AbsoluteSignatureClassName} key);
/**
* Persist the given transient instance, first assigning a generated identifier. (Or using the current value
* of the identifier property if the assigned generator is used.)
* @param ${class.VarName} a transient instance of a persistent class
* @return the class identifier
*/
${class.ParentRoot.Id.Property.ObjectClass} save(${class.ValueObjectClassName} ${class.VarName});
#end
void refresh(${class.ValueObjectClassName} ${class.VarName});
${class.ValueObjectClassName} saveOrUpdateCopy(${class.ValueObjectClassName} ${class.VarName});
/**
* Either save() or update() the given instance, depending upon the value of its identifier property. By default
* the instance is always saved. This behaviour may be adjusted by specifying an unsaved-value attribute of the
* identifier property mapping.
* @param ${class.VarName} a transient instance containing new or updated state
*/
void saveOrUpdate(${class.ValueObjectClassName} ${class.VarName});
/**
* Update the persistent state associated with the given identifier. An exception is thrown if there is a persistent
* instance with the same identifier in the current session.
* @param ${class.VarName} a transient instance containing updated state
*/
void update(${class.ValueObjectClassName} ${class.VarName}) ;
/**
* Remove a persistent instance from the datastore. The argument may be an instance associated with the receiving
* Session or a transient instance with an identifier associated with existing persistent state.
* @param ${class.VarName} the instance to be removed
*/
void delete(${class.ValueObjectClassName} ${class.VarName});
/**
* Remove a persistent instance from the datastore. The argument may be an instance associated with the receiving
* Session or a transient instance with an identifier associated with existing persistent state.
* @param ${class.VarName} the instance to be removed
*/
List loadAll();
}
How would I go about accomplishing things like this with hibernate tools?