Solved

Hibernate cascade deletes but does not save

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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Java 8 to Java 6 8 43
Unwanted output from my query 5 52
Good forum hosting with good privacy policy 3 31
Error in sql query statment. 21 70
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

732 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