-->
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.  [ 12 posts ] 
Author Message
 Post subject: FKs w/ the same name confuse artifcact generator
PostPosted: Fri Aug 12, 2005 8:17 pm 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
Not sure if anyone cares, but Postgres is perfectly OK w/ me making FKs w/ the same name and the generator is not ...

PostrgreSQL 8.0.3-1 w/ postgresql-8.0-312.jdbc2.jar
version = hibernate-tools-3.0.0.alpha4a

org.hibernate.cfg.JDBCBinderException: Foreign key name (m_c_fk) mapped to different tables! previous: org.hibernate.mapping.Table(public.activity) current:org.hibernate.mapping.Table(public.meeting)
at org.hibernate.cfg.JDBCBinder.processForeignKeys(JDBCBinder.java:1062)
at org.hibernate.cfg.JDBCBinder.readDatabaseSchema(JDBCBinder.java:136)
at org.hibernate.cfg.JDBCBinder.readFromDatabase(JDBCBinder.java:91)
at org.hibernate.cfg.JDBCMetaDataConfiguration.readFromJDBC(JDBCMetaDataConfiguration.java:37)
at org.hibernate.eclipse.console.wizards.ArtifactGeneratorWizard$3.execute(ArtifactGeneratorWizard.java:237)
at org.hibernate.console.ConsoleConfiguration.execute(ConsoleConfiguration.java:77)
at org.hibernate.eclipse.console.wizards.ArtifactGeneratorWizard.buildConfiguration(ArtifactGeneratorWizard.java:234)
at org.hibernate.eclipse.console.wizards.ArtifactGeneratorWizard.doFinish(ArtifactGeneratorWizard.java:164)
at org.hibernate.eclipse.console.wizards.ArtifactGeneratorWizard.access$0(ArtifactGeneratorWizard.java:132)
at org.hibernate.eclipse.console.wizards.ArtifactGeneratorWizard$1.run(ArtifactGeneratorWizard.java:98)
at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:113)


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 13, 2005 5:03 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
hmmm....most db's complain about that AFAIK....

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 28, 2005 6:51 pm 
Regular
Regular

Joined: Wed Sep 28, 2005 6:45 pm
Posts: 56
I had the exact same problem after importing my database into postgres and all the foreign keys were set to "$1", "$2", etc...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 28, 2005 6:53 pm 
Regular
Regular

Joined: Wed Sep 28, 2005 6:45 pm
Posts: 56
Couldn't find any edit button.. so..

org.hibernate.cfg.JDBCBinderException:Foreign key name ($1) mapped to different tables! previous: org.hibernate.mapping.Table(public.tcontactupdater) current:org.hibernate.mapping.Table(public.temroxcontact)

That was the error report I got while using artifact generation plugin for eclipse...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 29, 2005 6:43 am 
Regular
Regular

Joined: Wed Sep 28, 2005 6:45 pm
Posts: 56
Postgres creates foreign keys named "$1", "$2", etc by default if you use this kind of syntax

CREATE TABLE order (
orderid serial PRIMARY KEY NOT NULL,
id_contactid int4 REFERENCES tcontact
)

the "REFERENCES tcontact" part is the same as doing:

ALTER TABLE torder
ADD CONSTRAINT "$1" FOREIGN KEY (id_contactid) REFERENCES tcontact (contactid) ON UPDATE NO ACTION ON DELETE NO ACTION;

if contactid is the primary key of tcontact.

In other words, if you are using Postgres and the REFERENCES syntax you can't use the hibernate tools without dropping all your foreign keys and creating them with names...

So... is there any chance of non-unique keys beeing allowed in the hibernate tools for generating xml/java?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 29, 2005 6:51 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
Add this explanation to JIRA and lets see.

In other db's the foreign key name is unique (and actually also inside hibernate in some aspects); but we could probably handle it with a bit of work....patches welcome....

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 29, 2005 6:58 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
but i would recommend you name those foreign keys since otherwise the names would be pretty bad.

according to postgres docs that is done most compact via:

id_contactid int4 REFERENCES myFkName tcontact

(dont have a postgres install so let me know if that is actually possible)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 29, 2005 8:28 am 
Regular
Regular

Joined: Wed Sep 28, 2005 6:45 pm
Posts: 56
Hi, I had looked for what you just described, but couldn't find it... see documentation below.

I tried it as well, but it didn't work. (This is on postgres 7.4, I can check on postgres 8.0.1 for windows later)

Personally I don't do anything with foreign keys after they have been created and therefore haven't thought about nameing them in any useful fashion... and Postgres really doesn't care...

I haven't looked at the implementation of the tools, but you could generate unique names by using tablename+"_"+columname...

Seems like I am gonna drop "unnamed"/create "named" foreign keys in my database... Thanks for the reply, you probably get better support here than in commercial products :)

Name
CREATE TABLE -- define a new table
Synopsis
CREATE [ [ LOCAL ] { TEMPORARY | TEMP } ] TABLE table_name (
{ column_name data_type [ DEFAULT default_expr ] [ column_constraint [, ... ] ]
| table_constraint } [, ... ]
)
[ INHERITS ( parent_table [, ... ] ) ]
[ WITH OIDS | WITHOUT OIDS ]

where column_constraint is:

[ CONSTRAINT constraint_name ]
{ NOT NULL | NULL | UNIQUE | PRIMARY KEY |
CHECK (expression) |
REFERENCES reftable [ ( refcolumn ) ] [ MATCH FULL | MATCH PARTIAL ]
[ ON DELETE action ] [ ON UPDATE action ] }
[ DEFERRABLE | NOT DEFERRABLE ] [ INITIALLY DEFERRED | INITIALLY IMMEDIATE ]

and table_constraint is:

[ CONSTRAINT constraint_name ]
{ UNIQUE ( column_name [, ... ] ) |
PRIMARY KEY ( column_name [, ... ] ) |
CHECK ( expression ) |
FOREIGN KEY ( column_name [, ... ] ) REFERENCES reftable [ ( refcolumn [, ... ] ) ]
[ MATCH FULL | MATCH PARTIAL ] [ ON DELETE action ] [ ON UPDATE action ] }
[ DEFERRABLE | NOT DEFERRABLE ] [ INITIALLY DEFERRED | INITIALLY IMMEDIATE ]


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 29, 2005 10:16 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
I read it on http://www.postgresql.org/docs/8.0/inte ... TRAINTS-FK

and they are not very clear on how you actually name stuff when using REFERENCES.

Besides:

"So, to specify a named constraint, use the key word CONSTRAINT followed by an identifier followed by the constraint definition. (If you don't specify a constraint name in this way, the system chooses a name for you.)"

and then later on

"You can assign your own name for a foreign key constraint, in the usual way."

so maybe they mean:

product_no integer CONSTRAINT your_name REFERENCES products,

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 29, 2005 12:05 pm 
Regular
Regular

Joined: Wed Sep 28, 2005 6:45 pm
Posts: 56
I did some more research, and postgres 8.0 for windows creates foreign keys like this: torder_id_modelid_fkey if you use REFERENCES. I will just go ahead and rename my stupidly named foreign keys then ;)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 29, 2005 12:12 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
so postgres 8 looks much better ;)

Did you possibly find any docs about why they changed to this better strategy ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 29, 2005 12:30 pm 
Regular
Regular

Joined: Wed Sep 28, 2005 6:45 pm
Posts: 56
No, I just double checked in my 8.0 db, as it sounded idiotic to create names like $1. The postgres developers must have seen it as well, because its fixed ;)

Luckily I haven't been using the "REFERENCES" syntax for too long, so I only have about 100-200 foreign keys to fix.

What fun.


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