Ok, sorry if its a noob question, but i couldnt find the answer yet, and sorry for my bad english too.
I have the same
table name in two or more
different schemas. When trying to reverse eng. stuff I obviously get this:
Code:
org.hibernate.cfg.JDBCBinderException: Duplicate class name 'Table' generated for 'org.hibernate.mapping.Table(schema.table)'. Same name where generated for 'org.hibernate.mapping.Table(schema.table)'
Thats because I have a "table" named table in the "schema" named schema, and the same "table" named table in another schema.
Im trying to implement a custom naming strategy thing to fix that by concatenating the schema name before the table name, so, if the table is "schema.table" the class will become "SchemaTable" instead of just "Table", and then i can have a "anotherschema.table" cuz it will become the "AnotherschemaTable" class.
I have tried this as my CustomNamingStrategy class:
Code:
import org.hibernate.cfg.reveng.DelegatingReverseEngineeringStrategy;
import org.hibernate.cfg.reveng.ReverseEngineeringStrategy;
import org.hibernate.cfg.reveng.TableIdentifier;
public class CustomNamingStrategy extends DelegatingReverseEngineeringStrategy {
public CustomNamingStrategy(ReverseEngineeringStrategy delegate)
{
super(delegate);
}
@Override
public String tableToClassName(TableIdentifier tableIdentifier)
{
return tableIdentifier.getSchema() + super.tableToClassName(tableIdentifier);
}
}
It seems to work, but since I cant use DelegatingReverseEngineeringStrategy with the hibernate tools (i get a "could not configure naming strategy" error), im looking for a way to do the same using the supported extends, which are:
Code:
org.hibernate.cfg.DefaultComponentSafeNamingStrategy
org.hibernate.cfg.DefaultNamingStrategy
org.hibernate.cfg.EJB3NamingStrategy
org.hibernate.cfg.ImprovedNamingStrategy
The problem is: the "tableToClassName" for those guys look like this "classToTableName(String className)", in other words it receives only a string containing the className (well, i think those 2 methods would do the same thing... but i may be mistaken).
Question 1) How can i get the schema to concatenate it with this className variable? Is it even possible?Question 2) If its not possible, how you guys deal with this "same name tables in different schemas" thing? Its not possible no one ever needed this.OBS: I dont want to hardcode stuff on reveng.xml, cuz i could simply do the mapping telling that if the table X is from schema Y, concatenate stuff and all would be good, but that table name would be different from the other table standards... its name would look different... and im trying to avoid to hard code stuff anyway.