I have the following form inside a dialog:
<h:form id="CommentCreateForm">
<h:panelGroup id="display">
<p:outputPanel id="commentsPanel">
<p:row>
<p:column>
<p:inputTextarea id="commentText" value="#{commentsController.selected.commentText}" cols="100" rows="20" style="margin-bottom:10px"/>
</p:column>
</p:row>
</p:outputPanel>
<p:commandButton actionListener="#{commentsController.savePropReception}" value="#{myBundle.Save}" update="display,:PmMainListForm:datalist,:growl" oncomplete="handleSubmit(xhr,status,args,PF('CommentCreateDialog'));">
<p:confirm header="#{myBundle.ConfirmationHeader}" message="#{myBundle.ConfirmEditMessage}" icon="ui-icon-alert"/>
</p:commandButton>
</h:panelGroup>
</h:form>
With it's corresponding parent entity called Comments
:
@Entity
@Table(name = "comments")
@XmlRootElement
@NamedQueries({
@NamedQuery(name = "Comments.findAll", query = "SELECT c FROM Comments c")
, @NamedQuery(name = "Comments.findByCommentText", query = "SELECT c FROM Comments c WHERE c.commentText = :commentText")
, @NamedQuery(name = "Comments.findByIdComments", query = "SELECT c FROM Comments c WHERE c.idComments = :idComments")})
public class Comments implements Serializable {
private static final long serialVersionUID = 1L;
@Size(max = 2147483647)
@Column(name = "comment_text")
private String commentText;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "id_comments")
private Long idComments;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "propReceptionComment")
private List<PmMain> pmMainCollection5;
[... Getters and Setters ...]
public void setPropReception(PmMain pmMain){
pmMain.setPropReceptionComment(this);
pmMainCollection5.add(pmMain);
}
And it's child entity called PmMain
:
@Entity
@Table(name = "pm_main")
@XmlRootElement
@NamedQueries({
@NamedQuery(name = "PmMain.findAll", query = "SELECT p FROM PmMain p")
, @NamedQuery(name = "PmMain.findByPropId", query = "SELECT p FROM PmMain p WHERE p.propId = :propId")
, @NamedQuery(name = "PmMain.findByPropName", query = "SELECT p FROM PmMain p WHERE p.propName = :propName")
, @NamedQuery(name = "PmMain.findByPropStatus", query = "SELECT p FROM PmMain p WHERE p.propStatus = :propStatus")
, @NamedQuery(name = "PmMain.findByIdPmMain", query = "SELECT p FROM PmMain p WHERE p.idPmMain = :idPmMain")})
public class PmMain implements Serializable {
private static final long serialVersionUID = 1L;
@Size(max = 25)
@Column(name = "prop_id")
private String propId;
@Size(max = 125)
@Column(name = "prop_name")
private String propName;
@Size(max = 25)
@Column(name = "prop_status")
private String propStatus;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "id_pm_main")
private Long idPmMain;
@JoinColumn(name = "prop_reception_comment", referencedColumnName = "id_comments")
@ManyToOne
private Comments propReceptionComment;
[... Getters and Setters ...]
And the CommentsController
contains a method called savePropReception
:
public void savePropReception(){
PmMain pmMain = new PmMain();
Comments comments = new Comments();
pmMain.setPropReceptionComment(comments);
comments.setPropReception(pmMain);
commentsFacadeEJB.edit(comments);
}
While commentsFacadeEJB
contains:
public void edit(T entity) {
getEntityManager().merge(entity);
}
So, when a PmMain
is already created, I can't get PmMain.propRecetionComment
to update with the ID of a new 'Comments'. What am I missing?