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)
Collapse | Copy Code
@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.