-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: JPA cascade ?
PostPosted: Sun Jan 17, 2010 1:46 pm 
Newbie

Joined: Mon Jul 09, 2007 9:32 am
Posts: 17
I am using JPA + hibernate + Spring, but looks like the Cascade doesn't work.

Please see the coding, what I expect is, "John" is deleted, "Mary" is added. But I try all javax.persistence.CascadeType, it will not give me the result. Then I try to use org.hibernate.annotations.CascadeType, it will always give me syntax error.

Where is the problem ?

Thanks.

Code:
class Company{
    ....
    @OneToMany(cascade = javax.persistence.CascadeType.ALL, fetch = FetchType.EAGER)
    List<Employee> employeeList;
}

// test coding
Company company = new Company();
List<Employee> employeeList = new ArrayList<Employee>();
employeeList.add(new Empployee("John"));
employeeList.add(new Empployee("Peter"));
company.setEmployeeList(employeeList);
dao.getHibernateTemplate().merge(company);

//-------------
company.getEmployeeList().remove(0);
company.getEmployeeList().add(new Employee("Mary"));
dao.getHibernateTemplate().merge(company);
// what I expect is, "John" is deleted, "Mary" is added.


Top
 Profile  
 
 Post subject: Re: JPA cascade ?
PostPosted: Mon Jan 18, 2010 9:34 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Does the remove delete the entity, or simply remove the association? Try to delete the entity instead.

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.