2 Replies Latest reply on Aug 16, 2006 1:25 AM by wondermike

    How to deal with a list

    smokingapipe

      I'm setting up an application that has an object called Person. Every Person has an Address. But it's more complicated than that. For various legal and accounting reasons, we need to keep track of every Address that Person has ever had. So I set it up like this:

      @Entity public class Person {
      
       private List<Address> addresses;
      
       public List<Address> getAddresses() { ... }
       public void setAddresses(List<Address> list) { .... }
      
       // and to make it easy to get the current address:
       public void setCurrentAddress(Address address) {
       if(addressess == null) addresses = new LinkedList<Addresses>();
       addresses.add(address);
       }
      
       public Address getAddress() {
       // return the last element in the addresses array
       }
      }
      


      Pretty straight-forward, right? Oh, and I have set Cascade to ALL for these lists, so that is taken care of.

      How do I handle this within Seam? If I don't put @Transient on getAddress(), then it creates a bytea field in the DB to store the address, which is not what I want. If I do market it as transient, nothing gets stored.

      There must be some simple way to handle this, right?