- This topic has 9 replies, 3 voices, and was last updated 19 years, 12 months ago by
support-jeff.
-
AuthorPosts
-
passifMemberHiya all,
Hopefully somebody can shed some light on this. I am sure that there’s something I am not doing, but have no idea where to look. Here’s the scenario:
I have a small database (seven tables) in Firebird v1.5. Each table has a primary key (verified) and some tables have a foreign key defined to other tables. Two of my tables have multiple foreign keys. The tables all verify nicely – well, at least the IBOConsole displays all the appropriate values in the correct places… (yeah. like I implied, I is a n00blet to Firebird).
When I generate the Hibernate mappings and classes, everything generates hunky-dory, except for those two classes that have multiple foreign keys. Only the last entry of a foreign key definition is generated – thus if I have a foreign key called ‘FK100’ (referencing CLASSA) and then a second one called ‘FK200’ (referencing CLASSB) defined, only the Hibernate mapping link and source code to interact with ‘FK200’ (CLASSB) is generated.
Now, I can add the source code and mapping file to interact with CLASSA, but I would much rather get this to be generated, as any regeneration will overwrite my code.
Any ideas on why this behaviour is happening? Phases of the moon? Aliens? Anything?
passifMemberJust a quick addendum – here’s the needed info as per the forum posting guidelines (yes, I should have read it first… sorry)
OS: Windows XP Pro, SP2
Eclipse: v3.0.1, fresh install with MyEclipse, running on Java v1.4.2_05
Riyad KallaMemberAlso please provide your Firebird DB version info and the JDBC driver you are using.
support-jeffMemberAlso, any errors in the eclipse .log file related to the hibernate or sqlexplorer plugins? Personally, I think its the aliens… 😉
passifMemberOkay, Firebird v1.5.2 (fresh install), using the Jaybird JCA/JDBC Driver v1.5.5. As for the Eclipse error log, nope, doesn’t show any errors to do with Hibernate / SQLExplorer plugins.
Aliens covering their tracks then… 😯
support-jeffMembercuriouser and curiouser. I tried to reproduce something like what you describe in postgresql w/o a problem. Could you post the DDL for your tables (just the table giving you a problem and the tables to which it refers with the FK entries)? I would like to see that before I go and download and install Firebird… 😉
passifMemberOkay, here’s the DDL for one of the offending classes:
ALTER TABLE Device DROP CONSTRAINT FK1500;
ALTER TABLE Device DROP CONSTRAINT FK1501;
ALTER TABLE Device DROP CONSTRAINT FK1700;
ALTER TABLE Device DROP CONSTRAINT FK1800;DROP TABLE Organisation;
DROP TABLE Device;
DROP TABLE Assembly;
DROP TABLE Site;COMMIT;
CREATE TABLE Site (
UID bigint NOT NULL PRIMARY KEY,
STATUS VARCHAR(100),
SITETYPE VARCHAR(100),
HOSTTELNUMBER VARCHAR(50),
);CREATE TABLE Organisation (
UID bigint NOT NULL PRIMARY KEY,
STATUS VARCHAR(100),
NAME VARCHAR(75),
DESCRIPTION VARCHAR(255),
TELEPHONENUMBER VARCHAR(50),
FAXNUMBER VARCHAR(50)
);CREATE TABLE Person (
UID bigint NOT NULL PRIMARY KEY,
TITLE VARCHAR(255),
FIRST_NAME VARCHAR(50),
LAST_NAME VARCHAR(255)
);CREATE TABLE Assembly (
UID bigint NOT NULL PRIMARY KEY,
STATUS VARCHAR(100),
NAME VARCHAR(100)
);CREATE TABLE Device (
UID bigint NOT NULL PRIMARY KEY,
STATUS VARCHAR(100),
MODEL VARCHAR(150),
DESCRIPTION VARCHAR(255),
MANUFACTURER VARCHAR(255)
);COMMIT;
ALTER TABLE Device ADD CONSTRAINT FK1500 FOREIGN KEY (UID) REFERENCES Assembly;
ALTER TABLE Device ADD CONSTRAINT FK1501 FOREIGN KEY (UID) REFERENCES Organisation;
ALTER TABLE Device ADD CONSTRAINT FK1800 FOREIGN KEY (UID) REFERENCES Site;When it comes to generation, the AbstractDevice class that gets generated, only contains a Site attribute, whereas I expected an Assembly and Organisation attribute as well. Also, the Hibernate XML mapping file only contains a mapping entry for site, and not for assembly or organisation. The mapping entry is as follows:
<id name=”site” column=”UID” type=”java.lang.Long”>
<generator class=”native”/>
</id>I also checked the database using a tool called IBOConsole, and the referential constraints (Guess who learnt some new words 😉 ) have been defined for the three keys in question, namely FK1500, FK1501 and FK1800.
I think you guys need a head-scratching smiley as well 🙂
support-jeffMemberAh-ha. Now I am understandink problem. This is a design issue, not the hibernate tool. What you have provided shows four tables, each of which have a PK named UID. However, one of them declares three FK constraints on its single PK to the other three tables. How do I know which of the three tables is supplying a key value to the DEVICE table? In reality, you have three one-to-one relationships here all on the same property. I do not believe that Hibernate can handle this situation. Now if the DEVICE table had a single column for each FK being contributed (say ASSEMBLY_UID, ORGANIZATION_UID, and SITE_UID for example) in the DEVICE table, then Hibernate and the ME tool would understand this. Hibernate can handle one-to-one mappings, but only between two tables AFAIK.
passifMemberAh. 😳
Thanks for the heads-up on this one Jeff, I appreciate it. ‘This is a design issue’ – boy, did I hear that one during my OO training days, and it came and bit me again.
Thanks again – excellent support and service by the way, much better than some of the larger corporates (*cough* large blue shop *cough*) that we have the misfortune of dealing with in our neck of the woods, more than welcome to close this one.
support-jeffMemberIt’s a pleasure to serve! And as far as certain (blue) corporate support groups, I have the distinct (dis)pleasure of dealing with them on a near weekly basis, oh joy! So I am there with you. 😉
-
AuthorPosts