Solved

Hibernate cascade deletes but does not save

Posted on 2014-10-06
1
141 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
1 Comment
 

Accepted Solution

by:
fblack61 earned 0 total points
Comment Utility
I had to use merge.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This video teaches users how to migrate an existing Wordpress website to a new domain.
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.

744 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now