-->
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.  [ 9 posts ] 
Author Message
 Post subject: Foreign key name (0) mapped to different tables problem
PostPosted: Sun Mar 29, 2009 12:08 pm 
Newbie

Joined: Sun Mar 29, 2009 11:28 am
Posts: 1
Hello,
I use Hibernate v3.2 Tools Reverse engineering to generate Java Code from Access database (MDB).
The test database has 3 tables (don't care, if it doesn't make any sense):

Person
ID primary key
firstName
lastName

Address
ID primary key
street
pID foreign key Person.ID

Job
ID primary key
title
pID pID foreign key Person.ID

If I run th hbm2hbmxml tool, I get the following exception. If I have only in one table reference to the Person ID, then it works.
What should I defined in reveng.xml?
Please, help me.
Thanks in advance!

Full stack trace of any exception that occurs:
Executing Hibernate Tool with a JDBC Configuration (for reverse engineering)
1. task: hbm2hbmxml (Generates a set of hbm.xml files)
An exception occurred while running exporter #2:hbm2hbmxml (Generates a set of hbm.xml files)
To get the full stack trace run ant with -verbose
org.hibernate.cfg.JDBCBinderException: Foreign key name (0) mapped to different tables! previous: org.hibernate.mapping.Table(Address) current:org.hibernate.mapping.Table(Job)
org.hibernate.cfg.JDBCBinderException: Foreign key name (0) mapped to different tables! previous: org.hibernate.mapping.Table(Address) current:org.hibernate.mapping.Table(Job)
at org.hibernate.cfg.reveng.JDBCReader.processForeignKeys(JDBCReader.java:229)
at org.hibernate.cfg.reveng.JDBCReader.resolveForeignKeys(JDBCReader.java:119)
at org.hibernate.cfg.reveng.JDBCReader.readDatabaseSchema(JDBCReader.java:93)
at org.hibernate.cfg.reveng.JDBCReader.readDatabaseSchema(JDBCReader.java:860)
at org.hibernate.cfg.JDBCBinder.readDatabaseSchema(JDBCBinder.java:115)
at org.hibernate.cfg.JDBCBinder.readFromDatabase(JDBCBinder.java:88)
at org.hibernate.cfg.JDBCMetaDataConfiguration.readFromJDBC(JDBCMetaDataConfiguration.java:42)
at org.hibernate.tool.ant.JDBCConfigurationTask.doConfiguration(JDBCConfigurationTask.java:81)
at org.hibernate.tool.ant.ConfigurationTask.getConfiguration(ConfigurationTask.java:55)
at org.hibernate.tool.ant.HibernateToolTask.getConfiguration(HibernateToolTask.java:302)
at org.hibernate.tool.ant.HibernateToolTask.getProperties(HibernateToolTask.java:318)
at org.hibernate.tool.ant.ExporterTask.configureExporter(ExporterTask.java:94)
at org.hibernate.tool.ant.ExporterTask.execute(ExporterTask.java:39)
at org.hibernate.tool.ant.HibernateToolTask.execute(HibernateToolTask.java:186)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:357)
at org.apache.tools.ant.Target.performTasks(Target.java:385)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337)
at org.apache.tools.ant.Project.executeTarget(Project.java:1306)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1189)
at org.apache.tools.ant.module.bridge.impl.BridgeImpl.run(BridgeImpl.java:273)
at org.apache.tools.ant.module.run.TargetExecutor.run(TargetExecutor.java:499)
at org.netbeans.core.execution.RunClassThread.run(RunClassThread.java:151)
BUILD FAILED (total time: 1 second)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 02, 2009 1:25 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
seems like Access is not obeying the JDBC contract?

any chance you can open a jira with a sample database that can be used to reproduce the issue?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Re: Foreign key name (0) mapped to different tables problem
PostPosted: Thu Aug 13, 2009 12:11 am 
Newbie

Joined: Thu Aug 13, 2009 12:09 am
Posts: 5
I have the same issue, has there been any resolution?


Top
 Profile  
 
 Post subject: Re: Foreign key name (0) mapped to different tables problem
PostPosted: Thu Aug 13, 2009 3:29 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
dhoffer wrote:
I have the same issue, has there been any resolution?


see my previous reply ;) Can't help with a DB specific bug if noone gives enough info to reproduce it.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Re: Foreign key name (0) mapped to different tables problem
PostPosted: Thu Aug 13, 2009 5:58 pm 
Newbie

Joined: Thu Aug 13, 2009 12:09 am
Posts: 5
Hum, I can't send my DB its large and not public, and I don't know what's causing this bug so I can't create one with it.


Top
 Profile  
 
 Post subject: Re: Foreign key name (0) mapped to different tables problem
PostPosted: Fri Aug 14, 2009 8:25 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
look at the exception - it refers to Job and Address, start by looking at those tables and associations they are part of. Should reduce it a lot ;)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Re: Foreign key name (0) mapped to different tables problem
PostPosted: Sat Aug 15, 2009 2:25 pm 
Newbie

Joined: Wed Oct 19, 2005 10:06 am
Posts: 3
I think I see the issue. When a JDBC implementation returns NULL for FK_NAME (as allowable by the getExportedKeys() JDBC spec - http://java.sun.com/javase/6/docs/api/j ... ang.String) ), the hibernate code to generate a bogusFkName has a bug.

Code:
package org.hibernate.cfg.reveng;

public class JDBCReader {

   protected ForeignKeysInfo processForeignKeys(DatabaseCollector dbs, Table referencedTable, ProgressListener progress) throws JDBCBinderException {

      short bogusFkName = 0;
      
      // first get all the relationships dictated by the database schema
      
      Iterator exportedKeyIterator = null;
      
        log.debug("Calling getExportedKeys on " + referencedTable);
        progress.startSubTask("Finding exported foreignkeys on " + referencedTable.getName());
        try {
           Map exportedKeyRs = null;
           exportedKeyIterator = getMetaDataDialect().getExportedKeys(getCatalogForDBLookup(referencedTable.getCatalog()), getSchemaForDBLookup(referencedTable.getSchema()), referencedTable.getName() );
        try {
         while (exportedKeyIterator.hasNext() ) {
...
                                short keySeq = ((Short)exportedKeyRs.get("KEY_SEQ")).shortValue();
...
            if (keySeq == 0) {
               bogusFkName++;
            }
            
            if (fkName == null) {
               // somehow reuse hibernates name generator ?
               fkName = Short.toString(bogusFkName);
            }
...



By my reading of http://java.sun.com/javase/6/docs/api/j ... ang.String) the keySeq really shouldn't have anything to do with generating a unique bogusFkName.

Therefore, I think the guard if (keySeq == 0) should be removed and bogusFkName should be incremented every time.


Top
 Profile  
 
 Post subject: Re: Foreign key name (0) mapped to different tables problem
PostPosted: Tue Oct 20, 2009 6:39 am 
Beginner
Beginner

Joined: Tue Oct 20, 2009 6:28 am
Posts: 20
I had this problem also.

It seems it happens when a constraint called the same in two different tables.

The way to solve it is to name it different. I normally use the following format:


<srctbl_desttable>
Ex:

user_userInfo
userInfo_contactInformation

This way I obtain unique names for each constraint and can work around the bug.


Top
 Profile  
 
 Post subject: Re: Foreign key name (0) mapped to different tables problem
PostPosted: Tue Nov 17, 2009 9:43 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
have you tried removing the line and run the junit tests ?

_________________
Max
Don't forget to rate


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