-->
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.  [ 13 posts ] 
Author Message
 Post subject: Code Generation : ManytoOne Relationship
PostPosted: Thu Mar 22, 2007 8:55 am 
Newbie

Joined: Tue Feb 15, 2005 1:19 pm
Posts: 10
I am trying to generate POJO's using hbm2java.
<hbm2java jdk5="true" ejb3="true"/>
I have two tables : Customer and Account, with a one to many relationship.

The database has the constraint defined, and in my jdbcconfiguration I have specified detectmanytomany="true"

But the generated code doesn't produce the correct methods: e.g. I am expecting
private Customer customer; and corrosponding get/set but it generates private String customerid. It is not generating the methods for the relationships.
So do I have specify in the reveng.xml the foreign key relationships?

regards
Rajesh


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 22, 2007 1:15 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
you don't have a db with proper foreign keys in it (or your driver does not support it at least)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 22, 2007 3:34 pm 
Newbie

Joined: Tue Feb 15, 2005 1:19 pm
Posts: 10
I am using Apache Derby and using the JDBC Client Driver.
The hibernate.properties file has the following settings

## Derby
hibernate.dialect org.hibernate.dialect.DerbyDialect
hibernate.connection.driver_class org.apache.derby.jdbc.ClientDriver
hibernate.connection.url jdbc:derby://localhost:1527/sample;create=true

At the Database level, I can see the FK Constraint.
ALTER TABLE Account ADD CONSTRAINT Account_Customer FOREIGN KEY (CustomerId) REFERENCES Customer (id);


Any reasons why I cannot get this in the generated PO's. IS there any way to add DEBUG statments during generation, so I can see how the generator is working?

Thanx!
Rajesh


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 22, 2007 4:15 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
include log4j and enable debug logging and you should see alot ;)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 23, 2007 12:36 pm 
Newbie

Joined: Tue Feb 15, 2005 1:19 pm
Posts: 10
I am not getting much information in the console logs (kind of what should I be looking for, seems there are some zip file error spitted by Ant, otherwise looks good).

I am trying to zero on why I am not getting the Foreign Key Relationships generated.
Has anyone generated for Apache Derby and can they share their reverse engineering file and the build script.


regards
Rajesh


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 23, 2007 1:17 pm 
Newbie

Joined: Tue Feb 15, 2005 1:19 pm
Posts: 10
Is the association generation in Reverse engineering not available?

See this thread
http://forum.hibernate.org/viewtopic.ph ... t=hbm2java

regards
Rajesh


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 23, 2007 4:11 pm 
Newbie

Joined: Tue Feb 15, 2005 1:19 pm
Posts: 10
Ok, I did run hbm2java with HSQL and Associations works. So Derby doesn't work. FYI... I hope it gets picked up as it is getting popular.

regards


Top
 Profile  
 
 Post subject: Reverse Enginneering Oracle DB Schema
PostPosted: Mon Apr 23, 2007 4:40 am 
Newbie

Joined: Mon Apr 23, 2007 4:11 am
Posts: 3
Location: Koblenz, Germany
Hi,

while trying to reverse engineer an Oracle schema to produce jpa compliant annotations I found no relational information being generated into my pojos (using ANT with latest HT plugin jars 3.2.0.9a w/o eclipse).

I assume this is due to "wrong" data modelling.
In my scenario, I basically modelled two tables, MASTER and SLAVE,
of which MASTER carried the columns A (primary-key constraint), B (unique-key constraint) and C (some data)
and SLAVE was defined like X (primary-key constraint), Y (Foreign-key constraint) and Z (some data).

Y was related to B (FK), which does not work, at least with Oracle.
However, associating Y with A (FK) works pretty well.

Would you agree this is a faulty data modelling? Is there a chance this issue will be taken care of as a feature?

Take care
Klaus


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 23, 2007 4:47 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
how about showing the table and foreign key dml - think it would be easier to follow then ;)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 23, 2007 10:40 am 
Newbie

Joined: Mon Apr 23, 2007 4:11 am
Posts: 3
Location: Koblenz, Germany
Hi,

hope the below will help.

This will initially not work as described in my previous post.
Please observe the disparate foreign key constraints tagged with ***.

