Hi! I've been able to generate annotated POJOs from the database and now I need some help enhancing them a bit.
Hibernate version: 3.1.2
Tools version: 3.1.0.beta4
Annotations version: 3.1beta8
Here's my ant task:
Code:
<taskdef name="hibernatetool"
classname="org.hibernate.tool.ant.HibernateToolTask"
classpathref="lib.classpath"/>
<target name="hibernategen">
<hibernatetool destdir="${sourcedir}/WEB-INF/classes/">
<jdbcconfiguration
propertyfile="hibernateforant.properties"
packagename="reger.dao.hibernate"
reversestrategy="reger.hibernate.CustomReverseEngineeringStrategy"
revengfile="${sourcedir}/WEB-INF/classes/hibernate.reveng.xml"
/>
<hbm2java jdk5="true" ejb3="true"/>
<hbm2cfgxml ejb3="true"/>
</hibernatetool>
</target>
And here's my custom reverse engineering class:
Code:
import org.hibernate.cfg.reveng.DelegatingReverseEngineeringStrategy;
import org.hibernate.cfg.reveng.ReverseEngineeringStrategy;
public class CustomReverseEngineeringStrategy extends DelegatingReverseEngineeringStrategy {
public CustomReverseEngineeringStrategy(ReverseEngineeringStrategy delegate) {
super(delegate);
}
public String getTableIdentifierStrategyName(org.hibernate.cfg.reveng.TableIdentifier tableIdentifier){
return "GeneratorType.AUTO";
}
}
This outputs a POJO like:
Code:
@Entity
@Table(name="eventtogroup"
,catalog="reger"
, uniqueConstraints = { }
)
public class Eventtogroup implements java.io.Serializable {
// Fields
private int eventtogroupid;
private Integer eventid;
private Integer groupid;
// Constructors
/** default constructor */
public Eventtogroup() {
}
/** full constructor */
public Eventtogroup(Integer eventid, Integer groupid) {
this.eventid = eventid;
this.groupid = groupid;
}
// Property accessors
@GenericGenerator(name="generator", strategy="GeneratorType.AUTO", parameters = { } )
@Id @GeneratedValue(generator="generator")
@Column(name="eventtogroupid", unique=true, nullable=false, insertable=true, updatable=true)
public int getEventtogroupid() {
return this.eventtogroupid;
}
public void setEventtogroupid(int eventtogroupid) {
this.eventtogroupid = eventtogroupid;
}
@Column(name="eventid", unique=false, nullable=true, insertable=true, updatable=true)
public Integer getEventid() {
return this.eventid;
}
public void setEventid(Integer eventid) {
this.eventid = eventid;
}
@Column(name="groupid", unique=false, nullable=true, insertable=true, updatable=true)
public Integer getGroupid() {
return this.groupid;
}
public void setGroupid(Integer groupid) {
this.groupid = groupid;
}
}
I'm having two problems.
First, I can't seem to properly set the GeneratorType annotation on the identity column. This is what I get now:
Code:
@GenericGenerator(name="generator", strategy="GeneratorType.AUTO", parameters = { } )
@Id @GeneratedValue(generator="generator")
@Column(name="eventtogroupid", unique=true, nullable=false, insertable=true, updatable=true)
public int getEventtogroupid() {
return this.eventtogroupid;
}
But I'd like to see (basically, I want to use the AUTO type):
Code:
@Id @GeneratedValue(strategy=GeneratorType.AUTO)
@Column(name="eventtogroupid", unique=true, nullable=false, insertable=true, updatable=true)
public int getEventtogroupid() {
return this.eventtogroupid;
}
How would I go about this? Do I need to be working in my reverse engineering strategy (I'm passing a string with the value "GeneratorType.AUTO" now which isn't working) or is there some sort of mapping file that I need to work with?
Second, I don't like having the catalog name in the POJO:
Code:
@Table(name="eventtogroup"
,catalog="reger"
, uniqueConstraints = { }
)
How would I go about the "catalog="reger"' piece?
My goal on both of these is to have an ant-runnable task that I can use to update the entities periodically without user intervention or tweaking.
Thanks,
Joe