I have two questions:
I have two model objects, Item and Person that have a one-to-one
relationship driven by the primary key. Each of these objects extend a
ModelBase object that has a generated ID (annotations: @Id and
@GeneratedValue).
Am I correct to relate these objects to one another like this?
@Entity
public class Item extends ModelBase {
@OneToOne @PrimaryKeyJoinColumn
private Person person;
...
// getters and setters
}
@Entity
public class Person extends ModelBase {
@OneToOne
private Item item;
...
// getters and setters
}
Furthermore, how do I assign values to these in my action class when
populating via a form that assigns values to attributes in each model?
Right now, I have an action bean that is supposed to populate both, but on
persistence, my Person object is always null:
public class ItemFormActionBean extends BaseActionBean {
@ValidateNestedProperties ({
@Validate(field="name", required=true, on="submit"),
@Validate(field="desc", required=true, on="submit"),
})
private Item item;
@ValidateNestedProperties ({
@Validate(field="eMail", required=true, on="submit",
converter=EmailTypeConverter.class)
})
private Person person;
...
// getters and setters
public Resolution submit() {
EntityManager em = Stripersist.getEntityManager();
em.persist(item);
em.persist(person);
em.getTransaction().commit();
...
}
...
}
TIA!
------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Stripes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-users