Code:
CREATE TABLE "KLAUZ"."MASTER" ("A" VARCHAR2(10 byte) NOT NULL,
    "B" VARCHAR2(10 byte) NOT NULL, "C" LONG NOT NULL,
    CONSTRAINT "MASTER_PK11177337506546" PRIMARY KEY("A")
    USING INDEX 
    TABLESPACE "USERS"
    STORAGE ( INITIAL 64K NEXT 0K MINEXTENTS 1 MAXEXTENTS
    2147483645 PCTINCREASE 0) PCTFREE 10 INITRANS 2 MAXTRANS 255,
    CONSTRAINT "MASTER_UK21177337506546" UNIQUE("B")
    USING INDEX 
    TABLESPACE "USERS"
    STORAGE ( INITIAL 64K NEXT 0K MINEXTENTS 1 MAXEXTENTS
    2147483645 PCTINCREASE 0) PCTFREE 10 INITRANS 2 MAXTRANS 255)
     
    TABLESPACE "USERS" PCTFREE 10 PCTUSED 0 INITRANS 1 MAXTRANS
    255
    STORAGE ( INITIAL 64K NEXT 0K MINEXTENTS 1 MAXEXTENTS
    2147483645 PCTINCREASE 0)
    LOGGING

CREATE TABLE "KLAUZ"."SLAVE" ("X" VARCHAR2(10 byte) NOT NULL, "Y"
    VARCHAR2(10 byte) NOT NULL, "Z" LONG NOT NULL,
***
    CONSTRAINT "SLAVE_FK81177337605734" FOREIGN KEY("Y")
    REFERENCES "KLAUZ"."MASTER"("B"),
***
    CONSTRAINT "SLAVE_PK11177337529750" PRIMARY KEY("X")
    USING INDEX 
    TABLESPACE "USERS"
    STORAGE ( INITIAL 64K NEXT 0K MINEXTENTS 1 MAXEXTENTS
    2147483645 PCTINCREASE 0) PCTFREE 10 INITRANS 2 MAXTRANS 255)
     
    TABLESPACE "USERS" PCTFREE 10 PCTUSED 0 INITRANS 1 MAXTRANS
    255
    STORAGE ( INITIAL 64K NEXT 0K MINEXTENTS 1 MAXEXTENTS
    2147483645 PCTINCREASE 0)
    LOGGING



Slightly modifying the dependent table's fk constraints and the generation will operate as expected (master ddl omitted / unchanged).

Code:
CREATE TABLE "KLAUZ"."SLAVE" ("X" VARCHAR2(10 byte) NOT NULL, "Y"
    VARCHAR2(10 byte) NOT NULL, "Z" LONG NOT NULL,
***
    CONSTRAINT "SLAVE_FK31177338173718" FOREIGN KEY("Y")
    REFERENCES "KLAUZ"."MASTER"("A"),
***
    CONSTRAINT "SLAVE_PK11177337529750" PRIMARY KEY("X")
    USING INDEX 
    TABLESPACE "USERS"
    STORAGE ( INITIAL 64K NEXT 0K MINEXTENTS 1 MAXEXTENTS
    2147483645 PCTINCREASE 0) PCTFREE 10 INITRANS 2 MAXTRANS 255)
     
    TABLESPACE "USERS" PCTFREE 10 PCTUSED 0 INITRANS 1 MAXTRANS
    255
    STORAGE ( INITIAL 64K NEXT 0K MINEXTENTS 1 MAXEXTENTS
    2147483645 PCTINCREASE 0)
    LOGGING


Take care,
Klaus


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 16, 2007 10:16 am 
Newbie

Joined: Mon Apr 23, 2007 4:11 am
Posts: 3
Location: Koblenz, Germany
light on this issue, please


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 02, 2007 7:46 pm 
Newbie

Joined: Mon Jul 02, 2007 6:29 pm
Posts: 3
I am a little bit worried of reading all of this replies.........., so it means that hibernate tools does not work with derby to reflect his relations of foreign keys in the java classes and in the *.hbm.xml files?, it does not work at all?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 03, 2007 1:50 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
well looks to me that derby is not obeying the jdbc metadata spec.

oracle, ms sql, postgress, h2, hsqldb and even mysql reports foreign key constraints just fine (if the driver is recent enough).

_________________
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.  [ 13 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.