Announcement Announcement Module
Collapse
No announcement yet.
Help ! Spring MVC Design for inherited domain objects Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help ! Spring MVC Design for inherited domain objects

    hi,

    i am new in Spring 3 MVC programming. I had wrote a Spring 3 MVC example with Hibernate.

    This is the Class Diagram:

    Attachment

    There are the codes for person and company object:
    Code:
    @Entity
    @DiscriminatorValue("COMPANY")
    public class Company extends Customer {
    
    	private static final long serialVersionUID = 1L;
    	
    	private String companyName;
    
    	@Column(name = "company_name")
    	public String getCompanyName() {
    		return companyName;
    	}
    
    	public void setCompanyName(String companyName) {
    		this.companyName = companyName;
    	}
    
    }
    
    
    
    @Entity
    @DiscriminatorValue("PERSON")
    public class Person extends Customer {
    	
    	private static final long serialVersionUID = 1L;
    	
    	private String prefix;
    	private String firstName;
    	private String middleName;
    	private String lastName;
    	private String title;
    	private String gender;
    	private Date dateOfBirth;
    
           //  getters and setters
          }
    this is the code for object Customer:
    Code:
    @Entity
    @Table(name = "customer")
    @Inheritance(strategy = InheritanceType.SINGLE_TABLE)
    @DiscriminatorColumn(name = "customer_type", discriminatorType = DiscriminatorType.STRING)
    public class Customer implements Serializable {
    	
    	private static final long serialVersionUID = 1L;
    	
    	private Long id;
    	private String customerForeignId;
    	private List<Contact> contacts;
    	private Date creationDate;
    	private String status;
    
            // getters and setters
    
           @OneToMany(fetch = FetchType.LAZY, 
    			cascade = {CascadeType.ALL})
    	@JoinTable(name = "customer_hat_contacts",
    				joinColumns = {@JoinColumn(name = "customer_id")},
    				inverseJoinColumns = {@JoinColumn(name = "contact_id")})
    	public List<Contact> getContacts() {
    		return contacts;
    	}
    
           ...
           }

    There are the codes for contact and the inherited classes
    Code:
    @Entity
    @Table
    @Inheritance(strategy = InheritanceType.JOINED)
    @DiscriminatorColumn(name = "contact_cat", discriminatorType = DiscriminatorType.STRING)
    public abstract class Contact implements Serializable {
    
    	private static final long serialVersionUID = 1L;
    
    	private String id;
    	private boolean isPrimary;
    	private String contactType; // home, private, work, 24h
    	private String notice;
    	private Date createdDate;
            
            ...
           }
    
    @Entity
    @Table
    @DiscriminatorValue(value = "EMAIL")
    public class Email extends Contact {
    	
    	private static final long serialVersionUID = 1L;
    	
    	/*private long id;*/
    	private String email;
           
          // getter and setter
    }
    
    
    
    @Entity
    @Table
    @DiscriminatorValue(value = "TELEPHONE")
    public class Telephone extends Contact {
    	
    	private static final long serialVersionUID = 1L;
    	
    	//private long id;
    	private String telephoneNumber;
    	private String telephoneType; // Handy, Festnetz, Fax
    
           //getters and setters
    }
    
    ......
    My problems are:
    1. how to list all Customers(person and company mixed) in one jsp page. there are two different subclass objects.
    2. how to create a customer with contacts in one form?
    3. Is Creating a ViewObject(FromObject) for different Customer a better way?
    Attached Files

  • #2
    Did you ever get an answer to the question? I have the same issue

    Comment

    Working...
    X