-->
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: Properties contained in a list
PostPosted: Fri Apr 27, 2007 3:04 pm 
Newbie

Joined: Thu Jun 22, 2006 7:19 am
Posts: 14
Hi

I have an object (Client) that has a list of addresses. I want that the client have a main address, a billing address and a shipping address, all contained in the list of addresses. How can i reference those type of address without

Code:
@Entity()
@Table(name="Clients")
public class Client extends BasePersistentObject {
   
    private static Logger log = Logger.getLogger(Client.class);
   
   
    @Id
    @Column(name="Id")
    @GeneratedValue(strategy=GenerationType.AUTO)
    private long id;
   
    @Column(name="companyName")
    private String companyName;
   
    @OneToMany(mappedBy="client", cascade=CascadeType.ALL)
    private List<Address> addresses;

    // What annotations? Should reference to an object of the addresses list.
    private Address mainAddress;

    // What annotations? Should reference to an object of the addresses list.
    private Address billingAddress;

    // What annotations? Should reference to an object of the addresses list.
    private Address shippingAddress;

    // The rest of methods, contructors, getters and setters.

}


The address class is very simple:

Code:
@Entity()
@Table(name="Addresses")
public class Address extends BasePersistentObject {
   
    @Id
    @Column(name="Id")
    @GeneratedValue(strategy=GenerationType.AUTO)
    private long id;
   
    @ManyToOne()
    @JoinColumn(name="Client_ID", nullable=false)
    private Client client;
   
    @Column(name="Address")
    private String address;

    // ...

}


Should I add new fields to the database? What is the best method to do this? Thanks in advance.

Hibernate version: 3.2.3

Name and version of the database you are using: MySQL 5.0, Windows XP SP2 Professional


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 27, 2007 4:43 pm 
Red Hat Associate
Red Hat Associate

Joined: Mon Aug 16, 2004 11:14 am
Posts: 253
Location: Raleigh, NC
New fields to the database, or you can store the addresses using a Map and give the interesting ones distinguished names.

Code:
public Address getBillingAddress() {
   return getAddresses.get(BILLING_ADDRESS_KEY);
}


I've never done it that way but I suppose it might work. I prefer the extra columns, and I have used that :)

-Chris


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.