-->
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.  [ 11 posts ] 
Author Message
 Post subject: versioning a class and historizing
PostPosted: Wed Nov 24, 2004 5:30 am 
Newbie

Joined: Fri Oct 29, 2004 4:25 am
Posts: 7
hi there...
I am a newbe at hibernate and need a little help. I have a class (mapped on a table) that has an ID, a Version and a Name. The primary key is the ID, i tried to add the Version to the primarykey, but i couldn't make it.
The thing is:
each time i change my object, the version is increased. that is already working, thanks to the manual... the problem is, that hibernate overwrites the old row in the database. I want hibernate to create a new row in the database, so that i keep the old version and have the new one, but i don't want to create a whole new Object. I want to use the old one, store a new version and want to keep the old one. This is required because i maybe need to use the old rows later on.
Is there any way of doing it simplier than creating a new Object ?
I am still trying to understand the manual, therefore i maybe have overlooked something.

If anyone knows any help... I need it !
thanxs for your time !

cu Jens


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 24, 2004 5:59 am 
Expert
Expert

Joined: Tue Oct 05, 2004 9:45 am
Posts: 263
i think keeping the old version in the same table like the current version is not really a good idea ... the (for me) better way is to store the versioning data in a separate table ...

you can take a look in the wiki or in HiA ... there're some examples on how to write a history-object ...

gtx
curio


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 24, 2004 6:16 am 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
It depends on your needs.
  1. If you just need a kind of log in order you can see what hapened to your data the informatin on the wiki based on an Interceptor is fine.
  2. If you have a real historized DB, I mean if your data has different state depending on time, order, or other data I recomend to really model the behaviour. An example would be to have a master class/table with a child class/table representing the historized versions. If you have a lot of different classes with this kind of information it's worth to think about a Historized DAO which isolates this fact from the business logic.

HTH
Ernst


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 24, 2004 6:20 am 
Newbie

Joined: Fri Oct 29, 2004 4:25 am
Posts: 7
hi..
thanxs for the fast response!!!!

the point is, that it is not a real historizing. It is more a saving of all different versions of one object.
imagine:
You have a class like:

Code:
public class Process{
Integer ID;
Integer Version;
String Name;
}

and another one:

public class Node{
Integer NodeID;
Integer Version;
String Name;
Node [] next;
}



with those classes you can create a tree. I want to write an editor for this tree. when you switch to editormode, you can change the nodes in the process, and the properties of the process. when you then press save, i want to save the whole process/node thing in a new version. that means that the old process object and node objects are still there.
I only have two tables, that will be mapped to these two classes. in each table shall be all different objects with different versions.
I do not have a not historized object, therefore i wouldn't need a second table for historizing.
my problem is, each time i am saving an object of process, it overwrites the row of the table i created it with. but i want hibernate to insert a whole new row into the table... can i set some king o flag or constant that says "don not update, just insert a new one" ???
because of this, the version number should be part of the primary id (compositeID). how can i add a version number, that still has the functionality of a version number for hibernate, to a composite key ???

or do i have to create a whole new object each time i want to save a new one. still i would need the version number to be part of the ID !!!
how can i do this... ???

will read the texts you refered to... thanxs

Jens


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 26, 2004 5:05 am 
Newbie

Joined: Thu Oct 28, 2004 7:22 am
Posts: 5
if you find a "pretty" solution to your problem, it would be great to tell us... in fact i have excatly the same problem.. :)

Arnaud


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 26, 2004 5:07 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
the forum is done not only for asking for help but also for reading other topics

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

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 26, 2004 5:25 am 
Newbie

Joined: Fri Oct 29, 2004 4:25 am
Posts: 7
I was trying to build up a history with only one table. the example you refered to is done with two tables. that is easy... just copying the data and attaching a timstamp... but not the way i wanted it to be...


by the way.. i read that article, and it didn't look like the stuff i needed.
anthony wrote:
the forum is done not only for asking for help but also for reading other topics

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

there are over 460 pages with more than 20 articles a page... don't you think that it would take a lot of time, to search for anything helpful among this hughe number of articles ??? a little bit too much time....
don't you think aswell, that a searchenginge could overlook an article, or the search might not be precised enough ??? so you wouldn't find a specific article among the result of the search...

so don't you think that there is a rather great chance not to get all the articles that might be interesting for anyone concernes ?

i have to bear out that there should be an intense search and reading !!!!
but if you don't find anything, you usually ask ... most likely in a forum...

no offence !!!

thanxs for the great work and keep on doing...

J


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 26, 2004 6:09 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
i just think that searching at least the wiki and the blog helps a lot.

The topic i refered to was just one line under yours...

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 26, 2004 6:11 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
Quote:
but if you don't find anything, you usually ask ... most likely in a forum...


definitily not

you learn a lot of things reading other topics, i know what i'm talking about!

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 27, 2004 2:38 am 
Regular
Regular

Joined: Fri Nov 12, 2004 12:07 am
Posts: 57
Location: Beijing,China
Hi all,

The Attribute unsaved-value in mapping file of the object that corresponds the table should be set to "any" and The attrribute id should be set "assigned" at first,then wirte the code as below:

We assume class A maps table A

A a=(A)session1.get(A.class,"1_1");
sessioin1.close();
a.setId("1_2");
...
...
Session session2=sf.openSession();
session2.save(a);
session2.flush();
...

Above is only my guess,sorry for i don't try it and my english.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 27, 2004 3:33 pm 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
This thing with single table can be modeled this way:

1. TABLE to store data, primary key and version.
2. VIEW with corelated query to select rows with MAX version
3. TRIGGER on VIEW to transform updates to inserts with version generator.

Map class to view without any versions in model. This model is 'transparent', but it can be too slow, test it.


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