-->
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.  [ 4 posts ] 
Author Message
 Post subject: Hibernate Tools - reveng and foreign key
PostPosted: Tue Jan 11, 2011 6:37 am 
Newbie

Joined: Mon Jul 31, 2006 8:36 am
Posts: 4
Dear all,
I am facing a difficulty.
I would like to reverse engineer a postgresql database (8.2.1).
The database author use multiple foreign keys to the same primary table that use the same role name.

And so I have the following error :
[ERROR] : : Foreign key name (A_fk) mapped to different tables! previous: org.hibernate.mapping.Table(B) current:org.hibernate.mapping.Table(C) [0]

I would like to know if there is a way to configure hibernate.reveng.xml to solve this problem.
I do not have the rights to modify the database schema that is why i want to use hibernate.reveng.xml


Thank a lot for your help.

Francois


Top
 Profile  
 
 Post subject: Re: Hibernate Tools - reveng and foreign key
PostPosted: Tue Jan 11, 2011 8:08 am 
Newbie

Joined: Mon Jul 31, 2006 8:36 am
Posts: 4
Here the 2 tables description
with the 2 foreignkeys

> table1: chebi.compound_is_a
"chebi_id_fk" FOREIGN KEY (chebi_id) REFERENCES chebi.compound(chebi_id) ON UPDATE CASCADE ON DELETE CASCADE
> table 2:chebi.path_is_a_molecular_structure
"chebi_id_fk" FOREIGN KEY (chebi_id) REFERENCES chebi.compound(chebi_id) ON UPDATE CASCADE ON DELETE CASCADE

And the error message
Quote:
[ERROR] : : Foreign key name (chebi_id_fk) mapped to different tables! previous: org.hibernate.mapping.Table(chebi.compound_is_a) current:org.hibernate.mapping.Table(chebi.path_is_a_molecular_structure) [0]


TABLE 1
Code:
# \d [b][u]chebi.compound_is_a[/u][/b]
                     Table "chebi.compound_is_a"
   Column   |              Type              |       Modifiers       
------------+--------------------------------+------------------------
chebi_id   | text                           | not null
related_id | text                           | not null
relation   | text                           |
created    | timestamp(0) without time zone | not null default now()
Indexes:
    "compound_ancestor_pkey" primary key, btree (chebi_id, related_id)
    "compound_is_a_chebi_id__idx" btree (chebi_id)
    "compound_is_a_related_id__idx" btree (related_id)
    "compound_is_a_relation__idx" btree (relation)
Foreign-key constraints:
    "relation_fk" FOREIGN KEY (relation) REFERENCES chebi.relation(id) ON UPDATE CASCADE ON DELETE CASCADE
    "related_id_fk" FOREIGN KEY (related_id) REFERENCES chebi.compound(chebi_id) ON UPDATE CASCADE ON DELETE CASCADE
    "chebi_id_fk" FOREIGN KEY (chebi_id) REFERENCES chebi.compound(chebi_id) ON UPDATE CASCADE ON DELETE CASCADE


TABLE 2
Code:
# \d [b][u]chebi.path_is_a_molecular_structure[/u][/b]
                   Table "chebi.path_is_a_molecular_structure"
  Column   |              Type              |              Modifiers             
-----------+--------------------------------+-------------------------------------
chebi_id  | text                           | not null
path      | ltree                          | not null
root_name | text                           | default 'molecular structure'::text
root_id   | text                           | default '24431'::text
created   | timestamp(0) without time zone | not null default now()
Indexes:
    "path_is_a_molecular_structure_pkey" primary key, btree (chebi_id, path)
    "chebi_path_is_a_path_molecular_structure__idx" gist (path)
    "path_is_a_molecular_structure__chebi_id__idx" btree (chebi_id)
Check constraints:
    "path_is_a_molecular_structure_root_id_check" CHECK (root_id = '24431'::text)
    "path_is_a_molecular_structure_root_name_check" CHECK (root_name = 'molecular structure'::text)
Foreign-key constraints:
    "root_id_fk" FOREIGN KEY (root_id) REFERENCES chebi.compound(chebi_id) ON UPDATE CASCADE ON DELETE CASCADE
    "chebi_id_fk" FOREIGN KEY (chebi_id) REFERENCES chebi.compound(chebi_id) ON UPDATE CASCADE ON DELETE CASCADE


Top
 Profile  
 
 Post subject: Re: Hibernate Tools - reveng and foreign key
PostPosted: Tue Jan 11, 2011 1:24 pm 
Senior
Senior

Joined: Fri May 08, 2009 12:27 pm
Posts: 168
Try this:

1) Disable the database-defined FKs for the table in reveng. (Via <set exclude="true"/> on the master table I think.)
2) Add the constraints to hibernate.reveng.xml via <foreign-key>. Use a handmade constraint-name that doesn't exist elsewhere. Specifically, you'll have to manually specify foreign-table=, constraint-name=, <column-ref> (possibly multiple times), <many-to-one> and <set>.

The downside is that the foreign keys won't be reverse engineered from the database.
The plus is that it could work.

Note that the Java side does not have foreign keys, it has pointers. A single pointer from a detail to the master, and a Set of all detail records on the master. They just happen to be inferred from the database's foreign keys, but you're free to ignore what the database provides, and you're free to set up additional relationships.


Top
 Profile  
 
 Post subject: Re: Hibernate Tools - reveng and foreign key
PostPosted: Wed Jan 12, 2011 7:07 am 
Senior
Senior

Joined: Fri May 08, 2009 12:27 pm
Posts: 168
vyemialyanchyk, please use a snippet service that doesn't require Javascript.

Using Javascript means that I'm opening my browser to drive-by downloads.
It can be argued that it is reasonable to expect web site owner not to install drive-by malware, it is not reasonable to expect that they will withstand hacks from malicious third parties.
(Personally, I wouldn't trust a snippet service that does require Javascript. In the age of widely-supported CSS, there are many more illegitimate reasons to require JS than legitimate ones.)


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