Solved

Hibernate cascade deletes but does not save

Posted on 2014-10-06
1
146 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
ID: 40375777
I had to use merge.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
It’s a strangely common occurrence that when you send someone their login details for a system, they can’t get in. This article will help you understand why it happens, and what you can do about it.
Wufoo.com provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.
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.

803 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