-->
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: How to set initial properties
PostPosted: Tue Dec 02, 2003 8:54 am 
Regular
Regular

Joined: Thu Aug 28, 2003 10:54 am
Posts: 67
If I have a Customer object which has an Address object how can I ensure that the address is never null even though its fields in the database may be null.

e.g.

Code:
class Customer {
     
     private Address address;

     public Customer(){
         address=new Address();
      }

      getter/setter for address

}


class Address {

   private string street;
   private String town;

etc.
}



No suppose that for a particular customer street and town have not been set. Hibernate then does not create an Address object and sets the customer's address to null. What i want though is for this customer to have an empty address object.

does this make sense?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 02, 2003 9:15 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
You should do this logic in the setter and/or getter methods. Thats what they are there for, right?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 02, 2003 9:17 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
If you mapp this as a one-to-one, and give Adress a propper ID, it should work ... You cannot use component mappings here, IMHO


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 02, 2003 9:32 am 
Regular
Regular

Joined: Thu Aug 28, 2003 10:54 am
Posts: 67
Quote:
You should do this logic in the setter and/or getter methods. Thats what they are there for, right?


When I add a check in the setter i.e

Code:
public setAddress(Address newAddress) {
    if(newAddress!=null) this.address = newAddress;
}



hibernate issues a new update to the customer at the end of the transaction. I would like to avoid this.

Quote:
If you mapp this as a one-to-one, and give Adress a propper ID, it should work ...


Doesn't that mean that i will have to create a mapping file for Address? Since I will have many classes like Adress i'd rather not create separate mappings for them all.


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.