-->
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.  [ 2 posts ] 
Author Message
 Post subject: How to save object with custom id
PostPosted: Sun Jan 06, 2008 9:30 am 
Newbie

Joined: Mon Aug 27, 2007 8:51 am
Posts: 2
Hibernate version: 3.x

I have two tables. First with Users, second with Category.

For example

Code:
User

id | name   | categoryId
----------------------------
1  | Paul   | 3
2  | Raul   | 2
4  | Alice  | 5


Category

id | name
----------------------------
2  | one
3  | two
5  | three


I want to transfer database from one server to another. In program i use serialization to do this. I read all object and save (serialize) it to file. I copy this file to another server. Database is save as object into the file. In second server i just read it, and one more time save.

The problem is - how to save object with custom id. When i read object from file - they have right id. After i save it - they have auto generate id from hibernate. Foreign key categoryId - isn't right. Category have another new id.

The best solution is - save object with right, custom id. How to do this ?

thanks for help!


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 06, 2008 10:25 am 
Expert
Expert

Joined: Tue Jan 30, 2007 12:45 am
Posts: 283
Location: India
Hi Wareq,

Use <generator> type assigned

http://www.hibernate.org/hib_docs/reference/en/html/mapping.html

_________________
Dharmendra Pandey


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