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.  [ 5 posts ] 
Author Message
 Post subject: question regarding an update on mapped fields only
PostPosted: Thu Sep 09, 2004 2:44 pm 
Newbie

Joined: Wed Oct 22, 2003 12:59 pm
Posts: 14
Hi all

I have a question re. the best way to deal with the following scenario when
it is needed to update only fields that are mapped in a persistent object.
In other words, suppose there is the following hierarchy:



Hibernate version:
version 2.0.3



Code:
public class MyObject
{
    private String firstName;
     ...
     //public getter/setter method s
}


public class MyPersistentObject extends MyObject
{

    private String lastName;
     ...
     //public getter/setter method s


}



and in the MyPersistentObject.hbm.xml I only map the LastName attribute.

When we want to update this object, I only want to be able to set the changes on the mapped attributes i.e lastName and not firstName
I could override setter method for firstName by throwing an Exception or something similar, but the drawback of this approach would be the lack of synch between the two objects, whenever there is change in either object.
Is there any clearer way to accomplish this? does Hibernate provides any API that would allow me to know what are the attributes mapped for a specific object?
thanks in advance
Patria


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 10, 2004 11:15 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I don't really undestand what you want to do but Hibernate provides its metadata through sessionFactory.getClassMetadata()

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 10, 2004 12:46 pm 
Newbie

Joined: Wed Oct 22, 2003 12:59 pm
Posts: 14
hi Emmanuel

thanks for your reply.
Let me explain to you in a clearer way what I'd would like to do:

There is a objects hierarchy (A), but we have created a subset (B)of it because we are not interested in persisting the whole hierarchy.
By subset , I mean the following:
We have this class in the objects hierarchy A

Code:
public class Segment{
   private String destination
   private String origin
   private String airlineCode;
    // getters/setters for this fields

}


We're only interested in persisting attributes :destination and origin, and we want to persist also a new attribute Date
Therefore, we end up having the following:

Code:
public class MySegment extends Segment{
private Date departureDate;
// getter/setter for this field
   
}


And we have the mapping for this object which is MySegment.hbm.xml
which will contain mapping for following attributes:

Segment.destination
Segment.origin
MySegment.departureDate

now, when we want to update MySegment, we retrieve the persistent version of it, and then we are able to set new values for all attributes, including those that are not included in the mapping (which is NOT what we want) and then update the object.

Therefore, I was looking for a way to sort of disable the setting of non-mapped attributes.

am i making myself clearer? if not, just let me know what it is not clearly explained....

any help would be much appreciated
Patria


Code:
Code:
Code:


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 12, 2004 6:13 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Well not clear enough

1. You don't want to persist airlinecode.
if it is not mapped, then it is *not* persisted.

2. you don't want to set airline code from your java code, then do not add setAirlinecode() method in you Segment class

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 13, 2004 2:51 pm 
Newbie

Joined: Wed Oct 22, 2003 12:59 pm
Posts: 14
Hi Emmanuel

Well, the thing is that I can't disable those setter methods i.e for airline code since it is legacy code. There're some other pieces of code using those setter methods.....


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