-->
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 persist a Null Object
PostPosted: Mon Mar 01, 2004 4:54 am 
Newbie

Joined: Mon Mar 01, 2004 4:27 am
Posts: 1
Hi ,

I am using the Null Object pattern (http://www.refactoring.com/catalog/introduceNullObject.html) in my model.

I have a superclass A , and a null object N which is a subclass of A.
I have a situation where A is mapped to TABLE_A , and the discriminator column is TYPE.

Because N is a null object , I would not want it to be persisted into TABLE_A. It is discovered during runtime and should not be in TABLE_A.

I have a case where both A and N objects during runtime would be arranged in a certain sequence . After a sequence is arranged , I would need to capture a snapshot of the sequence and persist it into another table , say TABLE_ANOTHER. I would only need to store the OID into TABLE_ANOTHER.

How can I persist the null object instances into TABLE_ANOTHER ?
I tried using the subclass per table mapping (where the null object discriminator value is an arbitrary number -2 in the column TYPE to distinguish it from "actual" objects. Actual objects TYPE can is currently any integer number). But this method fails if I force TABLE_ANOTHER.OID to maintain referential integrity with TABLE_A.OID when performing a save.

If I drop the referential integrity , I get net.sf.hibernate.WrongClassException when I retrieve the object from TABLE_ANOTHER because I think internally Hibernate attempts to perform a join with TABLE_A and grab the discriminator value to create the actual object.

Is there a better solution to my problem ? Below is my existing mapping file.

<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
<class
name="A"
table="TABLE_A"
dynamic-update="false"
dynamic-insert="false"
>

<id
name="oid"
column="OID"
type="int"
>
<generator class="sequence">
</generator>
</id>

<discriminator
column="TYPE"
type="int"
/>

<property
name="type"
type="int"
update="false"
insert="false"
column="TYPE"
/>

<subclass
name="N"
dynamic-update="false"
dynamic-insert="false"
discriminator-value="-2"
>

</subclass>

</class>

</hibernate-mapping>


Thanks.
Kean


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 01, 2004 12:40 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
A cutom persister probably

_________________
Emmanuel


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.