-->
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.  [ 2 posts ] 
Author Message
 Post subject: foreign-key ignored in reveng due to mixed case table names
PostPosted: Fri Dec 10, 2010 11:15 am 
Newbie

Joined: Wed Mar 28, 2007 4:00 pm
Posts: 7
My Postgres db has mixed case table names. In my hibernate.properties I've added

hibernatetool.metadatadialect=com.xxx.util.hibernate.PostgreSQLMetaDialect
Code:
public class PostgreSQLMetaDialect extends JDBCMetaDataDialect {

   private static final Log log = LogFactory.getLog(PostgreSQLMetaDialect.class);
   
   public boolean needQuote(String name) {     
      log.debug("needQuote(" + name +")");
      if(null != name && 0 != name.compareTo(name.toUpperCase())) {
         return true;
      } else {
         return super.needQuote(name);
      }
   }
}


I have the following reveng.xml for Hibernate Tools 3.2.3.GA.
Code:
<hibernate-reverse-engineering>
  <schema-selection match-schema="public"/>

  <table-filter match-schema="public" match-name="employee_dept" package="com.xxx.domain.entity" exclude="false"/>
  <table-filter match-schema="public" match-name="xref_employee_number_Contact" package="com.xxx.domain.entity" exclude="false"/>
  <table-filter match-schema="public" match-name="CONT_Contact" package="com.xxx.domain.entity" exclude="false"/>
  <table-filter match-schema="public" match-name="CONT_EmployeeHR" package="com.xxx.domain.entity" exclude="false"/>

  <table schema="public" name="employee_dept">
    <foreign-key constraint-name="employee_number_fk" foreign-table="CONT_EmployeeHR">
        <column-ref local-column="employee_number" foreign-column="employee_number" />
        <many-to-one property="getEmployee" exclude="false"/>
        <set property="getDepartments" exclude="false"/>
    </foreign-key>
  </table>
</hibernate-reverse-engineering>


Any mixed case table that I want I am now able to filter. Classes and hbm.xml are created, but the foreign key definition in reveng.xml is ignored. The log says

DEBUG org.hibernate.cfg.reveng.JDBCReader - Table TableIdentifier(public.employee_dept) excluded by strategy
DEBUG org.hibernate.cfg.reveng.JDBCReader - User defined foreign key `employee_number_fk` references unknown or filtered table TableIdentifier(public.employee_dept)

Is it possible to override JDBCReader like I did for JDBCMetaDataDialect? Then I could bypass the condition. Is there another way around it?

Adding ticks didn't work, i.e "`employee_dept`".


Top
 Profile  
 
 Post subject: Re: foreign-key ignored in reveng due to mixed case table names
PostPosted: Mon Dec 20, 2010 10:46 am 
Senior
Senior

Joined: Fri May 08, 2009 12:27 pm
Posts: 168
It says "excluded by strategy", so I'd look into the strategy class.

The easiest way to hook into this and get logging output is configuring the reveng process to use this for your reverse engineering stratety:

Code:
public class HfReverseEngineeringStrategy
extends DelegatingReverseEngineeringStrategy
{
  public MyReverseEngineeringStrategy (ReverseEngineeringStrategy delegate)
  {
    super (delegate);
  }
}


Override and log as you see fit.
You'll probably want to log the class name of the delegate, and override excludeTable() and log both table names and decisions.
Or maybe you're using a strategy class already and excluding the table there? I can't say I didn't miss anything, but to me, it seems that that "excluded by strategy" message is generated by excludeTable() returning true, but none of the implementations of excludeTable() that I can find in the classes distributed with HibernateTools every return anything but false.

(There are some more oddities in the reveng file, but they might have their reasons in your setup and seem unrelated anyway.)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.