Hi!
I am trying to extend the reverse engineering strategy in order to include "
UPDATE_DT" as column name to be used for optimistic locking.
Extending the
DelegatingReverseEngineeringStrategy as described below, I would expect that a "
@Version" annotation for
UPDATE_DT columns would be generated in my entity beans, but this does not seem to work.
My
CustomReverseEngineeringStrategy gets called correctly and the entity beans are generated correctly except for the fact the the "
@Version" annotations are missing for the
UPDATE_DT columns.
Am I correct in assuming that if the method
useColumnForOptimisticLock for a column of a table returns true, then the "
@Version" annotation should be generated?
Hope some guru can help me! ;)
Kind regards,
Xserty
CustomReverseEngineeringStrategy class:
Code:
public class CustomReverseEngineeringStrategy extends DelegatingReverseEngineeringStrategy {
private ReverseEngineeringSettings settings;
private static Set<String> AUTO_OPTIMISTICLOCK_COLUMNS;
static {
AUTO_OPTIMISTICLOCK_COLUMNS = new HashSet<String>();
AUTO_OPTIMISTICLOCK_COLUMNS.add("UPDATE_DT");
}
public CustomReverseEngineeringStrategy(ReverseEngineeringStrategy delegate) {
super(delegate);
}
public void setSettings(ReverseEngineeringSettings settings) {
System.out.println("settings.getDetectOptimsticLock(): " + settings.getDetectOptimsticLock());
System.out.println("settings.getDetectManyToMany(): " + settings.getDetectManyToMany());
System.out.println("settings.getDefaultPackageName(): " + settings.getDefaultPackageName());
this.settings = settings;
}
public boolean useColumnForOptimisticLock(TableIdentifier identifier, String column) {
if (settings.getDetectOptimsticLock()) {
if (AUTO_OPTIMISTICLOCK_COLUMNS.contains(column.toUpperCase())) {
System.out.println("Column '" + column + "' for table '" + identifier.getName() + "' should be used for Optimistic Locking");
return true;
} else {
return false;
}
} else {
return false;
}
}
Ant reverse engineering output excerpt:Code:
[hibernatetool] Executing Hibernate Tool with a JDBC Configuration (for reverse engineering)
[hibernatetool] 1. task: hbm2java (Generates a set of .java files)
[hibernatetool] settings.getDetectOptimsticLock(): true
[hibernatetool] settings.getDetectManyToMany(): true
[hibernatetool] settings.getDefaultPackageName(): example.datalayer.model
[hibernatetool] Column 'UPDATE_DT' for table 'INTERNET_USERS' should be used for Optimistic Locking
[hibernatetool] Column 'UPDATE_DT' for table 'SYSTEM_USERS' should be used for Optimistic Locking
Generated entity bean excerpt:Code related to the UPDATE_DT column:
Code:
@Column(name="UPDATE_DT", length=7)
public Date getUpdateDt() {
return this.updateDt;
}
public void setUpdateDt(Date updateDt) {
this.updateDt = updateDt;
}
Hibernate Tools version: 3.2.0.b9
DB: Oracle 10g
Note: I'm not using/generating mapping files (*.hbm.xml).