-->
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.  [ 6 posts ] 
Author Message
 Post subject: Backup/Restore for generated Id
PostPosted: Tue Aug 14, 2007 12:05 pm 
Newbie

Joined: Tue Aug 08, 2006 7:48 am
Posts: 6
Hibernate version: 3.2.0.ga

MySQL 5.0.41

Hi!

Is it principally possible to manipulate the id of entities after a backup/restore-scenario for classes that are annotated with

Code:
...
   @Id
   @GeneratedValue
   private int id;
...


i.e. their ids are generated automatically and not provided by the client.

We have an application that uses more than one persistence unit with object relations crossing the PU's boundaries, so we maintain these relations "by hand" based on the id.

And, which is another reason for my question, we'd like to keep the id of objects of some of the entity classes constant after a backup/restore because their are referenced from outside the application.

regards,
Andreas


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 23, 2007 12:50 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I don't understand really what you mean.
Backup/restore of databases will not change the id, or maybe you want to do backup restore at the Java level, in this case look at session.replicate

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 24, 2007 5:18 am 
Newbie

Joined: Tue Aug 08, 2006 7:48 am
Posts: 6
Sorry, forgot these details. Yes, I want to do it at the Java level to "transfer data" between different versions of the application with possible changes in the object-relational-mapping, i.e. backup all data running under one version of the program to a version independent xml-format, then deploy the new version und restore all data from xml.

But the big problem seems to stem from the fact, that we use "hibernate through JPA", i.e. there is no Session, but an EntityManager et al.
There is no replicate then, unfortunately.

But thanks for your reply.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 28, 2007 3:04 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
do (Session) entityManager.getDelegate()
You will have the underlying session

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 30, 2007 7:50 am 
Newbie

Joined: Tue Aug 08, 2006 7:48 am
Posts: 6
Well, just tried that.

But despite the apidoc which says...

Persist the state of the given detached instance, reusing the current identifier value. This operation cascades to associated instances if the association is mapped with cascade="replicate".

...a new one is generated. :-((((

I debugged replicate() and found that in the end it uses the prepared insert-statement that leaves out the id-column, hence a new value is generated (in our case by an autoincrement field of MySQL5). But at least in MySQL you can set the value of an autoincrement field if it is given in the insert statement.

This is somehow related to

http://forum.hibernate.org/viewtopic.php?t=948071

I want to import my xml-backup'd data in a fashion that is contrain-friendly. I.e. objects are inserted back in an order where new objects only reference objects that are already there. Plus I don't care for replication-cascading. I only want the ids of my main objects preserved as they act as keys to the outside that mustn't change after first use. Internal ids for embedded relations may change freely.

So I have to go back to the other idea to "solve" this...add another column to each relevant entity class with an external id that is initialized by the value of the auto generated id and then stays untouched on each backup/restore.

But thanks for trying to help anyway!

Much appreciated.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 30, 2007 5:26 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Well, autoincrement columns cannot be fooled I think

_________________
Emmanuel


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