-->
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.  [ 5 posts ] 
Author Message
 Post subject: issue with DB2400 dialect?
PostPosted: Tue Jun 24, 2008 5:47 pm 
Beginner
Beginner

Joined: Wed Jun 15, 2005 1:28 pm
Posts: 39
Location: United States
Hibernate version: 3.2.4.sp1

Name and version of the database you are using: DB2 UDB for AS/400 iSeries V5R4m0

The generated SQL: alter table DB.Customer add constraint FK26568AABFFF088A foreign key (division_id) references DB1.Division

Error: [SQL5051] Qualifier DB1 not the same as name DB.

These two tables are created successfully by the automatic SQL, however the commands to create the constraints error out. Both tables have annotations to override the default library:

Code:
@Table(schema="DB")


To successfully create this constraint, the name needs to be preceeded by the database library name, ie DB.FK26568AABFFF088A.

The database connection string provides a default, which is set to DB1. The constraint name, without the preceeding library name, is defaulting back to DB1, causing the error. The table and the constraint must exist in the same library, or SQL5051 is thrown.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 15, 2008 11:34 am 
Newbie

Joined: Tue Jul 15, 2008 10:01 am
Posts: 2
I've run into the same issue even with 3.2.6.GA so I created a custom dialect that just minimally extends the existing one. I couldn't figure out how to get the schema for the current table other than pulling it out of the table's name, so that's what I've done. Hope this helps.

Code:
public class CustomDB2400Dialect extends DB2400Dialect {

   public String getAddForeignKeyConstraintString(
         String constraintName,
         String[] foreignKey,
         String referencedTable,
         String[] primaryKey,
         boolean referencesPrimaryKey) {
      int end = referencedTable.lastIndexOf(".");
      constraintName = referencedTable.substring(0, end) + "." + constraintName;
      return super.getAddForeignKeyConstraintString(
            constraintName,
            foreignKey,
            referencedTable,
            primaryKey,
            referencesPrimaryKey);
   }
}


Top
 Profile  
 
 Post subject: thank you
PostPosted: Tue Jul 15, 2008 12:04 pm 
Beginner
Beginner

Joined: Wed Jun 15, 2005 1:28 pm
Posts: 39
Location: United States
Thank you, much appreciated.


Top
 Profile  
 
 Post subject: table library
PostPosted: Tue Jul 15, 2008 12:50 pm 
Beginner
Beginner

Joined: Wed Jun 15, 2005 1:28 pm
Posts: 39
Location: United States
This approach only works for tables which reference another table in the same library, because the constraint belongs in the referencing table's library, not the library of the referenced table...

I haven't yet looked into how to access the information about the table doing the referencing within the dialect object.


Top
 Profile  
 
 Post subject: Re: table library
PostPosted: Tue Jul 15, 2008 1:49 pm 
Newbie

Joined: Tue Jul 15, 2008 10:01 am
Posts: 2
You're right, but I don't see a way, from a Dialect, to get more information about the table we're working with. Rather than passing specific strings to these dialect functions it would be much more useful if a more complete reference was available (like the referenced and referencing Table objects in this case).

I've followed the calling chain in a number of directions and don't see anything obvious for getting to them. It would be nice if any Dialect experts chimed in here.


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