Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
ttrostel
Post subject: Hibernate Table Mapping  PostPosted: Aug 17, 2004 - 02:04 PM
Veteran Member
Veteran Member


Joined: Jun 14, 2004
Posts: 108

Ummm ... Errr ....

It seems the way Hibernate mappings are constructed has changed slightly. Can you give me a back of the napkin style run through of how the new tool should be used? I'll mess around with it for a few and see if I can figure it out in the mean time.

Thanks!

Tom
 
 View user's profile Send private message  
Reply with quote Back to top
ttrostel
Post subject:   PostPosted: Aug 17, 2004 - 03:24 PM
Veteran Member
Veteran Member


Joined: Jun 14, 2004
Posts: 108

The new version is having some trouble creating classes with composite keys also ... do you have to create the objects in an order if there are one to many relationships?
 
 View user's profile Send private message  
Reply with quote Back to top
ttrostel
Post subject:   PostPosted: Aug 17, 2004 - 03:59 PM
Veteran Member
Veteran Member


Joined: Jun 14, 2004
Posts: 108

YuK ... its trying to create this mapping and getting VERY confused

<class name="SumRcv" table="SUM_RCV">
<composite-id name="id" class="SumRcvKey">
<key-many-to-one name="Invoices" column="INVOICE_NO" class="Invoices"/>
<key-property name="lineNo" column="LINE_NO" type="java.lang.Integer"/>
</composite-id>

... then it decides it can't create the key class
 
 View user's profile Send private message  
Reply with quote Back to top
support-rkalla
Post subject:   PostPosted: Aug 17, 2004 - 04:00 PM
Registered Member
Registered Member


Joined: Jan 06, 2004
Posts: 23855

I've asked the Hibernate dev to have a look at this, thank you for your patience.

_________________
Riyad
MyEclipse Support
 
 View user's profile Send private message Visit poster's website  
Reply with quote Back to top
ttrostel
Post subject:   PostPosted: Aug 17, 2004 - 05:03 PM
Veteran Member
Veteran Member


Joined: Jun 14, 2004
Posts: 108

No problem. I got around the issue coding those classes by hand. The issue is when the composite identity for one table is the foreign link to another table.
 
 View user's profile Send private message  
Reply with quote Back to top
support-jeff
Post subject:   PostPosted: Aug 17, 2004 - 06:32 PM
Moderator
Moderator


Joined: Jul 18, 2004
Posts: 357

Regarding the first question, yes, the mechanism for creating the mappings has changed dramatically - instead of using the old ddl2hbm tooling, we are now using Velocity templates to generate the mappings. This include adding support for composite ids and many-to-one relationships - the previous SQLEditor-based plugin did not do these (well).

For your second point regarding composite keys, they are supported - the mapping is correct since I take it that the INVOICE_NO column is a foreign key to the INVOICES table and the the LINE_NO column is just a simple attribute that forms the rest of the pk. Correct? If this is supposed to be mapped another way please provide the details.

Unfortunately, it looks like some fixes committed prior to the GA build did not make it into the build that has been release. damn.

Also, you have found another bug with this particular use case (comp key is also fk to other table). I will make sure this gets into bugzilla for the first maintenance release (I know one is in the works for other reasons).

Sorry for the inconvenience. This is a new feature within ME, and has changed significantly since beta2, but I had hoped I had all the test cases down. Bummer.

_________________
jeff
MyEclipse Support
 
 View user's profile Send private message  
Reply with quote Back to top
ttrostel
Post subject:   PostPosted: Aug 17, 2004 - 08:58 PM
Veteran Member
Veteran Member


Joined: Jun 14, 2004
Posts: 108

No problem Jeff,

I retooled the entire project with the new classes this afternoon to shake out any other issues which might have been missed. It looks very stable. I would definately say you're on the right track here. Do you know when you might have a patch release comming out to us? No rush here since we can code around any problems and the current release features have put us *way* ahead of schedule.

Quote:

For your second point regarding composite keys, they are supported - the mapping is correct since I take it that the INVOICE_NO column is a foreign key to the INVOICES table and the the LINE_NO column is just a simple attribute that forms the rest of the pk. Correct? If this is supposed to be mapped another way please provide the details.


Yes thats entirely correct. Unfortunately the Hibernate mapper can't construct the key class. Everything else gets constructed without a hitch.

I'll see if I can make you a small sample code segment which illustrates the problem as a test case for the developers.
 
 View user's profile Send private message  
Reply with quote Back to top
support-jeff
Post subject:   PostPosted: Aug 18, 2004 - 04:36 AM
Moderator
Moderator


Joined: Jul 18, 2004
Posts: 357

A maintenance release is already in the works, and I am working on the bug you discovered as I write this. First there was a typically NPE code problem (bad developer! bad! bad! ;-) but now it gets trickier - what if the composite key is made up of multiple fk's? It will get resolved. Thanx again for the patience!

_________________
jeff
MyEclipse Support
 
 View user's profile Send private message  
Reply with quote Back to top
dserodio
Post subject: Any news for 3.8.3?  PostPosted: Dec 15, 2004 - 09:14 PM
Registered Member
Registered Member


