Results 1 to 3 of 3
  1. #1
    jianrenyizhu is offline Member
    Join Date
    Mar 2012
    Posts
    5
    Rep Power
    0

    Default Help with deleting entity in a onetomany relationship

    Hi all, i'm having a problem deleting a child entity item. Everytime i delete it nothing happens and the association between the parent and the child is still there. I've searched through the net and some people suggest using orphanremoval but i've tried it and it didn't work. Appreciate if any could advise.
    My codes as below:

    ClientProfile Entity (PARENT)

    @Entity (name="ClientProfile")
    public class ClientProfile implements Serializable {

    @OneToMany(orphanRemoval = true)
    private List<Address> address;
    @OneToMany(orphanRemoval = true)
    private List<ClientJob> clientJob;
    @OneToMany(orphanRemoval = true)
    private List<Asset> clientAsset;
    ...
    }

    Asset Entity (CHILD)
    is a uni-directional relationship so asset entity doesnt contain any @ManyToOne

    In my SQL Database table my relationship is CLIENTPROFILE_CLIENTASSET
    adn they are connected by the clientid to the assetid

    In my session bean this is my remove method:

    @Override
    public void removeAsset(Long assetId) throws DoesNotExistsException{
    Query query = em.createQuery("SELECT as FROM Asset as WHERE as.assetId = :assetid");
    query.setParameter("assetid", assetId);
    if (query.getResultList().isEmpty()){
    throw new DoesNotExistsException("Asset does not exist!");
    } else {
    em.remove(query.getSingleResult());

    }
    }

    the assetid is being parsed into from the managedbean.
    i'm not sure if the remove method is wrong because this is the method i used to remove other entities items without relationship.

    Please advise. Thanks in advance!

  2. #2
    jianrenyizhu is offline Member
    Join Date
    Mar 2012
    Posts
    5
    Rep Power
    0

    Default Re: Help with deleting entity in a onetomany relationship

    anyone could help?

  3. #3
    jianrenyizhu is offline Member
    Join Date
    Mar 2012
    Posts
    5
    Rep Power
    0

    Default Re: Help with deleting entity in a onetomany relationship

    anyone could help?

Similar Threads

  1. oneToMany in JSF
    By renanrosa in forum JavaServer Faces (JSF)
    Replies: 0
    Last Post: 04-15-2011, 02:40 AM
  2. Replies: 1
    Last Post: 03-21-2011, 10:40 AM
  3. help with mapping and relationship
    By peace76 in forum Enterprise JavaBeans (EJB)
    Replies: 5
    Last Post: 12-07-2010, 08:12 PM
  4. What is this Object relationship?
    By SirRawlins in forum New To Java
    Replies: 3
    Last Post: 12-14-2007, 04:17 PM
  5. problem with ejb 3.0 entity beans with manyToMany relationship
    By makcro in forum Enterprise JavaBeans (EJB)
    Replies: 0
    Last Post: 07-26-2007, 08:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •