Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Issue deleting entity with references to them selves


Thanks! That took care of everything. Thanks for the tip. I'll reevaluate the Cascade Types.

Javier A. Ortiz Bultrón
Quality Assurance Engineer
B.Braun Medical, Inc.
972-466-5076 Phone




James Sutherland <jamesssss@xxxxxxxxx>
     Sent by: eclipselink-users-bounces@xxxxxxxxxxx

     
     
     12/08/2009 01:36 PM
Please respond to
EclipseLink User Discussions <eclipselink-users@xxxxxxxxxxx>

To
eclipselink-users@xxxxxxxxxxx
cc
Subject
Re: [eclipselink-users] Issue deleting entity with references to        them selves






What version of EclipseLink are you using?  Could you include the exception
and stack trace.

Do you have a cycle of objects being deleted?

You can try adding @PrivateOwned instead of the cascade remove, this may
resolve the issue, however you model seems very odd.  You have cascade ALL
on all your relationships, this means that if you delete anything, it will
delete everything, is this intended?  Normally remove is only cascaded for
dependent objects.



Javier.Ortiz wrote:
>
> I have an entity with a Many to One relationship to it self (but there are
> no instances of an entity referring to itself). When I try deleting the
> table contents I get complaints about the constraint. I thought that
> defining the relation as CascadeType.ALL would take care of it but that's
> not the case.
>
> Here's the entity (see the relationship in bold):
>
> /*
>  * To change this template, choose Tools | Templates
>  * and open the template in the editor.
>  */
> package com.bluecubs.xinco.core.server.persistence;
>
> import com.bluecubs.xinco.core.server.AuditedEntityListener;
> import com.bluecubs.xinco.core.server.XincoAuditedObject;
> import java.io.Serializable;
> import java.util.List;
> import javax.persistence.Basic;
> import javax.persistence.CascadeType;
> import javax.persistence.Column;
> import javax.persistence.Entity;
> import javax.persistence.EntityListeners;
> import javax.persistence.FetchType;
> import javax.persistence.Id;
> import javax.persistence.JoinColumn;
> import javax.persistence.ManyToOne;
> import javax.persistence.NamedQueries;
> import javax.persistence.NamedQuery;
> import javax.persistence.OneToMany;
> import javax.persistence.Table;
>
> /**
>  *
>  * @author Javier A. Ortiz Bultrón <javier.ortiz.78@xxxxxxxxx>
>  */
> @Entity
> @Table(name = "xinco_core_node")
> @EntityListeners(AuditedEntityListener.class)
> @NamedQueries({
>     @NamedQuery(name = "XincoCoreNode.findAll", query = "SELECT x FROM
> XincoCoreNode x"),
>     @NamedQuery(name = "XincoCoreNode.findById", query = "SELECT x FROM
> XincoCoreNode x WHERE x.id = :id"),
>     @NamedQuery(name = "XincoCoreNode.findByDesignation", query = "SELECT
> x FROM XincoCoreNode x WHERE x.designation = :designation"),
>     @NamedQuery(name = "XincoCoreNode.findByStatusNumber", query = "SELECT
> x FROM XincoCoreNode x WHERE x.statusNumber = :statusNumber")})
> public class XincoCoreNode extends XincoAuditedObject implements
> Serializable {
>
>     private static final long serialVersionUID = 1L;
>     @Id
>     @Basic(optional = false)
>     @Column(name = "id", nullable = false)
>     private Integer id;
>     @Basic(optional = false)
>     @Column(name = "designation", nullable = false, length = 255)
>     private String designation;
>     @Basic(optional = false)
>     @Column(name = "status_number", nullable = false)
>     private int statusNumber;
>     @JoinColumn(name = "xinco_core_language_id", referencedColumnName =
> "id", nullable = false)
>     @ManyToOne(optional = false, fetch = FetchType.LAZY)
>     private XincoCoreLanguage xincoCoreLanguageId;
>     @OneToMany(cascade = CascadeType.ALL, mappedBy = "xincoCoreNodeId",
> fetch = FetchType.LAZY)
>     private List<XincoCoreNode> xincoCoreNodeList;
>     @JoinColumn(name = "xinco_core_node_id", referencedColumnName = "id")
>     @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
>     private XincoCoreNode xincoCoreNodeId;
>     @OneToMany(cascade = CascadeType.ALL, mappedBy = "xincoCoreNodeId",
> fetch = FetchType.LAZY)
>     private List<XincoCoreAce> xincoCoreAceList;
>     @OneToMany(cascade = CascadeType.ALL, mappedBy = "xincoCoreNodeId",
> fetch = FetchType.LAZY)
>     private List<XincoCoreData> xincoCoreDataList;
>
>     public XincoCoreNode() {
>     }
>
>     public XincoCoreNode(Integer id) {
>         this.id = id;
>     }
>
>     public XincoCoreNode(Integer id, String designation, int statusNumber)
> {
>         this.id = id;
>         this.designation = designation;
>         this.statusNumber = statusNumber;
>     }
>
>     public Integer getId() {
>         return id;
>     }
>
>     public void setId(Integer id) {
>         this.id = id;
>     }
>
>     public String getDesignation() {
>         return designation;
>     }
>
>     public void setDesignation(String designation) {
>         this.designation = designation;
>     }
>
>     public int getStatusNumber() {
>         return statusNumber;
>     }
>
>     public void setStatusNumber(int statusNumber) {
>         this.statusNumber = statusNumber;
>     }
>
>     public XincoCoreLanguage getXincoCoreLanguageId() {
>         return xincoCoreLanguageId;
>     }
>
>     public void setXincoCoreLanguageId(XincoCoreLanguage
> xincoCoreLanguageId) {
>         this.xincoCoreLanguageId = xincoCoreLanguageId;
>     }
>
>     public List<XincoCoreNode> getXincoCoreNodeList() {
>         return xincoCoreNodeList;
>     }
>
>     public void setXincoCoreNodeList(List<XincoCoreNode>
> xincoCoreNodeList) {
>         this.xincoCoreNodeList = xincoCoreNodeList;
>     }
>
>     public XincoCoreNode getXincoCoreNodeId() {
>         return xincoCoreNodeId;
>     }
>
>     public void setXincoCoreNodeId(XincoCoreNode xincoCoreNodeId) {
>         this.xincoCoreNodeId = xincoCoreNodeId;
>     }
>
>     public List<XincoCoreAce> getXincoCoreAceList() {
>         return xincoCoreAceList;
>     }
>
>     public void setXincoCoreAceList(List<XincoCoreAce> xincoCoreAceList) {
>         this.xincoCoreAceList = xincoCoreAceList;
>     }
>
>     public List<XincoCoreData> getXincoCoreDataList() {
>         return xincoCoreDataList;
>     }
>
>     public void setXincoCoreDataList(List<XincoCoreData>
> xincoCoreDataList) {
>         this.xincoCoreDataList = xincoCoreDataList;
>     }
>
>     @Override
>     public int hashCode() {
>         int hash = 0;
>         hash += (id != null ? id.hashCode() : 0);
>         return hash;
>     }
>
>     @Override
>     public boolean equals(Object object) {
>         // TODO: Warning - this method won't work in the case the id
> fields are not set
>         if (!(object instanceof XincoCoreNode)) {
>             return false;
>         }
>         XincoCoreNode other = (XincoCoreNode) object;
>         if ((this.id == null && other.id != null) || (this.id != null &&
> !this.id.equals(other.id))) {
>             return false;
>         }
>         return true;
>     }
>
>     @Override
>     public String toString() {
>         return
> "com.bluecubs.xinco.core.server.persistence.XincoCoreNode[id=" + id + "]";
>     }
> }
>
> Any help/idea is welcomed!
>
> Thanks in advance!
>
> Javier A. Ortiz Bultrón
> Quality Assurance Engineer
> B.Braun Medical, Inc.
> 972-466-5076 Phone
> ********************************************************************************
> The information contained in this communication is confidential, may be
> attorney-client privileged, may constitute inside information, and is
> intended
> only for the use of the addressee. It is the property of the company of
> the
> sender of this e-mail. Unauthorized use, disclosure, or copying of this
> communication or any part thereof is strictly prohibited and may be
> unlawful.
> If you have received this communication in error, please notify us
> immediately
> by return e-mail and destroy this communication and all copies thereof,
> including all attachments.
> ********************************************************************************
>
>


-----
http://wiki.eclipse.org/User:James.sutherland.oracle.com James Sutherland
http://www.eclipse.org/eclipselink/
EclipseLink ,  http://www.oracle.com/technology/products/ias/toplink/
TopLink
Wiki:  http://wiki.eclipse.org/EclipseLink EclipseLink ,
http://wiki.oracle.com/page/TopLink TopLink
Forums:  http://forums.oracle.com/forums/forum.jspa?forumID=48 TopLink ,
http://www.nabble.com/EclipseLink-f26430.html EclipseLink
Book:  http://en.wikibooks.org/wiki/Java_Persistence Java Persistence
--
View this message in context: http://old.nabble.com/Issue-deleting-entity-with-references-to-them-selves-tp26683907p26699444.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.

_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users

********************************************************************************
The information contained in this communication is confidential, may be
attorney-client privileged, may constitute inside information, and is intended
only for the use of the addressee. It is the property of the company of the
sender of this e-mail. Unauthorized use, disclosure, or copying of this
communication or any part thereof is strictly prohibited and may be unlawful.
If you have received this communication in error, please notify us immediately
by return e-mail and destroy this communication and all copies thereof,
including all attachments.
********************************************************************************





Back to the top