-->
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.  [ 7 posts ] 
Author Message
 Post subject: Object Promotion?
PostPosted: Sun Feb 13, 2005 4:32 am 
Newbie

Joined: Thu Oct 28, 2004 3:38 am
Posts: 8
Assuming this simple mapping:

Code:
<class name="Entity"  discriminator-value="E">
    <id name="id" type="java.lang.Long">
        <generator class="identity"/>
    </id>
    <discriminator column="subclass" type="character"/>

    <!--  Numerous property definitions here -->

    <subclass name="NamedEntity" discriminator-value="N">
        <property name="name" type="java.lang.String"/>
    </subclass>
</class>


Is there any way of "promoting" an "Entity" object to a "NamedEntity" object?

I'd think it would generate an sql statement similar to the following:

Code:
update Entity set subclass='N', name=?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 13, 2005 6:02 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
do it in jdbc and don't forget to invalidate cache(s)

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


Top
 Profile  
 
 Post subject: Is this a common usage scenario?
PostPosted: Sun Feb 13, 2005 7:45 pm 
Newbie

Joined: Thu Oct 28, 2004 3:38 am
Posts: 8
Do people use it this way often? I know I've come across a couple situations where this would be handy - unless my thinking is skewed (which is very likely ;) ).

I know it can be done in jdbc - but I thought a hibernate abstraction of this function could be helpfull in ensuring value constraints were still met (i.e. a not-null constraint on the name property of the subclass). Also, in situations where this is performed often, constant cache invalidation would cause a performance hit.

My view of how this would actually work would be something like this:

Code:
Entity entity = session.load(Entity.class, integerValue);

NamedEntity namedEntity = session.promoteToSubclass(NamedEntity.class, entity);

namedEntity.setName("Entity Name");

session.update(namedEntity);


The promoteToSubclass function would return a special proxy object that would cause the persister to create the sql described above, also the cache invalidation would be handled either at that point or when update was called (whichever is appropriate).

Thoughts?


Top
 Profile  
 
 Post subject: Correction
PostPosted: Sun Feb 13, 2005 8:00 pm 
Newbie

Joined: Thu Oct 28, 2004 3:38 am
Posts: 8
Quote:
Also, in situations where this is performed often, constant cache invalidation would cause a performance hit.


I knew this wasn't true almost as soon as Isubmitted my previous post. I still think the API described above is interesting though.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 14, 2005 6:37 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
I understand that the API you described _seems_ easy... but it isn't.
Check the source and try to implement.

What you're trying to do isn't 100% related to Hibernate, try to change type in java... impossible.

Using hibernate/jdbc/refresh is a workaround, nothing else

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


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 14, 2005 7:09 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
This has also been discussed numerous times already here in the forum. Please search.


Top
 Profile  
 
 Post subject: Easy if there will never be both at the same time
PostPosted: Tue Feb 22, 2005 3:49 pm 
Newbie

Joined: Tue Jan 04, 2005 4:52 pm
Posts: 13
Hello,

You can simply set the discriminator to the same value on all your subclasses and the base class.

Then you simply get the kind you are interested in out and it ignores the properties not for the class you want.

This approach is not exactly what you wanted but will allow runtime determination of the kind of subclass to load.


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