Hi list
I'm playing around a bit with Amber and can't seem to get cascading
persist to work. The attached code runs fine but doesn't persist the
competences, only the search.
Have I misunderstood something?
Thanks in advance,
Torkil
package com.scr.data.search.entity;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
@Entity
public class Search {
@Id
@GeneratedValue
private int _id;
@OneToMany(mappedBy="search", cascade={CascadeType.ALL})
private Set<Competence> competences;
public int get_id() {
return _id;
}
public void set_id(int _id) {
this._id = _id;
}
public Set<Competence> getCompetences() {
return competences;
}
public void setCompetences(Set<Competence> competences) {
this.competences = competences;
}
}
package com.scr.data.search.entity;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
@Entity
public class Competence {
@Id
@GeneratedValue
private int _id;
private String _name;
private int _level;
private int _experience;
private int _last;
@ManyToOne
@JoinColumn(name="search")
private Search search;
public int get_id() {
return _id;
}
public void set_id(int _id) {
this._id = _id;
}
public String get_name() {
return _name;
}
public void set_name(String _name) {
this._name = _name;
}
public int get_level() {
return _level;
}
public void set_level(int _level) {
this._level = _level;
}
public int get_experience() {
return _experience;
}
public void set_experience(int _experience) {
this._experience = _experience;
}
public int get_last() {
return _last;
}
public void set_last(int _last) {
this._last = _last;
}
public Search getSearch() {
return search;
}
public void setSearch(Search search) {
this.search = search;
}
}
package com.scr.inhouse.test;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashSet;
import javax.ejb.TransactionAttribute;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.scr.data.search.entity.Competence;
import com.scr.data.search.entity.Search;
public class TestServlet extends HttpServlet {
private static final long serialVersionUID = -6604204182506392192L;
@PersistenceContext(name="search")
private EntityManager _manager;
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse
response) throws IOException {
PrintWriter out = response.getWriter();
response.setContentType("text/html");
insert(out);
}
@TransactionAttribute
protected void insert(PrintWriter out) {
Search search = new Search();
HashSet<Competence> competences = new HashSet<Competence>();
Competence competence1 = new Competence();
competence1.set_level(5);
competence1.set_name("Java");
competences.add(competence1);
Competence competence2 = new Competence();
competence2.set_level(5);
competence2.set_name("PHP");
competences.add(competence2);
System.out.println(competences);
search.setCompetences(competences);
_manager.persist(search);
}
}
_______________________________________________
resin-interest mailing list
resin-interest@caucho.com
http://maillist.caucho.com/mailman/listinfo/resin-interest