-
1. Re: Is Master-Detail possible in Seam
pmuir Jul 9, 2006 4:38 AM (in response to frustratedbyseam)Yes it is.
Perhaps if you post code and where you are having problems someone can help?
The problem you mention, duplicate entry of child row: perhaps you aren't creating a new child object for the second add?
I have such a page, it is based on a generic superclass that provides the standard actions and can be extended as needed to provide extra functionality and it works as you describe. -
2. Re: Is Master-Detail possible in Seam
frustratedbyseam Jul 9, 2006 6:54 AM (in response to frustratedbyseam)This is the parent code:
@Stateful
@Name("eventTypeUpdate")
@Conversational(ifNotBegunOutcome = "eventtypefind")
@LoggedIn
public class EventTypeUpdateAction implements EventTypeUpdate {
@PersistenceContext
private EntityManager em;
@In(required = false)
@Out
private EventType eventType;
@In(create = true)
private transient FacesMessages facesMessages;
@In(create = true)
private transient Events events;
@In
private EventTypeFind eventTypeFind = null;
@Begin
public String selectEventType() {
this.eventType = this.eventTypeFind.getSelectedEventType();
return "eventtypeupdate";
}
@End
public String cancel() {
return "eventtypefind";
}
@End
public String update() {
List existing = em.createQuery(
"select name from EventType where name=:name and id <> :id")
.setParameter("name", eventType.getName()).setParameter("id",
eventType.getId()).getResultList();
if (existing.size() == 0) {
em.merge(this.eventType);
Events.instance().raiseEvent("eventTypeUpdate");
return "eventtypefind";
} else {
facesMessages.add("An Event Type already exists with name #{eventtype.name}");
return null;
}
}
public String newEventTypeRole() {
EventTypeRole etr = new EventTypeRole();
this.eventType.getEventTypeRoles().add(etr);
etr.setEventType(this.eventType);
return "eventtypeupdate";
}
public int getEventTypeRolesNo() {
return this.eventType.getEventTypeRoles().size();
}
@DataModel
public List getEventTypeRoles() {
if (this.eventType == null || this.eventType.getEventTypeRoles() == null)
return new ArrayList();
return this.eventType.getEventTypeRoles();
}
@DataModelSelection
private EventTypeRole selectedEventTypeRole;
public EventTypeRole getSelectedEventTypeRole() {
return this.selectedEventTypeRole;
}
public String deleteEventTypeRole() {
if (this.eventType.getEventTypeRoles().contains(this.getSelectedEventTypeRole())) {
EventTypeRole etr = this.getSelectedEventTypeRole();
if (etr.getId() != null && etr.getId() > 0)
em.remove(etr);
this.eventType.getEventTypeRoles().remove(etr);
em.merge(this.eventType);
}
return "eventtypeupdate";
}
@Destroy
@Remove
public void destroy() {
}
} -
3. Re: Is Master-Detail possible in Seam
frustratedbyseam Jul 9, 2006 6:56 AM (in response to frustratedbyseam)Sorry mean't action code.
I've not posted the entities as I don't think there is anthing unusual there. -
4. Re: Is Master-Detail possible in Seam
frustratedbyseam Jul 9, 2006 2:09 PM (in response to frustratedbyseam)OK seem to have solved the repeating inserts. Adding a scope=PAGE on the @DataModel of the FindAction did the trick. Not sure why...
The next problem is that when I delete a child row, the action is persisted to the db. Is there a way to stop this. I've been digging around for stuff on Transaction annotations, but not found anything good. -
5. Re: Is Master-Detail possible in Seam
pmuir Jul 9, 2006 3:26 PM (in response to frustratedbyseam)@TransactionAttribute(TransactionType.NOT_SUPPORTED)
FlushMode.NEVER got removed from the EJB3 spec unfortunately, I know hibernate were going to provide it anway but it doesn't seem to be there atm. -
6. Re: Is Master-Detail possible in Seam
jcalvert Jul 10, 2006 10:33 AM (in response to frustratedbyseam)petemuir, can you elaborate on this? What does that do, TransactionType.NOT_SUPPORTED? Does it actually affect flushing?
I'm interested in potentially converting a Struts app backed by Hibernate to Seam. However we've had to set FlushMode.NEVER in many places because of the nature of our transactions. I'd like to believe there's a way to code around that, but I'd hate to start churning out code only to find it simply won't work. -
7. Re: Is Master-Detail possible in Seam
gavin.king Jul 10, 2006 1:11 PM (in response to frustratedbyseam)"FrustratedBySeam" wrote:
The next problem is that when I delete a child row, the action is persisted to the db. Is there a way to stop this.
One way to stop this is to use TransactionType.NOT_SUPPORTED -
8. Re: Is Master-Detail possible in Seam
frustratedbyseam Jul 10, 2006 5:10 PM (in response to frustratedbyseam)I think I've got it all working now with a few tweaks and using TransactionType.NOT_SUPPORTED.
Thanks for the comments.
Seams looking good once more.....