-->
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: Should we new a List?
PostPosted: Sun Feb 22, 2009 5:45 am 
Newbie

Joined: Mon Jul 21, 2008 5:40 am
Posts: 16
Hi,

In the class below, the two lists, one allocated while another not, all works, any difference? what is the correct way to handle a one to many situation like this? Thanks,

Angelo

public class User {

private Long id;

private List<Address> addresses;
private List<Contact> contacts = new ArrayList<Contacts>();

}


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 22, 2009 7:40 am 
Senior
Senior

Joined: Thu Jan 08, 2009 3:48 pm
Posts: 168
As far as i know this only makes a difference outside the persistence context, as soon as you access the collection inside a session you will always get a least an empty list, never null.

So it's up to you, but i would suggest going one way or the other for code consistency.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 22, 2009 8:14 pm 
Newbie

Joined: Mon Jul 21, 2008 5:40 am
Posts: 16
pkleindl wrote:
As far as i know this only makes a difference outside the persistence context, as soon as you access the collection inside a session So


Is a detached object consider as outside of persistence context?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 23, 2009 7:16 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
A detached object was previously attached so it was initialized by hibernate. The collections also should never be null. As pkleindl says, the only difference is, when you create objects of User using the constructor.

_________________
-----------------
Need advanced help? http://www.viada.eu


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.