-->
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.  [ 3 posts ] 
Author Message
 Post subject: O/R Mapping: What ID generator to use for Legacy schemas?
PostPosted: Mon Jul 02, 2007 6:56 pm 
Newbie

Joined: Mon Jul 02, 2007 6:25 pm
Posts: 3
[b]Hibernate version: 3.2 [/b]

[b]Mapping documents: hibernate-mapping [/b]

[b]Name and version of the database you are using: Sybase (ASE 12.5.3)[/b]

[b]The SQL schema(show_sql=true):
CREATE TABLE dbo.Customer
(
cus_id int NOT NULL,
fname char(30) NOT NULL,
lname char(30) NULL
)

CREATE TABLE dbo.Address
(
addr_id int NOT NULL,
cus_id int NULL,
street varchar(50) NULL,
city varchar(50) NULL,
zipcode varchar(50) NULL,
)

CREATE TABLE dbo.TableIds
(
table_name char(40) NOT NULL,
next_id int NOT NULL
)

[/b]


We need to migrate our 7 yr-old java code to use hibernate.

Currently, to insert a row into Customer table (renamed for simplicity) is to execute select statement in the TableIds to get the unique key before executing INSERT statement on Customer table. The app is using trigger to update entries in TableIds table.

Without changing the db schema, which id generator should I use? How can I express the one-to-many relationship between Customer and Address table in hibernate-mapping xml? (PLEASE provide sample code/config)

Thank you


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 02, 2007 8:44 pm 
Beginner
Beginner

Joined: Thu Feb 22, 2007 6:08 am
Posts: 35
one to many relationship:

One Bid is from 1 Item, One Item can have more than 1 Bids
Bid n ------> 1 Item

Code:
<class name="Bid"
    table="BID">
    ...
    <many-to-one name="item"
        column="ITEM_ID"
        class="Item"
        not-null="true"/>
    </class>

<class name="Item"
    table="ITEM">
    ...
    <bag name="bids"
        inverse="true">
        <key column="ITEM_ID"/>
        <one-to-many class="Bid"/>
    </bag>
</class>


O the page 167 of the book Java Persistence with Hibernate you can find a table with the GenerationType's. Check it out and see what is the better for your case. If you have doubts use the auto. here is an example

Code:
<class name="Category" table="CATEGORY">
    <id name="id" column="CATEGORY_ID" type="long">
        <generator class="native"/>
    </id>
...
</class>


That book is very good. Read the capter 1,2, 4, 6, 10.

**dont forget to rate if it was helpfull this tip


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 06, 2007 10:40 am 
Newbie

Joined: Mon Jul 02, 2007 6:25 pm
Posts: 3
I'm still getting mapping error. <generator class="native"/> does not work. I'm using Sybase and tables have no IDENTITY column thus "native" is not working.

I'm working on "assigned" and looking at chapter 8 of the same book. Thanks for input though.

Anybody has similar project? Please tell me how did you approach when designing your domain model.

Regards,
Marvin


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