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 can i return null values to bags not initialized?
PostPosted: Wed Feb 17, 2010 11:54 pm 
Newbie

Joined: Mon Feb 08, 2010 3:47 pm
Posts: 3
I'm trying serialize some objects through wcf. So, for performance reason, I have some collections configured with lazy=true. However, this proxy doesn't work with wcf. So, I made a solution based on the Tim Vasil solution.

http://timvasil.com/blog14/post/2008/02 ... rnate.aspx

In his solution he force initialization of collections with lazy=true because it can't be initialized in te client. Otherwise, in my solution if i don't force fetch mode in the moment of query so the collection will not be necessary on the client. Is there any way to instantiate a a empty collection or a return null without problem?

Tim Vasil
Code:
// Serialize persistent collections as the collection interface type
        if (obj is IPersistentCollection)
        {
            IPersistentCollection persistentCollection = (IPersistentCollection)obj;
            persistentCollection.ForceInitialization();
            obj = persistentCollection.Entries(); // This returns the "wrapped" collection
        }


I made the code bellow but it doesn't work.
Code:
           if (obj is IPersistentCollection) {
                IPersistentCollectioncoll = (IPersistentCollection)obj;
                if (!coll.WasInitialized){
                    obj = null;
                }
            }


Top
 Profile  
 
 Post subject: Re: How can i return null values to bags not initialized?
PostPosted: Fri Feb 19, 2010 12:50 am 
Newbie

Joined: Mon Feb 15, 2010 2:39 am
Posts: 4
how the instance variable was initialized with an instance of HashSet. This is the best way to initialize collection valued properties of newly instantiated (non-persistent) instances. When you make the instance persistent, by calling persist() for example, Hibernate will actually replace the HashSet with an instance of Hibernate's own implementation of Set. Be aware of the following errors:
Cat cat = new DomesticCat();
Cat kitten = new DomesticCat();
....
Set kittens = new HashSet();
kittens.add(kitten);
cat.setKittens(kittens);
session.persist(cat);
kittens = cat.getKittens(); // Okay, kittens collection is a Set
(HashSet) cat.getKittens(); // Error!

_________________
r4 gold ds


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.