?
Solved

Hibernate cascade deletes but does not save

Posted on 2014-10-06
1
Medium Priority
?
151 Views
Last Modified: 2014-10-12
UserprojectEntity has a OnetoMany relation with LinereferenceEntity. My cascade works for delete but not save.

UserprojectEntity:

  @XmlElementWrapper(name = "linereferencelist")
  @OneToMany(fetch = FetchType.LAZY,  mappedBy = "upl")
    @Cascade(CascadeType.ALL)
    @OrderBy("id ASC")
    public Collection<LinereferenceEntity> getLinereference() {
        return linereference;
    }

    public void setLinereference(Collection<LinereferenceEntity> linreference) {
        this.linereference = linreference;
    }

LinereferenceEntity:

 private UserprojectEntity upl;
    @XmlTransient
    @ManyToOne
    @JoinColumns({@JoinColumn(name = "user", referencedColumnName = "user", nullable = false,insertable = false,updatable = false), @JoinColumn(name = "project", referencedColumnName = "project", nullable = false,insertable = false,updatable = false)})
    public UserprojectEntity getUpl() {
        return upl;
    }

    public void setUpl(UserprojectEntity upl) {
        this.upl = upl;
    }
}

Calling program:


    private void deleteRecords(String sConfig, String sDelstring){
        SessionFactory sessionFactory = commonFuncs.getSessionFactory(sConfig) ;

        Session session = sessionFactory.openSession();
        Transaction transaction;

        transaction = session.beginTransaction();

        Query q = session.createQuery(sDelstring);

        Object upe = q.list().get(0);
        session.delete(upe);
        transaction.commit();
        session.close();

    }


 private void saveRecords(String sConfig, Object obj){
        SessionFactory sessionFactory = commonFuncs.getSessionFactory(sConfig) ;

        Session session = sessionFactory.openSession();
        Transaction transaction;
        transaction = session.beginTransaction();


        session.save(obj);

        transaction.commit();
        session.close();

    }
0
Comment
Question by:fblack61
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 

Accepted Solution

by:
fblack61 earned 0 total points
ID: 40375777
I had to use merge.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question