-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Yet another reverse engineering thread
PostPosted: Fri Feb 21, 2014 9:19 am 
Newbie

Joined: Fri Feb 21, 2014 8:48 am
Posts: 4
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.


Top
 Profile  
 
 Post subject: Re: Yet another reverse engineering thread
PostPosted: Fri Feb 21, 2014 9:58 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
Using Hibernate naming strategy does not really help here.

The right solution is to use the ReverseEngineeringStrategy since that is the only method that gives you TableIdentifier which have all the info AND it is the right place since hibernate naming strategy is called "too late" for this usecase.

What error are you getting when using it ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Re: Yet another reverse engineering thread
PostPosted: Fri Feb 21, 2014 10:07 am 
Newbie

Joined: Fri Feb 21, 2014 8:48 am
Posts: 4
max wrote:
Using Hibernate naming strategy does not really help here.

The right solution is to use the ReverseEngineeringStrategy since that is the only method that gives you TableIdentifier which have all the info AND it is the right place since hibernate naming strategy is called "too late" for this usecase.

What error are you getting when using it ?


the "too late" part fixed it... i realized i was setting the ReverseEngineeringStrategy in the naming strategy... not in the reveng.strategy... doh!

Thanks man (=


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.