Auto-commit with a4j:commandLink?
josief Sep 9, 2008 10:41 AMHi!
I have a problem and I don't understand what's going on! Just like there is a autocommit mode that is enabled and I don't get why and how.
This is my code :
I have a class that contains a Collection :
@Entity public class ExperimentalGroup { ... @OneToMany(mappedBy = "experimentalGroup", cascade = {CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REMOVE}, fetch = FetchType.LAZY) private Collection<RelSubjectExperimentalGroup> relSubjectExperimentalGroupList = new ArrayList<RelSubjectExperimentalGroup>(0); ...
And the objects that are contained in the collection:
@Entity @Table(name = "REL_SUBJECT_EXPERIMENTAL_GROUP") public class RelSubjectExperimentalGroup implements Serializable, Comparable<RelSubjectExperimentalGroup> { /** Subject */ @ManyToOne @JoinColumn(name = "SUBJECT_ID", referencedColumnName = "SUBJECT_ID") private Subject subject; /** Experimental Group */ @ManyToOne @JoinColumn(name = "EXPERIMENTAL_GROUP_ID", referencedColumnName = "EXPERIMENTAL_GROUP_ID") private ExperimentalGroup experimentalGroup; /** ID */ @Id @GeneratedValue(strategy = IDENTITY) @Column(name = "REL_SUBJECT_EXPERIMENTAL_GROUP_ID") private long id; ...
Then, to edit a ExperimentalGroup, I have this in my JSF page:
<s:fragment> <s:decorate id="relSubjectExperimentalGroupListDecorate" template="../template/editWithoutPassedImg.xhtml"> <ui:define name="label">#{msg['inrianeurotk.manageData.experimentalGroup.associated.subjects.associateNew']}:</ui:define> <h:selectOneMenu id="selectSubject" tabindex="2" for="subject" value="#{experimentalGroupHome.currentSubject}"> <s:selectItems value="#{subjectList.completeResultList}" var="subject" label="#{subject.subjectIdentifier} - #{subject.name}" noSelectionLabel="#{msg['inrianeurotk.manageData.create.new.subject.choose']}" /> <s:convertEntity /> </h:selectOneMenu> </s:decorate> <a4j:commandLink action="#{experimentalGroupHome.addSubject()}" id="createSubject" value="#{msg['inrianeurotk.manageData.experimentalGroup.subject.add']}" reRender="createExperimentalGroupForm"> </a4j:commandLink> </s:fragment>
In my JSF page, I can select a subject from the subject list and click on a add
commandLink to add the subject to the collection of subjects of the current instance of ExeprimentalGroupHome.
That is to say, I call the method addSubject() of ExperimentalGroupHome :
@Name("experimentalGroupHome") @Scope(ScopeType.CONVERSATION) @Stateful public class ExperimentalGroupHome extends EntityHome<ExperimentalGroup> implements IExperimentalGroupHome { private Subject currentSubject; public void addSubject() { if (currentSubject != null) { final RelSubjectExperimentalGroup relSubjectExperimentalGroup = new RelSubjectExperimentalGroup(); relSubjectExperimentalGroup.setSubject(currentSubject); relSubjectExperimentalGroup.setExperimentalGroup(this.getInstance()); if (!this.getInstance().getRelSubjectExperimentalGroupList().contains(relSubjectExperimentalGroup)) { this.getInstance().getRelSubjectExperimentalGroupList().add(relSubjectExperimentalGroup); currentSubject.getRelSubjectExperimentalGroupList().add(relSubjectExperimentalGroup); } } } ... }
What I want is to really add the subject when I click on the persist
button of my JSF page. Thus, the persist method of ExperimentalGroupHome is then called.
However, when I click on the Add
button (call to the addSubject() method), I can see in the logs that a new RelSubjectExperimentalGroup has been created and has been given an id.
I don't understand why the object RelSubjectExperimentalGroup is persisted! I don't call any method to do this.
Any help would be very appreciated.
Thanks in advance
Adrien