seam-gen code for many-to-one associations and reference dat
lawrieg Feb 14, 2007 11:32 AMHi,
I'm trying to understand the seam-generated code for many-to-one associations, and whether / how I need to modify it if I'm dealing with reference data that either is read-only (i.e. will be an Enum and will have matching database lookup table), or modified only very occasionally by an administrator (will be a class mapped to a database lookup/reference table).
seam-gen generates the following Seam Application Framework EntityHome code for my example project's Customer class:
@Name("customerHome") public class CustomerHome extends EntityHome<Customer> { @In(value = "#{statusHome.managedInstance}", required = false) Status status; @In(value = "#{customerTypeHome.managedInstance}", required = false) CustomerType customerType; public void setCustomerId(Integer id) { setId(id); } public Integer getCustomerId() { return (Integer) getId(); } @Override protected Customer createInstance() { Customer customer = new Customer(); return customer; } public void wire() { if (status != null) { getInstance().setStatus(status); } if (customerType != null) { getInstance().setCustomerType(customerType); } } public boolean isWired() { if (getInstance().getStatus() == null) return false; if (getInstance().getCustomerType() == null) return false; return true; } public Customer getManagedInstance() { return isManaged() ? getInstance() : null; } }
and CustomerEdit.page.xml is generated as follows
<page no-conversation-view-id="/CustomerList.xhtml"> <restrict>#{identity.loggedIn}</restrict> <begin-conversation join="true"/> <action execute="#{customerHome.wire}"/> <param name="customerFrom"/> <param name="customerId" value="#{customerHome.customerId}"/> <param name="statusFrom"/> <param name="statusId" value="#{statusHome.statusId}"/> <param name="customerTypeFrom"/> <param name="customerTypeId" value="#{customerTypeHome.customerTypeId}"/> <navigation from-action="#{customerHome.persist}"> <end-conversation/> <redirect view-id="/Customer.xhtml"/> </navigation> <navigation from-action="#{customerHome.update}"> <end-conversation/> <redirect view-id="/Customer.xhtml"/> </navigation> <navigation from-action="#{customerHome.remove}"> <end-conversation/> <redirect view-id="/CustomerList.xhtml"/> </navigation> </page>
So if I want Status to be an Enum, and CustomerType to be an immutable class that will be mapped to a database lookup/reference table, then what changes should I make to the seam-gen code???
I particular, I'm confused by the need for the wire() and isWired() methods - can anyone shed any light on what they are for and whether I'll still need them?
Thanks,
Lawrie