Joined: Jun 23, 2004
Posts: 51

Any news on this bug? I'm using 3.8.3, generated a Hibernate mapping from a simple schema and it doesn't generate foreign keys references:

Code:
CREATE TABLE group (
       id VARCHAR(32) NOT NULL
     , name VARCHAR(255) NOT NULL
     , PRIMARY KEY (id)
);

CREATE TABLE user (
       id VARCHAR(32) NOT NULL
     , login VARCHAR(32) NOT NULL
     , passwd VARCHAR(32)
     , PRIMARY KEY (id)
);

CREATE TABLE user_group (
       user_id VARCHAR(32) NOT NULL
     , group_id VARCHAR(32) NOT NULL
     , PRIMARY KEY (user_id, group_id)
     , CONSTRAINT FK_user_group_1 FOREIGN KEY (user_id)
                  REFERENCES user (id)
     , CONSTRAINT FK_user_group_2 FOREIGN KEY (group_id)
                  REFERENCES group (id)
);


Generated:

Code:
<hibernate-mapping package="">
    <class name="UserGroup" table="USER_GROUP">
        <composite-id name="id" class="UserGroupKey">
            <key-many-to-one name="group" column="GROUP_ID" class="Group"/>
            <key-many-to-one name="user" column="USER_ID" class="User"/>
        </composite-id>
    </class>
</hibernate-mapping>
 
 View user's profile Send private message Visit poster's website  
Reply with quote Back to top
support-rkalla
Post subject:   PostPosted: Dec 15, 2004 - 10:05 PM
Registered Member
Registered Member


Joined: Jan 06, 2004
Posts: 23855

IIRC those man-to-one's are the foreign key contraints back to your Group and User objects (Tables)... are they not?

_________________
Riyad
MyEclipse Support
 
 View user's profile Send private message Visit poster's website  
Reply with quote Back to top
support-jeff
Post subject:   PostPosted: Dec 16, 2004 - 01:45 AM
Moderator
Moderator


Joined: Jul 18, 2004
Posts: 357

Sho-nuf. Works as advertised. The PK of USER_GROUP consists of two FK refs - one to GROUP and one to USER. The generated class should have a composite key class that contains refs to User and Group class objects.

In reality, USER_GROUP would be a many-to-many relation that would not be mapped to a class. Instead there would be a m2m defined on one or both entity classes. This kind of mapping will be supported in a future release.

_________________
jeff
MyEclipse Support
 
 View user's profile Send private message  
Reply with quote Back to top
dserodio
Post subject:   PostPosted: Jan 03, 2005 - 12:07 PM
Registered Member
Registered Member


Joined: Jun 23, 2004
Posts: 51

The PK is correct, but there are no FK's in the generated mapping... There should be two FK in USER_GROUP, one to USER and another to GROUP.

_________________
"Correctness is clearly the prime quality. If a system does not do what it is supposed to do, then everything else about it matters little." - Bertrand Meyer
 
 View user's profile Send private message Visit poster's website  
Reply with quote Back to top
support-jeff
Post subject:   PostPosted: Jan 03, 2005 - 01:19 PM
Moderator
Moderator


Joined: Jul 18, 2004
Posts: 357

The composite key contains the only references you will ever get:
Code:
<composite-id name="id" class="UserGroupKey">
        <key-many-to-one name="group" column="GROUP_ID" class="Group"/>
        <key-many-to-one name="user" column="USER_ID" class="User"/>
</composite-id>


Are you thinking that you should have separate m2o properties outside of the key? This is not possible - it would really mess things up hibernate-wise.

Perhaps you should post what you think you should see for a mapping file? This might help clarify for me what you are getting at. According to what you have posted, the mapping is correct.

_________________
jeff
MyEclipse Support
 
 View user's profile Send private message  
Reply with quote Back to top
gtena3
Post subject: composite id  PostPosted: Jan 14, 2005 - 11:01 AM



Joined: Jan 11, 2005
Posts: 1

Somehow I've got the concept of composite id, but could you please give me a simple java code that would try to retrieve all "TABLE1" data with USERID='guest' and GROUPID='grp1'

sample mapping below:

<class name="table1" table="TABLE1">
<composite-id name="id" class="table1key">
<key-property name="userid" column="USERID" type="java.lang.String"/>
<key-property name="groupid" column="GROUPID" type="java.lang.String"/>
</composite-id>

<property name="name" column="NAME" type="java.lang.Long" />
<property name="address" column="ADDRESS" type="java.lang.Long" />
</class>


thanks.
 
 View user's profile Send private message  
Reply with quote Back to top
support-rkalla
Post subject:   PostPosted: Jan 14, 2005 - 02:10 PM
Registered Member
Registered Member


Joined: Jan 06, 2004
Posts: 23855

gtena,
That is a question for the Hibernate forums and/or reading the Hibernate docs on composite IDs. If you are getting started with Hibernate, the book Hibernate in Action is an absolute must-have.

_________________
Riyad
MyEclipse Support
 
 View user's profile Send private message Visit poster's website  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT - 6 Hours
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2004 The PNphpBB Group
Credits