-->
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.  [ 4 posts ] 
Author Message
 Post subject: Get a real HashSet for a lazy Set instead of PersistentSet
PostPosted: Mon Nov 20, 2017 2:15 am 
Newbie

Joined: Wed Dec 28, 2011 8:10 pm
Posts: 5
Hey guys,
I have entities that use lazy Set<T> as relationships and I would like to "read" a Set<T> instead of PersistentSet.
Is it possible? Because I'm sending the pojo through network and I would like to send null or an empty set instead of something that will throw an exception.
Thanks

Baskwo


Top
 Profile  
 
 Post subject: Re: Lazy collection to native type instead of Persistent*
PostPosted: Mon Nov 20, 2017 2:28 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
It's not possible to use a HashSet when the collection is to be loaded lazily.

What you can do is to use DTOs instead. You can even get trees of DTOs right from the query.

Check out this article for more details.


Top
 Profile  
 
 Post subject: Re: Get a real HashSet for a lazy Set instead of PersistentSet
PostPosted: Tue Nov 21, 2017 10:42 am 
Newbie

Joined: Wed Dec 28, 2011 8:10 pm
Posts: 5
Well not just HashSet but any "native type" of Set like LinkedHashSet or SortedSet, etc.


Top
 Profile  
 
 Post subject: Re: Get a real HashSet for a lazy Set instead of PersistentSet
PostPosted: Tue Nov 21, 2017 11:02 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
Quote:
Well not just HashSet but any "native type" of Set like LinkedHashSet or SortedSet, etc.


It's the same thing. You can only get that:

1. Via DTO projections
2. If you eagerly fetch the association, which is a bad idea.

Anyway, passing entities to the web layer sounds like a code smell. Entities are only useful if you plan on modifying them. Otherwise, a DTO projection is much more efficient way of fetching data.


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