I'm trying to generate pojo's from existing tables in a DB.
(all of this is in the context that I am trying to upgrade from Hibernate 2 and middlegen)
Some of the tables are truncated and end in '$' when I run hbbm2Java i end up with class names that have a '.' in place of the '$'
so what I mean is
table name="criminal_defendant_to_sentenc$"
will become
"criminalDefendantToSentence..java"
I've tried explicitly naming the class name in reveng.xml
...
Code:
<table name="criminal_defendant_to_sentenc$" schema="import"
class="com.legaledge.importdb.CriminalDefendantToSentenc$" >
</table>
<table schema="import" name="criminal_defendant_to_interim$"
class="com.legaledge.importdb.CriminalDefendantToInterim$">
</table>
<table schema="import" name="organization_to_organization_$"
class="com.legaledge.importdb.OrganizationToOrganization$">
</table>
<table schema="import" name="probation_identifier_to_perso$"
class="com.legaledge.importdb.ProbationIdentifierToPerso$">
</table>
<table schema="import" name="case_participant_to_clinical_$"
class="com.legaledge.importdb.CaseParticipantToClinical$">
</table>
<table schema="import" name="case_defendant_to_investigati$"
class="com.legaledge.importdb.CaseDefendantToInvestigati$">
</table>
<table schema="import" name="organization_to_contact_infor$"
class="com.legaledge.importdb.OrganizationToContactInfor$">
</table>
<table schema="import" name="sentence_to_sentence_conditio$"
class="com.legaledge.importdb.SentenceToSentenceConditio$">
</table>
<table schema="import" name="investigation_task_to_chronol$"
class="com.legaledge.importdb.InvestigationTaskToChronol$">
</table>
<table schema="import" name="criminal_appearance_to_crimin$"
class="com.legaledge.importdb.CriminalAppearanceToCrimin$">
</table>
<table schema="import" name="juvenile_appearance_to_juveni$"
class="com.legaledge.importdb.JuvenileAppearanceToJuveni$">
</table>
<table schema="import" name="juvenile_case_to_juvenile_iss$"
class="com.legaledge.importdb.JuvenileCaseToJuvenileIss$">
</table>
<table schema="import" name="juvenile_appearance_to_appear$"
class="com.legaledge.importdb.JuvenileAppearanceToAppear$">
</table>
and I've tried using tableToClassName
/
Code:
**
*
*/
package main.java.com.hib;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.Collections;
import java.util.Enumeration;
import java.util.List;
import java.util.Properties;
import org.hibernate.cfg.reveng.DelegatingReverseEngineeringStrategy;
import org.hibernate.cfg.reveng.ReverseEngineeringStrategy;
import org.hibernate.cfg.reveng.TableIdentifier;
public class CustomReverseEngineeringStrategy extends
DelegatingReverseEngineeringStrategy {
/**
* @param delegate
*/
public CustomReverseEngineeringStrategy(ReverseEngineeringStrategy delegate) {
super(delegate);
}
public String tableToClassName(TableIdentifier tableIdentifier) {
String className = super.tableToClassName(tableIdentifier);
String className2 = className;
if (className.endsWith("$")) {
String tableName = tableIdentifier.getName();
String packageName = "com.legaledge.importdb";
System.out.println("The tableName is : " + tableName);
System.out.println("The ClassName is : " + className);
className2 = className.substring(0,className.length()-1);
className2 = className2 + "$";
if (className.equalsIgnoreCase(className2)){
System.out.println("The Classnames are the SAME!!!!!!!! is : " + className2);
}
}
return className2;
}
public Properties getTableIdentifierProperties(TableIdentifier identifier)
{
Properties properties = super.getTableIdentifierProperties(identifier);
java.io.OutputStream os;
if (properties != null){
System.out.println("props are NOT null ");
}
String className = super.tableToClassName(identifier);
if (className.endsWith("$") && (properties != null)) {
System.out.println("Processing properties for " + className);
Enumeration enumeration = properties.keys();
System.out.println("keys found ");
while (enumeration.hasMoreElements()) {
String key = (String) enumeration.nextElement();
System.out.println("key " + key);
System.out.println(key + " -- " + properties.getProperty(key));
}
if (properties.isEmpty()){
System.out.println(" properties is empty " + className);
} else {
try {
os = new java.io.FileOutputStream(className + ".xml");
properties.storeToXML(os,"comment");
os.close();
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
return properties;
}
}
nothing seems to work. Does anyone know how to solve this?