You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by bruno grandjean <br...@live.fr> on 2010/03/27 18:27:35 UTC

CRUD with a OneToMany association under Struts 2 / Hibernate 3

Hi

I am trying to implement a simple CRUD with a OneToMany association under Struts 2 / Hibernate 3.
I have two entities Parent and Child:

@Entity
@Table(name="PARENT")
public class Parent {
 private Long id;
 private Set<Child> values = new HashSet<Child>();  
..
@Entity
@Table(name="CHILD")
public class Child {
 private Long id; 
 private String name; 
..

I can easily create, delete Parent or read the Child Set (values) but it is impossible to update Child Set.
The jsp page (see below) reinit the values Set, no record after updating!
Could u explain to me what's wrong?

here are my code:

@Entity
@Table(name="PARENT")
public class Parent {
 private Long id;
 private Set<Child> values = new HashSet<Child>();  
 @Id
 @GeneratedValue
 @Column(name="PARENT_ID") 
 public Long getId() {
  return id;
 }
 public void setId(Long id) {
  this.id = id;
 }
 @ManyToMany(fetch = FetchType.EAGER)    
 @JoinTable(name = "PARENT_CHILD", joinColumns = { @JoinColumn(name = "PARENT_ID") }, inverseJoinColumns = { @JoinColumn(name = "CHILD_ID") })  
 public Set<Child> getValues() {  
  return values;
 }
 public void setValues(Set<Child> lst) {
  values = lst;  
 }
}

@Entity
@Table(name="CHILD")
public class Child {
 private Long id; 
 private String name; 
 @Id
 @GeneratedValue
 @Column(name="CHILD_ID") 
 public Long getId() {
  return id;
 }
 public void setId(Long id) {
  this.id = id;
 }
 @Column(name="NAME")
 public String getName() {  
  return name;
 }
 public void setName(String val) {
  name = val;
 } 
}

public interface ParentDAO {
 public void saveOrUpdateParent(Parent cl);
 public void saveParent(Parent cl);
 public List<Parent> listParent();
 public Parent listParentById(Long clId);
 public void deleteParent(Long clId);
}

public class ParentDAOImpl implements ParentDAO {
 @SessionTarget
 Session session;
 @TransactionTarget
 Transaction transaction;

 @Override
 public void saveOrUpdateParent(Parent cl) {  
  try {
   session.saveOrUpdate(cl);
  } catch (Exception e) {
   transaction.rollback(); 
   e.printStackTrace();
  }
 }

 @Override
 public void saveParent(Parent cl) {
  try {
   session.save(cl);
  } catch (Exception e) {
   transaction.rollback();
   e.printStackTrace();
  }
 }
 
 @Override
 public void deleteParent(Long clId) {
  try {
   Parent cl = (Parent) session.get(Parent.class, clId);
   session.delete(cl);
  } catch (Exception e) {
   transaction.rollback();
   e.printStackTrace();
  } 
 }
 
 @SuppressWarnings("unchecked")
 @Override
 public List<Parent> listParent() {
  List<Parent> courses = null;
  try {
   courses = session.createQuery("from Parent").list();
   } catch (Exception e) {
   e.printStackTrace();
  }
  return courses;
 }

 @Override
 public Parent listParentById(Long clId) {
  Parent cl = null;
  try {
   cl = (Parent) session.get(Parent.class, clId);
  } catch (Exception e) {
   e.printStackTrace();
  }
  return cl;
 }
}

public class ParentAction  extends ActionSupport implements ModelDriven<Parent> {

 private static final long serialVersionUID = -2662966220408285700L;
 private Parent cl = new Parent();
 private List<Parent> clList = new ArrayList<Parent>(); 
 private ParentDAO clDAO = new ParentDAOImpl();
 
 @Override
 public Parent getModel() {
  return cl;
 }
 
 public String saveOrUpdate()
 {
  clDAO.saveOrUpdateParent(cl);  
  return SUCCESS;
 }

 public String save()
 {  
  clDAO.saveParent(cl);  
  return SUCCESS;
 }

 public String list()
 {
  clList = clDAO.listParent();
  return SUCCESS;
 }
 
 public String delete()
 {
  HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
  clDAO.deleteParent(Long.parseLong(request.getParameter("id")));
  return SUCCESS;
 }

 public String edit()
 {
  HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
  cl = clDAO.listParentById(Long.parseLong(request.getParameter("id")));
  return SUCCESS;
 }
 
 public Parent getParent() {
  return cl;
 }

 public void setParent(Parent cl) {
  this.cl = cl;
 }

 public List<Parent> getParentList() {
  return clList;
 }

 public void setParentList(List<Parent> clList) {
  this.clList = clList;
 }
}

and finally the jsp page:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
 pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib uri="/struts-tags" prefix="s"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Parent Registration Page</title>
<s:head />
<style type="text/css">
@import url(style.css);
</style>
</head>
<body>
<s:form action="saveOrUpdateParent">
 <s:push value="parent">
  <s:hidden name="id" />  
   <s:push value="values">
   <s:iterator id="p" value="values">
   <s:textfield label="Nom" name="values(%{id}).name" value="%{name}"/>
        </s:iterator>
  </s:push>
    <s:submit />
 </s:push>
</s:form>

<s:if test="parentList.size() > 0">
 <div class="content">
 <table class="userTable" cellpadding="5px">
  <tr class="even">
   <th>Child(s)</th>
  </tr>
  <s:iterator value="parentList" status="userStatus">
   <tr
    class="<s:if test="#userStatus.odd == true ">odd</s:if><s:else>even</s:else>">
    <td><s:property value="values.size()" /></td>
    <s:iterator value="values">
     <td><s:property value="name" /></td>
    </s:iterator>
    <td><s:url id="editURL" action="editParent">
     <s:param name="id" value="%{id}"></s:param>
    </s:url> <s:a href="%{editURL}">Edit</s:a></td>
    <td><s:url id="deleteURL" action="deleteParent">
     <s:param name="id" value="%{id}"></s:param>
    </s:url> <s:a href="%{deleteURL}">Delete</s:a></td>
   </tr>
  </s:iterator>
 </table>
 </div>
</s:if>
</body>
</html>

Re: CRUD with a OneToMany association under Struts 2 / Hibernate 3

Posted by bruno grandjean <br...@live.fr>.
Dear Rene,

Thks a lot for replying to me because I am feeling a little bit alone with 
my CRUD ;-). In fact I am trying to build a dynamic MetaCrud.
My pb is simple: in the same jsp page I would like to update a Parent object 
and its Childs (values):

<s:form action="saveOrUpdateParent">
<s:push value="parent">
	<s:hidden name="id" />	<s:textfield 
name="name" label="Nom" />
		<s:push value="values">
 		<s:iterator id="p" value="values">
		    <s:textfield label="Nom" name="#name" value="%{name}"/>
                                </s:iterator>
		</s:push>
<s:submit />
</s:push>
</s:form>

>From an existing Parent object with many Childs objects I can easily modify 
parent.name for instance but the collection of Child objects (values) is 
always empty in the ParentAction (saveOrUpdate() method) after submitting.
However I can display each values[i].name in the jsp page with the correct 
value.
So it is not an issue with Hibernate but with the jsp or ModelDriven 
interface I don't know..Do you have any idea?
Basically I was not able to find a struts or spring documentation about CRUD 
& association between two entities on the same jsp page.
best regards
bruno

--------------------------------------------------
From: "Rene Gielen" <gi...@it-neering.net>
Sent: Wednesday, March 31, 2010 7:12 PM
To: "Struts Users Mailing List" <us...@struts.apache.org>
Subject: Re: CRUD with a OneToMany association under Struts 2 / Hibernate 3

> I'm not sure if I understand what your actual question is, nor whether
> it is particularly Struts 2 related (rather than just Hibernate) - but
> you might want to have a look in the CRUD demo section of the Struts 2
> showcase application. Maybe you will also find this demo useful:
> http://github.com/rgielen/struts2crudevolutiondemo
>
> - René
>
> bruno grandjean schrieb:
>> Hi
>>
>> I am trying to implement a simple CRUD with a OneToMany association under 
>> Struts 2 / Hibernate 3.
>> I have two entities Parent and Child:
>>
>> @Entity
>> @Table(name="PARENT")
>> public class Parent {
>>  private Long id;
>>  private Set<Child> values = new HashSet<Child>();
>> ..
>> @Entity
>> @Table(name="CHILD")
>> public class Child {
>>  private Long id;
>>  private String name;
>> ..
>>
>> I can easily create, delete Parent or read the Child Set (values) but it 
>> is impossible to update Child Set.
>> The jsp page (see below) reinit the values Set, no record after updating!
>> Could u explain to me what's wrong?
>>
>> here are my code:
>>
>> @Entity
>> @Table(name="PARENT")
>> public class Parent {
>>  private Long id;
>>  private Set<Child> values = new HashSet<Child>();
>>  @Id
>>  @GeneratedValue
>>  @Column(name="PARENT_ID")
>>  public Long getId() {
>>   return id;
>>  }
>>  public void setId(Long id) {
>>   this.id = id;
>>  }
>>  @ManyToMany(fetch = FetchType.EAGER)
>>  @JoinTable(name = "PARENT_CHILD", joinColumns = { @JoinColumn(name = 
>> "PARENT_ID") }, inverseJoinColumns = { @JoinColumn(name = "CHILD_ID") })
>>  public Set<Child> getValues() {
>>   return values;
>>  }
>>  public void setValues(Set<Child> lst) {
>>   values = lst;
>>  }
>> }
>>
>> @Entity
>> @Table(name="CHILD")
>> public class Child {
>>  private Long id;
>>  private String name;
>>  @Id
>>  @GeneratedValue
>>  @Column(name="CHILD_ID")
>>  public Long getId() {
>>   return id;
>>  }
>>  public void setId(Long id) {
>>   this.id = id;
>>  }
>>  @Column(name="NAME")
>>  public String getName() {
>>   return name;
>>  }
>>  public void setName(String val) {
>>   name = val;
>>  }
>> }
>>
>> public interface ParentDAO {
>>  public void saveOrUpdateParent(Parent cl);
>>  public void saveParent(Parent cl);
>>  public List<Parent> listParent();
>>  public Parent listParentById(Long clId);
>>  public void deleteParent(Long clId);
>> }
>>
>> public class ParentDAOImpl implements ParentDAO {
>>  @SessionTarget
>>  Session session;
>>  @TransactionTarget
>>  Transaction transaction;
>>
>>  @Override
>>  public void saveOrUpdateParent(Parent cl) {
>>   try {
>>    session.saveOrUpdate(cl);
>>   } catch (Exception e) {
>>    transaction.rollback();
>>    e.printStackTrace();
>>   }
>>  }
>>
>>  @Override
>>  public void saveParent(Parent cl) {
>>   try {
>>    session.save(cl);
>>   } catch (Exception e) {
>>    transaction.rollback();
>>    e.printStackTrace();
>>   }
>>  }
>>
>>  @Override
>>  public void deleteParent(Long clId) {
>>   try {
>>    Parent cl = (Parent) session.get(Parent.class, clId);
>>    session.delete(cl);
>>   } catch (Exception e) {
>>    transaction.rollback();
>>    e.printStackTrace();
>>   }
>>  }
>>
>>  @SuppressWarnings("unchecked")
>>  @Override
>>  public List<Parent> listParent() {
>>   List<Parent> courses = null;
>>   try {
>>    courses = session.createQuery("from Parent").list();
>>    } catch (Exception e) {
>>    e.printStackTrace();
>>   }
>>   return courses;
>>  }
>>
>>  @Override
>>  public Parent listParentById(Long clId) {
>>   Parent cl = null;
>>   try {
>>    cl = (Parent) session.get(Parent.class, clId);
>>   } catch (Exception e) {
>>    e.printStackTrace();
>>   }
>>   return cl;
>>  }
>> }
>>
>> public class ParentAction  extends ActionSupport implements 
>> ModelDriven<Parent> {
>>
>>  private static final long serialVersionUID = -2662966220408285700L;
>>  private Parent cl = new Parent();
>>  private List<Parent> clList = new ArrayList<Parent>();
>>  private ParentDAO clDAO = new ParentDAOImpl();
>>
>>  @Override
>>  public Parent getModel() {
>>   return cl;
>>  }
>>
>>  public String saveOrUpdate()
>>  {
>>   clDAO.saveOrUpdateParent(cl);
>>   return SUCCESS;
>>  }
>>
>>  public String save()
>>  {
>>   clDAO.saveParent(cl);
>>   return SUCCESS;
>>  }
>>
>>  public String list()
>>  {
>>   clList = clDAO.listParent();
>>   return SUCCESS;
>>  }
>>
>>  public String delete()
>>  {
>>   HttpServletRequest request = (HttpServletRequest) 
>> ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
>>   clDAO.deleteParent(Long.parseLong(request.getParameter("id")));
>>   return SUCCESS;
>>  }
>>
>>  public String edit()
>>  {
>>   HttpServletRequest request = (HttpServletRequest) 
>> ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
>>   cl = clDAO.listParentById(Long.parseLong(request.getParameter("id")));
>>   return SUCCESS;
>>  }
>>
>>  public Parent getParent() {
>>   return cl;
>>  }
>>
>>  public void setParent(Parent cl) {
>>   this.cl = cl;
>>  }
>>
>>  public List<Parent> getParentList() {
>>   return clList;
>>  }
>>
>>  public void setParentList(List<Parent> clList) {
>>   this.clList = clList;
>>  }
>> }
>>
>> and finally the jsp page:
>>
>> <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
>>  pageEncoding="ISO-8859-1"%>
>> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
>> "http://www.w3.org/TR/html4/loose.dtd">
>> <%@taglib uri="/struts-tags" prefix="s"%>
>> <html>
>> <head>
>> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
>> <title>Parent Registration Page</title>
>> <s:head />
>> <style type="text/css">
>> @import url(style.css);
>> </style>
>> </head>
>> <body>
>> <s:form action="saveOrUpdateParent">
>>  <s:push value="parent">
>>   <s:hidden name="id" />
>>    <s:push value="values">
>>    <s:iterator id="p" value="values">
>>    <s:textfield label="Nom" name="values(%{id}).name" value="%{name}"/>
>>         </s:iterator>
>>   </s:push>
>>     <s:submit />
>>  </s:push>
>> </s:form>
>>
>> <s:if test="parentList.size() > 0">
>>  <div class="content">
>>  <table class="userTable" cellpadding="5px">
>>   <tr class="even">
>>    <th>Child(s)</th>
>>   </tr>
>>   <s:iterator value="parentList" status="userStatus">
>>    <tr
>>     class="<s:if test="#userStatus.odd == true 
>> ">odd</s:if><s:else>even</s:else>">
>>     <td><s:property value="values.size()" /></td>
>>     <s:iterator value="values">
>>      <td><s:property value="name" /></td>
>>     </s:iterator>
>>     <td><s:url id="editURL" action="editParent">
>>      <s:param name="id" value="%{id}"></s:param>
>>     </s:url> <s:a href="%{editURL}">Edit</s:a></td>
>>     <td><s:url id="deleteURL" action="deleteParent">
>>      <s:param name="id" value="%{id}"></s:param>
>>     </s:url> <s:a href="%{deleteURL}">Delete</s:a></td>
>>    </tr>
>>   </s:iterator>
>>  </table>
>>  </div>
>> </s:if>
>> </body>
>> </html>
>>
>
> -- 
> René Gielen
> IT-Neering.net
> Saarstrasse 100, 52062 Aachen, Germany
> Tel: +49-(0)241-4010770
> Fax: +49-(0)241-4010771
> Cel: +49-(0)163-2844164
> http://twitter.com/rgielen
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: CRUD with a OneToMany association under Struts 2 / Hibernate 3

Posted by bruno grandjean <br...@live.fr>.
Dear Adam,
 
I wrote a CascadeType.ALL in my @OneToMany annotation:
 

@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) 
@JoinTable(name = "PARENT_CHILD", joinColumns = { @JoinColumn(name = "PARENT_ID") }, inverseJoinColumns = { @JoinColumn(name = "CHILD_ID") }) 
public Set<Child> getValues() { 
return values;}
 
but I got unfortunately the same result.
 
Before running the application I execute the following hsqldb script:
 
insert into CHILD (CHILD_ID, NAME) values (1, 'Child1');
insert into CHILD (CHILD_ID, NAME) values (2, 'Child2');
insert into PARENT (PARENT_ID, NAME) values (1, 'Parent1');
insert into PARENT_CHILD (PARENT_ID, CHILD_ID) values (1, 1);
insert into PARENT_CHILD (PARENT_ID, CHILD_ID) values (1, 2);

After that, in the jsp page I have no pb to modify the fields:
 
1
Nom: Parent1
Id: 1
Nom: Child1
Id: 2
Nom: Child 2

s:form action="saveOrUpdateParent">

<s:push value="parent">
<s:hidden name="id" /> 
<s:textfield name="name" label="Nom" />
<s:push value="values">
<s:iterator id="p" value="values">
<s:textfield label="Id" name="#id" value="%{id}" />
<s:textfield label="Nom" name="#name" value="%{name}"/>
</s:iterator>
</s:push>



<s:submit />


</s:push>
</s:form>
 
I do not modify any keys which are auto-generated with Hibernate annotations:

 

@Id
@GeneratedValue


Iin debug mode just after clicking the submit button the size of Child Set is 0, I lost all my Child objects which is abnormal.
After running the session.saveOrUpdate(parent) method the hibernate trace is:
 


Hibernate: update PARENT set NAME=? where PARENT_ID=?
Hibernate: delete from PARENT_CHILD where PARENT_ID=?
 
So I am little bit lost because I do not know how to keep my Child Set alive..

 

All the best

 

Bruno


 
> From: apinder@hotmail.co.uk
> To: user@struts.apache.org
> Subject: RE: CRUD with a OneToMany association under Struts 2 / Hibernate 3
> Date: Thu, 1 Apr 2010 07:46:59 +0100
> 
> 
> 
> have you got the correct cascade setting on the parent object
> 
> i use the xml files for hibernate rather than the @ syntax in java classes and i can set cascade="all" which means when i save/update the parent the children are also saved or updated.
> 
> also remember that for hibernate to realise the children need to be updated rather than saved, the child object needs to have a primary key set otherwise it will want to do a save ... and if cascade was only update then nothing would be done with child objects.
> 
> turn on debugging of sql in hibernate config file to see if any sql to update/save children is actually being created.
> 
> 
> 
> ----------------------------------------
> > From: brgrandjean@live.fr
> > To: user@struts.apache.org
> > Subject: Re: CRUD with a OneToMany association under Struts 2 / Hibernate 3
> > Date: Wed, 31 Mar 2010 22:15:34 +0200
> >
> > Dear Rene,
> >
> > Thks a lot for replying to me because I am feeling a little bit alone with
> > my CRUD ;-). In fact I am trying to build a dynamic MetaCrud.
> > My pb is simple: in the same jsp page I would like to update a Parent object
> > and its Childs (values):
> >
> > 
> > 
> >> name="name" label="Nom" />
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> >
> > From an existing Parent object with many Childs objects I can easily modify
> > parent.name for instance but the collection of Child objects (values) is
> > always empty in the ParentAction (saveOrUpdate() method) after submitting.
> > However I can display each values[i].name in the jsp page with the correct
> > value.
> > So it is not an issue with Hibernate but with the jsp or ModelDriven
> > interface I don't know..Do you have any idea?
> > Basically I was not able to find a struts or spring documentation about CRUD
> > & association between two entities on the same jsp page.
> > best regards
> > bruno
> >
> >
> >
> > --------------------------------------------------
> > From: "Rene Gielen" 
> > Sent: Wednesday, March 31, 2010 7:12 PM
> > To: "Struts Users Mailing List" 
> > Subject: Re: CRUD with a OneToMany association under Struts 2 / Hibernate 3
> >
> >> I'm not sure if I understand what your actual question is, nor whether
> >> it is particularly Struts 2 related (rather than just Hibernate) - but
> >> you might want to have a look in the CRUD demo section of the Struts 2
> >> showcase application. Maybe you will also find this demo useful:
> >> http://github.com/rgielen/struts2crudevolutiondemo
> >>
> >> - René
> >>
> >> bruno grandjean schrieb:
> >>> Hi
> >>>
> >>> I am trying to implement a simple CRUD with a OneToMany association under
> >>> Struts 2 / Hibernate 3.
> >>> I have two entities Parent and Child:
> >>>
> >>> @Entity
> >>> @Table(name="PARENT")
> >>> public class Parent {
> >>> private Long id;
> >>> private Set values = new HashSet();
> >>> ..
> >>> @Entity
> >>> @Table(name="CHILD")
> >>> public class Child {
> >>> private Long id;
> >>> private String name;
> >>> ..
> >>>
> >>> I can easily create, delete Parent or read the Child Set (values) but it
> >>> is impossible to update Child Set.
> >>> The jsp page (see below) reinit the values Set, no record after updating!
> >>> Could u explain to me what's wrong?
> >>>
> >>> here are my code:
> >>>
> >>> @Entity
> >>> @Table(name="PARENT")
> >>> public class Parent {
> >>> private Long id;
> >>> private Set values = new HashSet();
> >>> @Id
> >>> @GeneratedValue
> >>> @Column(name="PARENT_ID")
> >>> public Long getId() {
> >>> return id;
> >>> }
> >>> public void setId(Long id) {
> >>> this.id = id;
> >>> }
> >>> @ManyToMany(fetch = FetchType.EAGER)
> >>> @JoinTable(name = "PARENT_CHILD", joinColumns = { @JoinColumn(name =
> >>> "PARENT_ID") }, inverseJoinColumns = { @JoinColumn(name = "CHILD_ID") })
> >>> public Set getValues() {
> >>> return values;
> >>> }
> >>> public void setValues(Set lst) {
> >>> values = lst;
> >>> }
> >>> }
> >>>
> >>> @Entity
> >>> @Table(name="CHILD")
> >>> public class Child {
> >>> private Long id;
> >>> private String name;
> >>> @Id
> >>> @GeneratedValue
> >>> @Column(name="CHILD_ID")
> >>> public Long getId() {
> >>> return id;
> >>> }
> >>> public void setId(Long id) {
> >>> this.id = id;
> >>> }
> >>> @Column(name="NAME")
> >>> public String getName() {
> >>> return name;
> >>> }
> >>> public void setName(String val) {
> >>> name = val;
> >>> }
> >>> }
> >>>
> >>> public interface ParentDAO {
> >>> public void saveOrUpdateParent(Parent cl);
> >>> public void saveParent(Parent cl);
> >>> public List listParent();
> >>> public Parent listParentById(Long clId);
> >>> public void deleteParent(Long clId);
> >>> }
> >>>
> >>> public class ParentDAOImpl implements ParentDAO {
> >>> @SessionTarget
> >>> Session session;
> >>> @TransactionTarget
> >>> Transaction transaction;
> >>>
> >>> @Override
> >>> public void saveOrUpdateParent(Parent cl) {
> >>> try {
> >>> session.saveOrUpdate(cl);
> >>> } catch (Exception e) {
> >>> transaction.rollback();
> >>> e.printStackTrace();
> >>> }
> >>> }
> >>>
> >>> @Override
> >>> public void saveParent(Parent cl) {
> >>> try {
> >>> session.save(cl);
> >>> } catch (Exception e) {
> >>> transaction.rollback();
> >>> e.printStackTrace();
> >>> }
> >>> }
> >>>
> >>> @Override
> >>> public void deleteParent(Long clId) {
> >>> try {
> >>> Parent cl = (Parent) session.get(Parent.class, clId);
> >>> session.delete(cl);
> >>> } catch (Exception e) {
> >>> transaction.rollback();
> >>> e.printStackTrace();
> >>> }
> >>> }
> >>>
> >>> @SuppressWarnings("unchecked")
> >>> @Override
> >>> public List listParent() {
> >>> List courses = null;
> >>> try {
> >>> courses = session.createQuery("from Parent").list();
> >>> } catch (Exception e) {
> >>> e.printStackTrace();
> >>> }
> >>> return courses;
> >>> }
> >>>
> >>> @Override
> >>> public Parent listParentById(Long clId) {
> >>> Parent cl = null;
> >>> try {
> >>> cl = (Parent) session.get(Parent.class, clId);
> >>> } catch (Exception e) {
> >>> e.printStackTrace();
> >>> }
> >>> return cl;
> >>> }
> >>> }
> >>>
> >>> public class ParentAction extends ActionSupport implements
> >>> ModelDriven {
> >>>
> >>> private static final long serialVersionUID = -2662966220408285700L;
> >>> private Parent cl = new Parent();
> >>> private List clList = new ArrayList();
> >>> private ParentDAO clDAO = new ParentDAOImpl();
> >>>
> >>> @Override
> >>> public Parent getModel() {
> >>> return cl;
> >>> }
> >>>
> >>> public String saveOrUpdate()
> >>> {
> >>> clDAO.saveOrUpdateParent(cl);
> >>> return SUCCESS;
> >>> }
> >>>
> >>> public String save()
> >>> {
> >>> clDAO.saveParent(cl);
> >>> return SUCCESS;
> >>> }
> >>>
> >>> public String list()
> >>> {
> >>> clList = clDAO.listParent();
> >>> return SUCCESS;
> >>> }
> >>>
> >>> public String delete()
> >>> {
> >>> HttpServletRequest request = (HttpServletRequest)
> >>> ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
> >>> clDAO.deleteParent(Long.parseLong(request.getParameter("id")));
> >>> return SUCCESS;
> >>> }
> >>>
> >>> public String edit()
> >>> {
> >>> HttpServletRequest request = (HttpServletRequest)
> >>> ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
> >>> cl = clDAO.listParentById(Long.parseLong(request.getParameter("id")));
> >>> return SUCCESS;
> >>> }
> >>>
> >>> public Parent getParent() {
> >>> return cl;
> >>> }
> >>>
> >>> public void setParent(Parent cl) {
> >>> this.cl = cl;
> >>> }
> >>>
> >>> public List getParentList() {
> >>> return clList;
> >>> }
> >>>
> >>> public void setParentList(List clList) {
> >>> this.clList = clList;
> >>> }
> >>> }
> >>>
> >>> and finally the jsp page:
> >>>
> >>> 
> >>>>>> "http://www.w3.org/TR/html4/loose.dtd">
> >>> 
> >>> 
> >>> 
> >>> 
> >>> 
> >>> 
> >>> 
> 
> 
> >>> 
> >>> 
> >>> 
> >>> 
> >>> 
> >>> 
> >>> 
> >>> 
> >>> 
> >>> 
> >>> 
> >>> 
> >>> 
> >>>
> >>> 
> >>> 
> 
> >>> 
> 
> >>> 
> 
> 
> >>> 
> Child(s)
> >>> 
> 
> >>> 
> >>>>>> class="oddeven">
> >>> 
> 
> 
> >>> 
> >>> 
> 
> >>> 
> >>> 
> 
> >>> 
> >>> Edit
> >>> 
> 
> >>> 
> >>> Delete
> >>> 
> 
> >>> 
> >>> 
> >>> 
> >>> 
> >>> 
> >>> 
> >>>
> >>
> >> --
> >> René Gielen
> >> IT-Neering.net
> >> Saarstrasse 100, 52062 Aachen, Germany
> >> Tel: +49-(0)241-4010770
> >> Fax: +49-(0)241-4010771
> >> Cel: +49-(0)163-2844164
> >> http://twitter.com/rgielen
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >> For additional commands, e-mail: user-help@struts.apache.org
> >>
> >>
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> > 
> _________________________________________________________________
> We want to hear all your funny, exciting and crazy Hotmail stories. Tell us now
> http://clk.atdmt.com/UKM/go/195013117/direct/01/
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 

 		 	   		  
_________________________________________________________________
Consultez gratuitement vos emails Orange, Gmail, Free, ... directement dans HOTMAIL !
http://www.windowslive.fr/hotmail/agregation/

RE: CRUD with a OneToMany association under Struts 2 / Hibernate 3

Posted by adam pinder <ap...@hotmail.co.uk>.
 
have you got the correct cascade setting on the parent object
 
i use the xml files for hibernate rather than the @ syntax in java classes and i can set cascade="all" which means when i save/update the parent the children are also saved or updated.
 
also remember that for hibernate to realise the children need to be updated rather than saved, the child object needs to have a primary key set otherwise it will want to do a save ... and if cascade was only update then nothing would be done with child objects.
 
turn on debugging of sql in hibernate config file to see if any sql to update/save children is actually being created.
 


----------------------------------------
> From: brgrandjean@live.fr
> To: user@struts.apache.org
> Subject: Re: CRUD with a OneToMany association under Struts 2 / Hibernate 3
> Date: Wed, 31 Mar 2010 22:15:34 +0200
>
> Dear Rene,
>
> Thks a lot for replying to me because I am feeling a little bit alone with
> my CRUD ;-). In fact I am trying to build a dynamic MetaCrud.
> My pb is simple: in the same jsp page I would like to update a Parent object
> and its Childs (values):
>
> 
> 
>> name="name" label="Nom" />
> 
> 
> 
> 
> 
> 
> 
> 
>
> From an existing Parent object with many Childs objects I can easily modify
> parent.name for instance but the collection of Child objects (values) is
> always empty in the ParentAction (saveOrUpdate() method) after submitting.
> However I can display each values[i].name in the jsp page with the correct
> value.
> So it is not an issue with Hibernate but with the jsp or ModelDriven
> interface I don't know..Do you have any idea?
> Basically I was not able to find a struts or spring documentation about CRUD
> & association between two entities on the same jsp page.
> best regards
> bruno
>
>
>
> --------------------------------------------------
> From: "Rene Gielen" 
> Sent: Wednesday, March 31, 2010 7:12 PM
> To: "Struts Users Mailing List" 
> Subject: Re: CRUD with a OneToMany association under Struts 2 / Hibernate 3
>
>> I'm not sure if I understand what your actual question is, nor whether
>> it is particularly Struts 2 related (rather than just Hibernate) - but
>> you might want to have a look in the CRUD demo section of the Struts 2
>> showcase application. Maybe you will also find this demo useful:
>> http://github.com/rgielen/struts2crudevolutiondemo
>>
>> - René
>>
>> bruno grandjean schrieb:
>>> Hi
>>>
>>> I am trying to implement a simple CRUD with a OneToMany association under
>>> Struts 2 / Hibernate 3.
>>> I have two entities Parent and Child:
>>>
>>> @Entity
>>> @Table(name="PARENT")
>>> public class Parent {
>>> private Long id;
>>> private Set values = new HashSet();
>>> ..
>>> @Entity
>>> @Table(name="CHILD")
>>> public class Child {
>>> private Long id;
>>> private String name;
>>> ..
>>>
>>> I can easily create, delete Parent or read the Child Set (values) but it
>>> is impossible to update Child Set.
>>> The jsp page (see below) reinit the values Set, no record after updating!
>>> Could u explain to me what's wrong?
>>>
>>> here are my code:
>>>
>>> @Entity
>>> @Table(name="PARENT")
>>> public class Parent {
>>> private Long id;
>>> private Set values = new HashSet();
>>> @Id
>>> @GeneratedValue
>>> @Column(name="PARENT_ID")
>>> public Long getId() {
>>> return id;
>>> }
>>> public void setId(Long id) {
>>> this.id = id;
>>> }
>>> @ManyToMany(fetch = FetchType.EAGER)
>>> @JoinTable(name = "PARENT_CHILD", joinColumns = { @JoinColumn(name =
>>> "PARENT_ID") }, inverseJoinColumns = { @JoinColumn(name = "CHILD_ID") })
>>> public Set getValues() {
>>> return values;
>>> }
>>> public void setValues(Set lst) {
>>> values = lst;
>>> }
>>> }
>>>
>>> @Entity
>>> @Table(name="CHILD")
>>> public class Child {
>>> private Long id;
>>> private String name;
>>> @Id
>>> @GeneratedValue
>>> @Column(name="CHILD_ID")
>>> public Long getId() {
>>> return id;
>>> }
>>> public void setId(Long id) {
>>> this.id = id;
>>> }
>>> @Column(name="NAME")
>>> public String getName() {
>>> return name;
>>> }
>>> public void setName(String val) {
>>> name = val;
>>> }
>>> }
>>>
>>> public interface ParentDAO {
>>> public void saveOrUpdateParent(Parent cl);
>>> public void saveParent(Parent cl);
>>> public List listParent();
>>> public Parent listParentById(Long clId);
>>> public void deleteParent(Long clId);
>>> }
>>>
>>> public class ParentDAOImpl implements ParentDAO {
>>> @SessionTarget
>>> Session session;
>>> @TransactionTarget
>>> Transaction transaction;
>>>
>>> @Override
>>> public void saveOrUpdateParent(Parent cl) {
>>> try {
>>> session.saveOrUpdate(cl);
>>> } catch (Exception e) {
>>> transaction.rollback();
>>> e.printStackTrace();
>>> }
>>> }
>>>
>>> @Override
>>> public void saveParent(Parent cl) {
>>> try {
>>> session.save(cl);
>>> } catch (Exception e) {
>>> transaction.rollback();
>>> e.printStackTrace();
>>> }
>>> }
>>>
>>> @Override
>>> public void deleteParent(Long clId) {
>>> try {
>>> Parent cl = (Parent) session.get(Parent.class, clId);
>>> session.delete(cl);
>>> } catch (Exception e) {
>>> transaction.rollback();
>>> e.printStackTrace();
>>> }
>>> }
>>>
>>> @SuppressWarnings("unchecked")
>>> @Override
>>> public List listParent() {
>>> List courses = null;
>>> try {
>>> courses = session.createQuery("from Parent").list();
>>> } catch (Exception e) {
>>> e.printStackTrace();
>>> }
>>> return courses;
>>> }
>>>
>>> @Override
>>> public Parent listParentById(Long clId) {
>>> Parent cl = null;
>>> try {
>>> cl = (Parent) session.get(Parent.class, clId);
>>> } catch (Exception e) {
>>> e.printStackTrace();
>>> }
>>> return cl;
>>> }
>>> }
>>>
>>> public class ParentAction extends ActionSupport implements
>>> ModelDriven {
>>>
>>> private static final long serialVersionUID = -2662966220408285700L;
>>> private Parent cl = new Parent();
>>> private List clList = new ArrayList();
>>> private ParentDAO clDAO = new ParentDAOImpl();
>>>
>>> @Override
>>> public Parent getModel() {
>>> return cl;
>>> }
>>>
>>> public String saveOrUpdate()
>>> {
>>> clDAO.saveOrUpdateParent(cl);
>>> return SUCCESS;
>>> }
>>>
>>> public String save()
>>> {
>>> clDAO.saveParent(cl);
>>> return SUCCESS;
>>> }
>>>
>>> public String list()
>>> {
>>> clList = clDAO.listParent();
>>> return SUCCESS;
>>> }
>>>
>>> public String delete()
>>> {
>>> HttpServletRequest request = (HttpServletRequest)
>>> ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
>>> clDAO.deleteParent(Long.parseLong(request.getParameter("id")));
>>> return SUCCESS;
>>> }
>>>
>>> public String edit()
>>> {
>>> HttpServletRequest request = (HttpServletRequest)
>>> ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
>>> cl = clDAO.listParentById(Long.parseLong(request.getParameter("id")));
>>> return SUCCESS;
>>> }
>>>
>>> public Parent getParent() {
>>> return cl;
>>> }
>>>
>>> public void setParent(Parent cl) {
>>> this.cl = cl;
>>> }
>>>
>>> public List getParentList() {
>>> return clList;
>>> }
>>>
>>> public void setParentList(List clList) {
>>> this.clList = clList;
>>> }
>>> }
>>>
>>> and finally the jsp page:
>>>
>>> 
>>>>>> "http://www.w3.org/TR/html4/loose.dtd">
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 


>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>>
>>> 
>>> 

>>> 

>>> 


>>> 
Child(s)
>>> 

>>> 
>>>>>> class="oddeven">
>>> 


>>> 
>>> 

>>> 
>>> 

>>> 
>>> Edit
>>> 

>>> 
>>> Delete
>>> 

>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>>
>>
>> --
>> René Gielen
>> IT-Neering.net
>> Saarstrasse 100, 52062 Aachen, Germany
>> Tel: +49-(0)241-4010770
>> Fax: +49-(0)241-4010771
>> Cel: +49-(0)163-2844164
>> http://twitter.com/rgielen
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 		 	   		  
_________________________________________________________________
We want to hear all your funny, exciting and crazy Hotmail stories. Tell us now
http://clk.atdmt.com/UKM/go/195013117/direct/01/
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: CRUD with a OneToMany association under Struts 2 / Hibernate 3

Posted by bruno grandjean <br...@live.fr>.
In all cases, thks a lot for helping me because I was absolutely unable to 
find a solution.
I will try to test what u suggest but I must admit that I am a little bit 
frustrated and disappointed with the ModelDriven interface.
 I am also trying to do the same thing with Spring, I hope to be more lucky 
;-)
bruno


--------------------------------------------------
From: "adam pinder" <ap...@hotmail.co.uk>
Sent: Thursday, April 01, 2010 6:19 PM
To: <us...@struts.apache.org>
Subject: RE: CRUD with a OneToMany association under Struts 2 / Hibernate 3

>
>
> so it looks like your issue is more to do with the child values not being 
> set by Struts
>
> there have been a few postings about using the [] notation on field names 
> to get struts to assign the values properly.
>
> in struts1 i found it worked fine, however in struts2 i've not really seen 
> it working... in some of my actions i have actually added a method which 
> gets the parameter values off the request and populates the objects 
> myself..
>
> e.g. look for parameter names starting parent.values and use the parameter 
> name/value to construct the correct call to set the object.
>
> seems unnecessary as struts2 should handle it, but as i say i couldn't get 
> it to do it with arraylists i was using.
>
>
>
> ----------------------------------------
>> From: brgrandjean@live.fr
>> To: user@struts.apache.org
>> Subject: RE: CRUD with a OneToMany association under Struts 2 / Hibernate 
>> 3
>> Date: Thu, 1 Apr 2010 15:16:36 +0200
>>
>>
>> Thks a lot Adam it is now more concise:
>>
>>
>>
>> Setting params
>> Setting params id => [ 1 ]
>> Setting params id => [ 1 ] method:saveOrUpdate => [ Submit ] name => [ 
>> Parent1 ] parent.values[0].id => [ 2 ] parent.values[0].name => [ 
>> Child2 ] parent.values[1].id => [ 1 ] parent.values[1].name => [ Child1 ]
>>
>>
>>
>> Error setting value
>> ognl.NoSuchPropertyException: java.util.HashSet.0
>> at ognl.SetPropertyAccessor.getProperty(SetPropertyAccessor.java:67)
>> at 
>> com.opensymphony.xwork2.ognl.accessor.XWorkCollectionPropertyAccessor.getProperty(XWorkCollectionPropertyAccessor.java:80)
>> at java.lang.Thread.run(Unknown Source)
>> ..
>> Error setting value
>> ognl.NoSuchPropertyException: java.util.HashSet.0
>> at ognl.SetPropertyAccessor.getProperty(SetPropertyAccessor.java:67)
>> ..
>> Error setting value
>> ognl.NoSuchPropertyException: java.util.HashSet.1
>> at ognl.SetPropertyAccessor.getProperty(SetPropertyAccessor.java:67)
>> at 
>> com.opensymphony.xwork2.ognl.accessor.XWorkCollectionPropertyAccessor.getProperty(XWorkCollectionPropertyAccessor.java:80)
>> ..
>> Error setting value
>> ognl.NoSuchPropertyException: java.util.HashSet.1
>> at ognl.SetPropertyAccessor.getProperty(SetPropertyAccessor.java:67)
>> at 
>> com.opensymphony.xwork2.ognl.accessor.XWorkCollectionPropertyAccessor.getProperty(XWorkCollectionPropertyAccessor.java:80)
>> at ognl.OgnlRuntime.getProperty(OgnlRuntime.java:1643)
>> ..
>>
>> Setting params
>>
>> Do u see something wrong??
>>
>>
>>
>>
>>> From: apinder@hotmail.co.uk
>>> To: user@struts.apache.org
>>> Subject: RE: CRUD with a OneToMany association under Struts 2 / 
>>> Hibernate 3
>>> Date: Thu, 1 Apr 2010 13:54:58 +0100
>>>
>>>
>>>
>>> set the rootlogger to warn
>>>
>>> log4j.rootLogger=warn, stdout
>>>
>>> rather than debug
>>>
>>> you should only get a parameterinterceptor log entry every time you post 
>>> something to the server
>>>
>>> ----------------------------------------
>>>> From: brgrandjean@live.fr
>>>> To: user@struts.apache.org
>>>> Subject: RE: CRUD with a OneToMany association under Struts 2 / 
>>>> Hibernate 3
>>>> Date: Thu, 1 Apr 2010 14:51:40 +0200
>>>>
>>>>
>>>> thks adam but I got now thousand & thousand of lines
>>>>
>>>> I am afraid that I won't be able to read its before the end of the 
>>>> world in 2012..
>>>>
>>>>
>>>>
>>>> I saw very quicky an exception at the beginning..
>>>>
>>>> How can I limit this huge quantity of lines?
>>>>
>>>>
>>>>
>>>> here is my log4j.properties file:
>>>>
>>>>
>>>>
>>>> log4j.appender.stdout=org.apache.log4j.ConsoleAppender
>>>> log4j.appender.stdout.Target=System.out
>>>> log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
>>>> log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p 
>>>> %c{1}:%L - %m%n
>>>> log4j.rootLogger=debug, stdout
>>>> log4j.logger.com.opensymphony.xwork2.interceptor.ParametersInterceptor=debug
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>> From: apinder@hotmail.co.uk
>>>>> To: user@struts.apache.org
>>>>> Subject: RE: CRUD with a OneToMany association under Struts 2 / 
>>>>> Hibernate 3
>>>>> Date: Thu, 1 Apr 2010 12:57:39 +0100
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> in log4j.properties file (same location as struts.xml and hibernate 
>>>>> config files)
>>>>>
>>>>> add
>>>>>
>>>>> log4j.logger.com.opensymphony.xwork2.interceptor.ParametersInterceptor=debug
>>>>>
>>>>> this will output param name/value pairs being posted from your page.
>>>>>
>>>>>
>>>>>
>>>>> ----------------------------------------
>>>>>> From: brgrandjean@live.fr
>>>>>> To: user@struts.apache.org
>>>>>> Subject: RE: CRUD with a OneToMany association under Struts 2 / 
>>>>>> Hibernate 3
>>>>>> Date: Thu, 1 Apr 2010 13:54:33 +0200
>>>>>>
>>>>>>
>>>>>> Dear Adam,
>>>>>>
>>>>>>
>>>>>>
>>>>>> I just added a public Child getValues(int idx) in the Parent class 
>>>>>> definition but it is never called.
>>>>>>
>>>>>>
>>>>>>
>>>>>> Could u explain to me where and how can I turn on the 
>>>>>> parameterinterceptor logging? In the struts.xml file?
>>>>>>
>>>>>>
>>>>>>
>>>>>> thks a lot
>>>>>>
>>>>>>
>>>>>> bruno
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>> From: apinder@hotmail.co.uk
>>>>>>> To: user@struts.apache.org
>>>>>>> Subject: RE: CRUD with a OneToMany association under Struts 2 / 
>>>>>>> Hibernate 3
>>>>>>> Date: Thu, 1 Apr 2010 12:18:48 +0100
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> turn on the parameterinterceptor logging and make sure as mentioned 
>>>>>>> that
>>>>>>>
>>>>>>> 1) the values you expect for each child are being sent to the server 
>>>>>>> (id and name)
>>>>>>> 2) the parameter names are correct for setting each child
>>>>>>>
>>>>>>> i had some issues getting lists of items to be updated by form 
>>>>>>> submission alone.
>>>>>>>
>>>>>>> for example does your parent object have a getValues method taking 
>>>>>>> an index value
>>>>>>>
>>>>>>> getParent().getValues(1).setId(1)
>>>>>>> getParent().getValues(1).setName("bob")
>>>>>>>
>>>>>>> would be called by parameterinterceptor
>>>>>>>
>>>>>>>
>>>>>>> ----------------------------------------
>>>>>>>> From: brgrandjean@live.fr
>>>>>>>> To: user@struts.apache.org
>>>>>>>> Subject: RE: CRUD with a OneToMany association under Struts 2 / 
>>>>>>>> Hibernate 3
>>>>>>>> Date: Thu, 1 Apr 2010 12:16:09 +0200
>>>>>>>>
>>>>>>>>
>>>>>>>> Dear René
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> I changed my jsp page so as to integrate the following block:
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> which generates the following html code:
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> I can display my complete Child Set but I got the same result after 
>>>>>>>> updating: my Child Set is empty.
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> Is that necessary to modify my ParentAction as well? If yes what to 
>>>>>>>> do?
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> public class ParentAction extends ActionSupport implements 
>>>>>>>> ModelDriven {
>>>>>>>>
>>>>>>>> private static final long serialVersionUID = -2662966220408285700L;
>>>>>>>> private Parent cl = new Parent();
>>>>>>>> private List clList = new ArrayList();
>>>>>>>> private ParentDAO clDAO = new ParentDAOImpl();
>>>>>>>>
>>>>>>>> @Override
>>>>>>>> public Parent getModel() {
>>>>>>>> return cl;
>>>>>>>> }
>>>>>>>>
>>>>>>>> public String saveOrUpdate()
>>>>>>>> { // cl.values is empty here!!
>>>>>>>> clDAO.saveOrUpdateParent(cl);
>>>>>>>> return SUCCESS;
>>>>>>>> }
>>>>>>>>
>>>>>>>> public String save()
>>>>>>>> {
>>>>>>>> clDAO.saveParent(cl);
>>>>>>>> return SUCCESS;
>>>>>>>> }
>>>>>>>>
>>>>>>>> public String list()
>>>>>>>> {
>>>>>>>> clList = clDAO.listParent();
>>>>>>>> return SUCCESS;
>>>>>>>> }
>>>>>>>>
>>>>>>>> public String delete()
>>>>>>>> {
>>>>>>>> HttpServletRequest request = (HttpServletRequest) 
>>>>>>>> ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
>>>>>>>> clDAO.deleteParent(Long.parseLong(request.getParameter("id")));
>>>>>>>> return SUCCESS;
>>>>>>>> }
>>>>>>>>
>>>>>>>> public String edit()
>>>>>>>> { // cl.values contains some valid Child elements here!!
>>>>>>>> HttpServletRequest request = (HttpServletRequest) 
>>>>>>>> ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
>>>>>>>> cl = 
>>>>>>>> clDAO.listParentById(Long.parseLong(request.getParameter("id")));
>>>>>>>> }
>>>>>>>> return SUCCESS;
>>>>>>>> }
>>>>>>>>
>>>>>>>> public Parent getParent() {
>>>>>>>> return cl;
>>>>>>>> }
>>>>>>>>
>>>>>>>> public void setParent(Parent cl) {
>>>>>>>> this.cl = cl;
>>>>>>>> }
>>>>>>>>
>>>>>>>> public List getParentList() {
>>>>>>>> return clList;
>>>>>>>> }
>>>>>>>>
>>>>>>>> public void setParentList(List clList) {
>>>>>>>> this.clList = clList;
>>>>>>>> }
>>>>>>>> }
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>> Date: Thu, 1 Apr 2010 11:30:23 +0200
>>>>>>>>> From: gielen@it-neering.net
>>>>>>>>> To: user@struts.apache.org
>>>>>>>>> Subject: Re: CRUD with a OneToMany association under Struts 2 / 
>>>>>>>>> Hibernate 3
>>>>>>>>>
>>>>>>>>> Given the model you presented in the first post, your problem 
>>>>>>>>> seems to
>>>>>>>>> be that the posted values have not the correct name for the 
>>>>>>>>> children's
>>>>>>>>> form fields. The parameters names you would need are
>>>>>>>>>
>>>>>>>>> id
>>>>>>>>> name
>>>>>>>>> values[0].id
>>>>>>>>> values[0].name
>>>>>>>>> values[1].id
>>>>>>>>> values[2].name
>>>>>>>>> ...
>>>>>>>>>
>>>>>>>>> for the parameters interceptor to work properly when applying the 
>>>>>>>>> posted
>>>>>>>>> values.
>>>>>>>>>
>>>>>>>>> See here for more details:
>>>>>>>>> http://struts.apache.org/2.1.8/docs/tabular-inputs.html
>>>>>>>>>
>>>>>>>>> - René
>>>>>>>>>
>>>>>>>>> bruno grandjean schrieb:
>>>>>>>>>> Dear Rene,
>>>>>>>>>>
>>>>>>>>>> Thks a lot for replying to me because I am feeling a little bit 
>>>>>>>>>> alone with
>>>>>>>>>> my CRUD ;-). In fact I am trying to build a dynamic MetaCrud.
>>>>>>>>>> My pb is simple: in the same jsp page I would like to update a 
>>>>>>>>>> Parent
>>>>>>>>>> object
>>>>>>>>>> and its Childs (values):
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>>>> name="name" label="Nom" />
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> From an existing Parent object with many Childs objects I can 
>>>>>>>>>> easily modify
>>>>>>>>>> parent.name for instance but the collection of Child objects 
>>>>>>>>>> (values) is
>>>>>>>>>> always empty in the ParentAction (saveOrUpdate() method) after 
>>>>>>>>>> submitting.
>>>>>>>>>> However I can display each values[i].name in the jsp page with 
>>>>>>>>>> the correct
>>>>>>>>>> value.
>>>>>>>>>> So it is not an issue with Hibernate but with the jsp or 
>>>>>>>>>> ModelDriven
>>>>>>>>>> interface I don't know..Do you have any idea?
>>>>>>>>>> Basically I was not able to find a struts or spring documentation 
>>>>>>>>>> about
>>>>>>>>>> CRUD
>>>>>>>>>> & association between two entities on the same jsp page.
>>>>>>>>>> best regards
>>>>>>>>>> bruno
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> --------------------------------------------------
>>>>>>>>>> From: "Rene Gielen"
>>>>>>>>>> Sent: Wednesday, March 31, 2010 7:12 PM
>>>>>>>>>> To: "Struts Users Mailing List"
>>>>>>>>>> Subject: Re: CRUD with a OneToMany association under Struts 2 / 
>>>>>>>>>> Hibernate 3
>>>>>>>>>>
>>>>>>>>>>> I'm not sure if I understand what your actual question is, nor 
>>>>>>>>>>> whether
>>>>>>>>>>> it is particularly Struts 2 related (rather than just 
>>>>>>>>>>> Hibernate) - but
>>>>>>>>>>> you might want to have a look in the CRUD demo section of the 
>>>>>>>>>>> Struts 2
>>>>>>>>>>> showcase application. Maybe you will also find this demo useful:
>>>>>>>>>>> http://github.com/rgielen/struts2crudevolutiondemo
>>>>>>>>>>>
>>>>>>>>>>> - René
>>>>>>>>>>>
>>>>>>>>>>> bruno grandjean schrieb:
>>>>>>>>>>>> Hi
>>>>>>>>>>>>
>>>>>>>>>>>> I am trying to implement a simple CRUD with a OneToMany 
>>>>>>>>>>>> association
>>>>>>>>>>>> under Struts 2 / Hibernate 3.
>>>>>>>>>>>> I have two entities Parent and Child:
>>>>>>>>>>>>
>>>>>>>>>>>> @Entity
>>>>>>>>>>>> @Table(name="PARENT")
>>>>>>>>>>>> public class Parent {
>>>>>>>>>>>> private Long id;
>>>>>>>>>>>> private Set values = new HashSet();
>>>>>>>>>>>> ..
>>>>>>>>>>>> @Entity
>>>>>>>>>>>> @Table(name="CHILD")
>>>>>>>>>>>> public class Child {
>>>>>>>>>>>> private Long id;
>>>>>>>>>>>> private String name;
>>>>>>>>>>>> ..
>>>>>>>>>>>>
>>>>>>>>>>>> I can easily create, delete Parent or read the Child Set 
>>>>>>>>>>>> (values) but
>>>>>>>>>>>> it is impossible to update Child Set.
>>>>>>>>>>>> The jsp page (see below) reinit the values Set, no record after
>>>>>>>>>>>> updating!
>>>>>>>>>>>> Could u explain to me what's wrong?
>>>>>>>>>>>>
>>>>>>>>>>>> here are my code:
>>>>>>>>>>>>
>>>>>>>>>>>> @Entity
>>>>>>>>>>>> @Table(name="PARENT")
>>>>>>>>>>>> public class Parent {
>>>>>>>>>>>> private Long id;
>>>>>>>>>>>> private Set values = new HashSet();
>>>>>>>>>>>> @Id
>>>>>>>>>>>> @GeneratedValue
>>>>>>>>>>>> @Column(name="PARENT_ID")
>>>>>>>>>>>> public Long getId() {
>>>>>>>>>>>> return id;
>>>>>>>>>>>> }
>>>>>>>>>>>> public void setId(Long id) {
>>>>>>>>>>>> this.id = id;
>>>>>>>>>>>> }
>>>>>>>>>>>> @ManyToMany(fetch = FetchType.EAGER)
>>>>>>>>>>>> @JoinTable(name = "PARENT_CHILD", joinColumns = { 
>>>>>>>>>>>> @JoinColumn(name =
>>>>>>>>>>>> "PARENT_ID") }, inverseJoinColumns = { @JoinColumn(name = 
>>>>>>>>>>>> "CHILD_ID") })
>>>>>>>>>>>> public Set getValues() {
>>>>>>>>>>>> return values;
>>>>>>>>>>>> }
>>>>>>>>>>>> public void setValues(Set lst) {
>>>>>>>>>>>> values = lst;
>>>>>>>>>>>> }
>>>>>>>>>>>> }
>>>>>>>>>>>>
>>>>>>>>>>>> @Entity
>>>>>>>>>>>> @Table(name="CHILD")
>>>>>>>>>>>> public class Child {
>>>>>>>>>>>> private Long id;
>>>>>>>>>>>> private String name;
>>>>>>>>>>>> @Id
>>>>>>>>>>>> @GeneratedValue
>>>>>>>>>>>> @Column(name="CHILD_ID")
>>>>>>>>>>>> public Long getId() {
>>>>>>>>>>>> return id;
>>>>>>>>>>>> }
>>>>>>>>>>>> public void setId(Long id) {
>>>>>>>>>>>> this.id = id;
>>>>>>>>>>>> }
>>>>>>>>>>>> @Column(name="NAME")
>>>>>>>>>>>> public String getName() {
>>>>>>>>>>>> return name;
>>>>>>>>>>>> }
>>>>>>>>>>>> public void setName(String val) {
>>>>>>>>>>>> name = val;
>>>>>>>>>>>> }
>>>>>>>>>>>> }
>>>>>>>>>>>>
>>>>>>>>>>>> public interface ParentDAO {
>>>>>>>>>>>> public void saveOrUpdateParent(Parent cl);
>>>>>>>>>>>> public void saveParent(Parent cl);
>>>>>>>>>>>> public List listParent();
>>>>>>>>>>>> public Parent listParentById(Long clId);
>>>>>>>>>>>> public void deleteParent(Long clId);
>>>>>>>>>>>> }
>>>>>>>>>>>>
>>>>>>>>>>>> public class ParentDAOImpl implements ParentDAO {
>>>>>>>>>>>> @SessionTarget
>>>>>>>>>>>> Session session;
>>>>>>>>>>>> @TransactionTarget
>>>>>>>>>>>> Transaction transaction;
>>>>>>>>>>>>
>>>>>>>>>>>> @Override
>>>>>>>>>>>> public void saveOrUpdateParent(Parent cl) {
>>>>>>>>>>>> try {
>>>>>>>>>>>> session.saveOrUpdate(cl);
>>>>>>>>>>>> } catch (Exception e) {
>>>>>>>>>>>> transaction.rollback();
>>>>>>>>>>>> e.printStackTrace();
>>>>>>>>>>>> }
>>>>>>>>>>>> }
>>>>>>>>>>>>
>>>>>>>>>>>> @Override
>>>>>>>>>>>> public void saveParent(Parent cl) {
>>>>>>>>>>>> try {
>>>>>>>>>>>> session.save(cl);
>>>>>>>>>>>> } catch (Exception e) {
>>>>>>>>>>>> transaction.rollback();
>>>>>>>>>>>> e.printStackTrace();
>>>>>>>>>>>> }
>>>>>>>>>>>> }
>>>>>>>>>>>>
>>>>>>>>>>>> @Override
>>>>>>>>>>>> public void deleteParent(Long clId) {
>>>>>>>>>>>> try {
>>>>>>>>>>>> Parent cl = (Parent) session.get(Parent.class, clId);
>>>>>>>>>>>> session.delete(cl);
>>>>>>>>>>>> } catch (Exception e) {
>>>>>>>>>>>> transaction.rollback();
>>>>>>>>>>>> e.printStackTrace();
>>>>>>>>>>>> }
>>>>>>>>>>>> }
>>>>>>>>>>>>
>>>>>>>>>>>> @SuppressWarnings("unchecked")
>>>>>>>>>>>> @Override
>>>>>>>>>>>> public List listParent() {
>>>>>>>>>>>> List courses = null;
>>>>>>>>>>>> try {
>>>>>>>>>>>> courses = session.createQuery("from Parent").list();
>>>>>>>>>>>> } catch (Exception e) {
>>>>>>>>>>>> e.printStackTrace();
>>>>>>>>>>>> }
>>>>>>>>>>>> return courses;
>>>>>>>>>>>> }
>>>>>>>>>>>>
>>>>>>>>>>>> @Override
>>>>>>>>>>>> public Parent listParentById(Long clId) {
>>>>>>>>>>>> Parent cl = null;
>>>>>>>>>>>> try {
>>>>>>>>>>>> cl = (Parent) session.get(Parent.class, clId);
>>>>>>>>>>>> } catch (Exception e) {
>>>>>>>>>>>> e.printStackTrace();
>>>>>>>>>>>> }
>>>>>>>>>>>> return cl;
>>>>>>>>>>>> }
>>>>>>>>>>>> }
>>>>>>>>>>>>
>>>>>>>>>>>> public class ParentAction extends ActionSupport implements
>>>>>>>>>>>> ModelDriven {
>>>>>>>>>>>>
>>>>>>>>>>>> private static final long serialVersionUID 
>>>>>>>>>>>> = -2662966220408285700L;
>>>>>>>>>>>> private Parent cl = new Parent();
>>>>>>>>>>>> private List clList = new ArrayList();
>>>>>>>>>>>> private ParentDAO clDAO = new ParentDAOImpl();
>>>>>>>>>>>>
>>>>>>>>>>>> @Override
>>>>>>>>>>>> public Parent getModel() {
>>>>>>>>>>>> return cl;
>>>>>>>>>>>> }
>>>>>>>>>>>>
>>>>>>>>>>>> public String saveOrUpdate()
>>>>>>>>>>>> {
>>>>>>>>>>>> clDAO.saveOrUpdateParent(cl);
>>>>>>>>>>>> return SUCCESS;
>>>>>>>>>>>> }
>>>>>>>>>>>>
>>>>>>>>>>>> public String save()
>>>>>>>>>>>> {
>>>>>>>>>>>> clDAO.saveParent(cl);
>>>>>>>>>>>> return SUCCESS;
>>>>>>>>>>>> }
>>>>>>>>>>>>
>>>>>>>>>>>> public String list()
>>>>>>>>>>>> {
>>>>>>>>>>>> clList = clDAO.listParent();
>>>>>>>>>>>> return SUCCESS;
>>>>>>>>>>>> }
>>>>>>>>>>>>
>>>>>>>>>>>> public String delete()
>>>>>>>>>>>> {
>>>>>>>>>>>> HttpServletRequest request = (HttpServletRequest)
>>>>>>>>>>>> ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
>>>>>>>>>>>> clDAO.deleteParent(Long.parseLong(request.getParameter("id")));
>>>>>>>>>>>> return SUCCESS;
>>>>>>>>>>>> }
>>>>>>>>>>>>
>>>>>>>>>>>> public String edit()
>>>>>>>>>>>> {
>>>>>>>>>>>> HttpServletRequest request = (HttpServletRequest)
>>>>>>>>>>>> ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
>>>>>>>>>>>> cl = 
>>>>>>>>>>>> clDAO.listParentById(Long.parseLong(request.getParameter("id")));
>>>>>>>>>>>> return SUCCESS;
>>>>>>>>>>>> }
>>>>>>>>>>>>
>>>>>>>>>>>> public Parent getParent() {
>>>>>>>>>>>> return cl;
>>>>>>>>>>>> }
>>>>>>>>>>>>
>>>>>>>>>>>> public void setParent(Parent cl) {
>>>>>>>>>>>> this.cl = cl;
>>>>>>>>>>>> }
>>>>>>>>>>>>
>>>>>>>>>>>> public List getParentList() {
>>>>>>>>>>>> return clList;
>>>>>>>>>>>> }
>>>>>>>>>>>>
>>>>>>>>>>>> public void setParentList(List clList) {
>>>>>>>>>>>> this.clList = clList;
>>>>>>>>>>>> }
>>>>>>>>>>>> }
>>>>>>>>>>>>
>>>>>>>>>>>> and finally the jsp page:
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> "http://www.w3.org/TR/html4/loose.dtd">
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>
>>>>>>>>>>>>
>>>>>>>
>>>>>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>>>>>>
>>>>>>> Child(s)
>>>>>>>>>>>>
>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> class="oddeven">
>>>>>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>> Edit
>>>>>>>>>>>>
>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>> Delete
>>>>>>>>>>>>
>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> --
>>>>>>>>>>> René Gielen
>>>>>>>>>>> IT-Neering.net
>>>>>>>>>>> Saarstrasse 100, 52062 Aachen, Germany
>>>>>>>>>>> Tel: +49-(0)241-4010770
>>>>>>>>>>> Fax: +49-(0)241-4010771
>>>>>>>>>>> Cel: +49-(0)163-2844164
>>>>>>>>>>> http://twitter.com/rgielen
>>>>>>>>>>>
>>>>>>>>>>> ---------------------------------------------------------------------
>>>>>>>>>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>>>>>>>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> ---------------------------------------------------------------------
>>>>>>>>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>>>>>>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>> --
>>>>>>>>> René Gielen
>>>>>>>>> IT-Neering.net
>>>>>>>>> Saarstrasse 100, 52062 Aachen, Germany
>>>>>>>>> Tel: +49-(0)241-4010770
>>>>>>>>> Fax: +49-(0)241-4010771
>>>>>>>>> Cel: +49-(0)163-2844164
>>>>>>>>> http://twitter.com/rgielen
>>>>>>>>>
>>>>>>>>> ---------------------------------------------------------------------
>>>>>>>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>>>>>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>>>>>>
>>>>>>>>
>>>>>>>> _________________________________________________________________
>>>>>>>> Découvrez comment SURFER DISCRETEMENT sur un site de rencontres !
>>>>>>>> http://clk.atdmt.com/FRM/go/206608211/direct/01/
>>>>>>> _________________________________________________________________
>>>>>>> Do you have a story that started on Hotmail? Tell us now
>>>>>>> http://clk.atdmt.com/UKM/go/195013117/direct/01/
>>>>>>> ---------------------------------------------------------------------
>>>>>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>>>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>>>>
>>>>>>
>>>>>> _________________________________________________________________
>>>>>> Consultez gratuitement vos emails Orange, Gmail, Free, ... 
>>>>>> directement dans HOTMAIL !
>>>>>> http://www.windowslive.fr/hotmail/agregation/
>>>>> _________________________________________________________________
>>>>> Do you have a story that started on Hotmail? Tell us now
>>>>> http://clk.atdmt.com/UKM/go/195013117/direct/01/
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>>
>>>>
>>>> _________________________________________________________________
>>>> Découvrez comment SURFER DISCRETEMENT sur un site de rencontres !
>>>> http://clk.atdmt.com/FRM/go/206608211/direct/01/
>>> _________________________________________________________________
>>> Got a cool Hotmail story? Tell us now
>>> http://clk.atdmt.com/UKM/go/195013117/direct/01/
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>> For additional commands, e-mail: user-help@struts.apache.org
>>>
>>
>> _________________________________________________________________
>> Consultez gratuitement vos emails Orange, Gmail, Free, ... directement 
>> dans HOTMAIL !
>> http://www.windowslive.fr/hotmail/agregation/
> _________________________________________________________________
> Got a cool Hotmail story? Tell us now
> http://clk.atdmt.com/UKM/go/195013117/direct/01/
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: CRUD with a OneToMany association under Struts 2 / Hibernate 3

Posted by adam pinder <ap...@hotmail.co.uk>.
 
so it looks like your issue is more to do with the child values not being set by Struts
 
there have been a few postings about using the [] notation on field names to get struts to assign the values properly.
 
in struts1 i found it worked fine, however in struts2 i've not really seen it working... in some of my actions i have actually added a method which gets the parameter values off the request and populates the objects myself..
 
e.g. look for parameter names starting parent.values and use the parameter name/value to construct the correct call to set the object.
 
seems unnecessary as struts2 should handle it, but as i say i couldn't get it to do it with arraylists i was using.
 


----------------------------------------
> From: brgrandjean@live.fr
> To: user@struts.apache.org
> Subject: RE: CRUD with a OneToMany association under Struts 2 / Hibernate 3
> Date: Thu, 1 Apr 2010 15:16:36 +0200
>
>
> Thks a lot Adam it is now more concise:
>
>
>
> Setting params
> Setting params id => [ 1 ]
> Setting params id => [ 1 ] method:saveOrUpdate => [ Submit ] name => [ Parent1 ] parent.values[0].id => [ 2 ] parent.values[0].name => [ Child2 ] parent.values[1].id => [ 1 ] parent.values[1].name => [ Child1 ]
>
>
>
> Error setting value
> ognl.NoSuchPropertyException: java.util.HashSet.0
> at ognl.SetPropertyAccessor.getProperty(SetPropertyAccessor.java:67)
> at com.opensymphony.xwork2.ognl.accessor.XWorkCollectionPropertyAccessor.getProperty(XWorkCollectionPropertyAccessor.java:80)
> at java.lang.Thread.run(Unknown Source)
> ..
> Error setting value
> ognl.NoSuchPropertyException: java.util.HashSet.0
> at ognl.SetPropertyAccessor.getProperty(SetPropertyAccessor.java:67)
> ..
> Error setting value
> ognl.NoSuchPropertyException: java.util.HashSet.1
> at ognl.SetPropertyAccessor.getProperty(SetPropertyAccessor.java:67)
> at com.opensymphony.xwork2.ognl.accessor.XWorkCollectionPropertyAccessor.getProperty(XWorkCollectionPropertyAccessor.java:80)
> ..
> Error setting value
> ognl.NoSuchPropertyException: java.util.HashSet.1
> at ognl.SetPropertyAccessor.getProperty(SetPropertyAccessor.java:67)
> at com.opensymphony.xwork2.ognl.accessor.XWorkCollectionPropertyAccessor.getProperty(XWorkCollectionPropertyAccessor.java:80)
> at ognl.OgnlRuntime.getProperty(OgnlRuntime.java:1643)
> ..
>
> Setting params
>
> Do u see something wrong??
>
>
>
>
>> From: apinder@hotmail.co.uk
>> To: user@struts.apache.org
>> Subject: RE: CRUD with a OneToMany association under Struts 2 / Hibernate 3
>> Date: Thu, 1 Apr 2010 13:54:58 +0100
>>
>>
>>
>> set the rootlogger to warn
>>
>> log4j.rootLogger=warn, stdout
>>
>> rather than debug
>>
>> you should only get a parameterinterceptor log entry every time you post something to the server
>>
>> ----------------------------------------
>>> From: brgrandjean@live.fr
>>> To: user@struts.apache.org
>>> Subject: RE: CRUD with a OneToMany association under Struts 2 / Hibernate 3
>>> Date: Thu, 1 Apr 2010 14:51:40 +0200
>>>
>>>
>>> thks adam but I got now thousand & thousand of lines
>>>
>>> I am afraid that I won't be able to read its before the end of the world in 2012..
>>>
>>>
>>>
>>> I saw very quicky an exception at the beginning..
>>>
>>> How can I limit this huge quantity of lines?
>>>
>>>
>>>
>>> here is my log4j.properties file:
>>>
>>>
>>>
>>> log4j.appender.stdout=org.apache.log4j.ConsoleAppender
>>> log4j.appender.stdout.Target=System.out
>>> log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
>>> log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
>>> log4j.rootLogger=debug, stdout
>>> log4j.logger.com.opensymphony.xwork2.interceptor.ParametersInterceptor=debug
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>> From: apinder@hotmail.co.uk
>>>> To: user@struts.apache.org
>>>> Subject: RE: CRUD with a OneToMany association under Struts 2 / Hibernate 3
>>>> Date: Thu, 1 Apr 2010 12:57:39 +0100
>>>>
>>>>
>>>>
>>>>
>>>> in log4j.properties file (same location as struts.xml and hibernate config files)
>>>>
>>>> add
>>>>
>>>> log4j.logger.com.opensymphony.xwork2.interceptor.ParametersInterceptor=debug
>>>>
>>>> this will output param name/value pairs being posted from your page.
>>>>
>>>>
>>>>
>>>> ----------------------------------------
>>>>> From: brgrandjean@live.fr
>>>>> To: user@struts.apache.org
>>>>> Subject: RE: CRUD with a OneToMany association under Struts 2 / Hibernate 3
>>>>> Date: Thu, 1 Apr 2010 13:54:33 +0200
>>>>>
>>>>>
>>>>> Dear Adam,
>>>>>
>>>>>
>>>>>
>>>>> I just added a public Child getValues(int idx) in the Parent class definition but it is never called.
>>>>>
>>>>>
>>>>>
>>>>> Could u explain to me where and how can I turn on the parameterinterceptor logging? In the struts.xml file?
>>>>>
>>>>>
>>>>>
>>>>> thks a lot
>>>>>
>>>>>
>>>>> bruno
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>> From: apinder@hotmail.co.uk
>>>>>> To: user@struts.apache.org
>>>>>> Subject: RE: CRUD with a OneToMany association under Struts 2 / Hibernate 3
>>>>>> Date: Thu, 1 Apr 2010 12:18:48 +0100
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> turn on the parameterinterceptor logging and make sure as mentioned that
>>>>>>
>>>>>> 1) the values you expect for each child are being sent to the server (id and name)
>>>>>> 2) the parameter names are correct for setting each child
>>>>>>
>>>>>> i had some issues getting lists of items to be updated by form submission alone.
>>>>>>
>>>>>> for example does your parent object have a getValues method taking an index value
>>>>>>
>>>>>> getParent().getValues(1).setId(1)
>>>>>> getParent().getValues(1).setName("bob")
>>>>>>
>>>>>> would be called by parameterinterceptor
>>>>>>
>>>>>>
>>>>>> ----------------------------------------
>>>>>>> From: brgrandjean@live.fr
>>>>>>> To: user@struts.apache.org
>>>>>>> Subject: RE: CRUD with a OneToMany association under Struts 2 / Hibernate 3
>>>>>>> Date: Thu, 1 Apr 2010 12:16:09 +0200
>>>>>>>
>>>>>>>
>>>>>>> Dear René
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> I changed my jsp page so as to integrate the following block:
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> which generates the following html code:
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> I can display my complete Child Set but I got the same result after updating: my Child Set is empty.
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> Is that necessary to modify my ParentAction as well? If yes what to do?
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> public class ParentAction extends ActionSupport implements ModelDriven {
>>>>>>>
>>>>>>> private static final long serialVersionUID = -2662966220408285700L;
>>>>>>> private Parent cl = new Parent();
>>>>>>> private List clList = new ArrayList();
>>>>>>> private ParentDAO clDAO = new ParentDAOImpl();
>>>>>>>
>>>>>>> @Override
>>>>>>> public Parent getModel() {
>>>>>>> return cl;
>>>>>>> }
>>>>>>>
>>>>>>> public String saveOrUpdate()
>>>>>>> { // cl.values is empty here!!
>>>>>>> clDAO.saveOrUpdateParent(cl);
>>>>>>> return SUCCESS;
>>>>>>> }
>>>>>>>
>>>>>>> public String save()
>>>>>>> {
>>>>>>> clDAO.saveParent(cl);
>>>>>>> return SUCCESS;
>>>>>>> }
>>>>>>>
>>>>>>> public String list()
>>>>>>> {
>>>>>>> clList = clDAO.listParent();
>>>>>>> return SUCCESS;
>>>>>>> }
>>>>>>>
>>>>>>> public String delete()
>>>>>>> {
>>>>>>> HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
>>>>>>> clDAO.deleteParent(Long.parseLong(request.getParameter("id")));
>>>>>>> return SUCCESS;
>>>>>>> }
>>>>>>>
>>>>>>> public String edit()
>>>>>>> { // cl.values contains some valid Child elements here!!
>>>>>>> HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
>>>>>>> cl = clDAO.listParentById(Long.parseLong(request.getParameter("id")));
>>>>>>> }
>>>>>>> return SUCCESS;
>>>>>>> }
>>>>>>>
>>>>>>> public Parent getParent() {
>>>>>>> return cl;
>>>>>>> }
>>>>>>>
>>>>>>> public void setParent(Parent cl) {
>>>>>>> this.cl = cl;
>>>>>>> }
>>>>>>>
>>>>>>> public List getParentList() {
>>>>>>> return clList;
>>>>>>> }
>>>>>>>
>>>>>>> public void setParentList(List clList) {
>>>>>>> this.clList = clList;
>>>>>>> }
>>>>>>> }
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>> Date: Thu, 1 Apr 2010 11:30:23 +0200
>>>>>>>> From: gielen@it-neering.net
>>>>>>>> To: user@struts.apache.org
>>>>>>>> Subject: Re: CRUD with a OneToMany association under Struts 2 / Hibernate 3
>>>>>>>>
>>>>>>>> Given the model you presented in the first post, your problem seems to
>>>>>>>> be that the posted values have not the correct name for the children's
>>>>>>>> form fields. The parameters names you would need are
>>>>>>>>
>>>>>>>> id
>>>>>>>> name
>>>>>>>> values[0].id
>>>>>>>> values[0].name
>>>>>>>> values[1].id
>>>>>>>> values[2].name
>>>>>>>> ...
>>>>>>>>
>>>>>>>> for the parameters interceptor to work properly when applying the posted
>>>>>>>> values.
>>>>>>>>
>>>>>>>> See here for more details:
>>>>>>>> http://struts.apache.org/2.1.8/docs/tabular-inputs.html
>>>>>>>>
>>>>>>>> - René
>>>>>>>>
>>>>>>>> bruno grandjean schrieb:
>>>>>>>>> Dear Rene,
>>>>>>>>>
>>>>>>>>> Thks a lot for replying to me because I am feeling a little bit alone with
>>>>>>>>> my CRUD ;-). In fact I am trying to build a dynamic MetaCrud.
>>>>>>>>> My pb is simple: in the same jsp page I would like to update a Parent
>>>>>>>>> object
>>>>>>>>> and its Childs (values):
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>>>> name="name" label="Nom" />
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> From an existing Parent object with many Childs objects I can easily modify
>>>>>>>>> parent.name for instance but the collection of Child objects (values) is
>>>>>>>>> always empty in the ParentAction (saveOrUpdate() method) after submitting.
>>>>>>>>> However I can display each values[i].name in the jsp page with the correct
>>>>>>>>> value.
>>>>>>>>> So it is not an issue with Hibernate but with the jsp or ModelDriven
>>>>>>>>> interface I don't know..Do you have any idea?
>>>>>>>>> Basically I was not able to find a struts or spring documentation about
>>>>>>>>> CRUD
>>>>>>>>> & association between two entities on the same jsp page.
>>>>>>>>> best regards
>>>>>>>>> bruno
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> --------------------------------------------------
>>>>>>>>> From: "Rene Gielen"
>>>>>>>>> Sent: Wednesday, March 31, 2010 7:12 PM
>>>>>>>>> To: "Struts Users Mailing List"
>>>>>>>>> Subject: Re: CRUD with a OneToMany association under Struts 2 / Hibernate 3
>>>>>>>>>
>>>>>>>>>> I'm not sure if I understand what your actual question is, nor whether
>>>>>>>>>> it is particularly Struts 2 related (rather than just Hibernate) - but
>>>>>>>>>> you might want to have a look in the CRUD demo section of the Struts 2
>>>>>>>>>> showcase application. Maybe you will also find this demo useful:
>>>>>>>>>> http://github.com/rgielen/struts2crudevolutiondemo
>>>>>>>>>>
>>>>>>>>>> - René
>>>>>>>>>>
>>>>>>>>>> bruno grandjean schrieb:
>>>>>>>>>>> Hi
>>>>>>>>>>>
>>>>>>>>>>> I am trying to implement a simple CRUD with a OneToMany association
>>>>>>>>>>> under Struts 2 / Hibernate 3.
>>>>>>>>>>> I have two entities Parent and Child:
>>>>>>>>>>>
>>>>>>>>>>> @Entity
>>>>>>>>>>> @Table(name="PARENT")
>>>>>>>>>>> public class Parent {
>>>>>>>>>>> private Long id;
>>>>>>>>>>> private Set values = new HashSet();
>>>>>>>>>>> ..
>>>>>>>>>>> @Entity
>>>>>>>>>>> @Table(name="CHILD")
>>>>>>>>>>> public class Child {
>>>>>>>>>>> private Long id;
>>>>>>>>>>> private String name;
>>>>>>>>>>> ..
>>>>>>>>>>>
>>>>>>>>>>> I can easily create, delete Parent or read the Child Set (values) but
>>>>>>>>>>> it is impossible to update Child Set.
>>>>>>>>>>> The jsp page (see below) reinit the values Set, no record after
>>>>>>>>>>> updating!
>>>>>>>>>>> Could u explain to me what's wrong?
>>>>>>>>>>>
>>>>>>>>>>> here are my code:
>>>>>>>>>>>
>>>>>>>>>>> @Entity
>>>>>>>>>>> @Table(name="PARENT")
>>>>>>>>>>> public class Parent {
>>>>>>>>>>> private Long id;
>>>>>>>>>>> private Set values = new HashSet();
>>>>>>>>>>> @Id
>>>>>>>>>>> @GeneratedValue
>>>>>>>>>>> @Column(name="PARENT_ID")
>>>>>>>>>>> public Long getId() {
>>>>>>>>>>> return id;
>>>>>>>>>>> }
>>>>>>>>>>> public void setId(Long id) {
>>>>>>>>>>> this.id = id;
>>>>>>>>>>> }
>>>>>>>>>>> @ManyToMany(fetch = FetchType.EAGER)
>>>>>>>>>>> @JoinTable(name = "PARENT_CHILD", joinColumns = { @JoinColumn(name =
>>>>>>>>>>> "PARENT_ID") }, inverseJoinColumns = { @JoinColumn(name = "CHILD_ID") })
>>>>>>>>>>> public Set getValues() {
>>>>>>>>>>> return values;
>>>>>>>>>>> }
>>>>>>>>>>> public void setValues(Set lst) {
>>>>>>>>>>> values = lst;
>>>>>>>>>>> }
>>>>>>>>>>> }
>>>>>>>>>>>
>>>>>>>>>>> @Entity
>>>>>>>>>>> @Table(name="CHILD")
>>>>>>>>>>> public class Child {
>>>>>>>>>>> private Long id;
>>>>>>>>>>> private String name;
>>>>>>>>>>> @Id
>>>>>>>>>>> @GeneratedValue
>>>>>>>>>>> @Column(name="CHILD_ID")
>>>>>>>>>>> public Long getId() {
>>>>>>>>>>> return id;
>>>>>>>>>>> }
>>>>>>>>>>> public void setId(Long id) {
>>>>>>>>>>> this.id = id;
>>>>>>>>>>> }
>>>>>>>>>>> @Column(name="NAME")
>>>>>>>>>>> public String getName() {
>>>>>>>>>>> return name;
>>>>>>>>>>> }
>>>>>>>>>>> public void setName(String val) {
>>>>>>>>>>> name = val;
>>>>>>>>>>> }
>>>>>>>>>>> }
>>>>>>>>>>>
>>>>>>>>>>> public interface ParentDAO {
>>>>>>>>>>> public void saveOrUpdateParent(Parent cl);
>>>>>>>>>>> public void saveParent(Parent cl);
>>>>>>>>>>> public List listParent();
>>>>>>>>>>> public Parent listParentById(Long clId);
>>>>>>>>>>> public void deleteParent(Long clId);
>>>>>>>>>>> }
>>>>>>>>>>>
>>>>>>>>>>> public class ParentDAOImpl implements ParentDAO {
>>>>>>>>>>> @SessionTarget
>>>>>>>>>>> Session session;
>>>>>>>>>>> @TransactionTarget
>>>>>>>>>>> Transaction transaction;
>>>>>>>>>>>
>>>>>>>>>>> @Override
>>>>>>>>>>> public void saveOrUpdateParent(Parent cl) {
>>>>>>>>>>> try {
>>>>>>>>>>> session.saveOrUpdate(cl);
>>>>>>>>>>> } catch (Exception e) {
>>>>>>>>>>> transaction.rollback();
>>>>>>>>>>> e.printStackTrace();
>>>>>>>>>>> }
>>>>>>>>>>> }
>>>>>>>>>>>
>>>>>>>>>>> @Override
>>>>>>>>>>> public void saveParent(Parent cl) {
>>>>>>>>>>> try {
>>>>>>>>>>> session.save(cl);
>>>>>>>>>>> } catch (Exception e) {
>>>>>>>>>>> transaction.rollback();
>>>>>>>>>>> e.printStackTrace();
>>>>>>>>>>> }
>>>>>>>>>>> }
>>>>>>>>>>>
>>>>>>>>>>> @Override
>>>>>>>>>>> public void deleteParent(Long clId) {
>>>>>>>>>>> try {
>>>>>>>>>>> Parent cl = (Parent) session.get(Parent.class, clId);
>>>>>>>>>>> session.delete(cl);
>>>>>>>>>>> } catch (Exception e) {
>>>>>>>>>>> transaction.rollback();
>>>>>>>>>>> e.printStackTrace();
>>>>>>>>>>> }
>>>>>>>>>>> }
>>>>>>>>>>>
>>>>>>>>>>> @SuppressWarnings("unchecked")
>>>>>>>>>>> @Override
>>>>>>>>>>> public List listParent() {
>>>>>>>>>>> List courses = null;
>>>>>>>>>>> try {
>>>>>>>>>>> courses = session.createQuery("from Parent").list();
>>>>>>>>>>> } catch (Exception e) {
>>>>>>>>>>> e.printStackTrace();
>>>>>>>>>>> }
>>>>>>>>>>> return courses;
>>>>>>>>>>> }
>>>>>>>>>>>
>>>>>>>>>>> @Override
>>>>>>>>>>> public Parent listParentById(Long clId) {
>>>>>>>>>>> Parent cl = null;
>>>>>>>>>>> try {
>>>>>>>>>>> cl = (Parent) session.get(Parent.class, clId);
>>>>>>>>>>> } catch (Exception e) {
>>>>>>>>>>> e.printStackTrace();
>>>>>>>>>>> }
>>>>>>>>>>> return cl;
>>>>>>>>>>> }
>>>>>>>>>>> }
>>>>>>>>>>>
>>>>>>>>>>> public class ParentAction extends ActionSupport implements
>>>>>>>>>>> ModelDriven {
>>>>>>>>>>>
>>>>>>>>>>> private static final long serialVersionUID = -2662966220408285700L;
>>>>>>>>>>> private Parent cl = new Parent();
>>>>>>>>>>> private List clList = new ArrayList();
>>>>>>>>>>> private ParentDAO clDAO = new ParentDAOImpl();
>>>>>>>>>>>
>>>>>>>>>>> @Override
>>>>>>>>>>> public Parent getModel() {
>>>>>>>>>>> return cl;
>>>>>>>>>>> }
>>>>>>>>>>>
>>>>>>>>>>> public String saveOrUpdate()
>>>>>>>>>>> {
>>>>>>>>>>> clDAO.saveOrUpdateParent(cl);
>>>>>>>>>>> return SUCCESS;
>>>>>>>>>>> }
>>>>>>>>>>>
>>>>>>>>>>> public String save()
>>>>>>>>>>> {
>>>>>>>>>>> clDAO.saveParent(cl);
>>>>>>>>>>> return SUCCESS;
>>>>>>>>>>> }
>>>>>>>>>>>
>>>>>>>>>>> public String list()
>>>>>>>>>>> {
>>>>>>>>>>> clList = clDAO.listParent();
>>>>>>>>>>> return SUCCESS;
>>>>>>>>>>> }
>>>>>>>>>>>
>>>>>>>>>>> public String delete()
>>>>>>>>>>> {
>>>>>>>>>>> HttpServletRequest request = (HttpServletRequest)
>>>>>>>>>>> ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
>>>>>>>>>>> clDAO.deleteParent(Long.parseLong(request.getParameter("id")));
>>>>>>>>>>> return SUCCESS;
>>>>>>>>>>> }
>>>>>>>>>>>
>>>>>>>>>>> public String edit()
>>>>>>>>>>> {
>>>>>>>>>>> HttpServletRequest request = (HttpServletRequest)
>>>>>>>>>>> ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
>>>>>>>>>>> cl = clDAO.listParentById(Long.parseLong(request.getParameter("id")));
>>>>>>>>>>> return SUCCESS;
>>>>>>>>>>> }
>>>>>>>>>>>
>>>>>>>>>>> public Parent getParent() {
>>>>>>>>>>> return cl;
>>>>>>>>>>> }
>>>>>>>>>>>
>>>>>>>>>>> public void setParent(Parent cl) {
>>>>>>>>>>> this.cl = cl;
>>>>>>>>>>> }
>>>>>>>>>>>
>>>>>>>>>>> public List getParentList() {
>>>>>>>>>>> return clList;
>>>>>>>>>>> }
>>>>>>>>>>>
>>>>>>>>>>> public void setParentList(List clList) {
>>>>>>>>>>> this.clList = clList;
>>>>>>>>>>> }
>>>>>>>>>>> }
>>>>>>>>>>>
>>>>>>>>>>> and finally the jsp page:
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>>>>>> "http://www.w3.org/TR/html4/loose.dtd">
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>
>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>
>>>>>>>>>>>
>>>>>>
>>>>>>>>>>>
>>>>>>
>>>>>>
>>>>>>>>>>>
>>>>>> Child(s)
>>>>>>>>>>>
>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>>>>>> class="oddeven">
>>>>>>>>>>>
>>>>>>
>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> Edit
>>>>>>>>>>>
>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> Delete
>>>>>>>>>>>
>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> --
>>>>>>>>>> René Gielen
>>>>>>>>>> IT-Neering.net
>>>>>>>>>> Saarstrasse 100, 52062 Aachen, Germany
>>>>>>>>>> Tel: +49-(0)241-4010770
>>>>>>>>>> Fax: +49-(0)241-4010771
>>>>>>>>>> Cel: +49-(0)163-2844164
>>>>>>>>>> http://twitter.com/rgielen
>>>>>>>>>>
>>>>>>>>>> ---------------------------------------------------------------------
>>>>>>>>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>>>>>>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>> ---------------------------------------------------------------------
>>>>>>>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>>>>>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>>>>>>
>>>>>>>>
>>>>>>>> --
>>>>>>>> René Gielen
>>>>>>>> IT-Neering.net
>>>>>>>> Saarstrasse 100, 52062 Aachen, Germany
>>>>>>>> Tel: +49-(0)241-4010770
>>>>>>>> Fax: +49-(0)241-4010771
>>>>>>>> Cel: +49-(0)163-2844164
>>>>>>>> http://twitter.com/rgielen
>>>>>>>>
>>>>>>>> ---------------------------------------------------------------------
>>>>>>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>>>>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>>>>>
>>>>>>>
>>>>>>> _________________________________________________________________
>>>>>>> Découvrez comment SURFER DISCRETEMENT sur un site de rencontres !
>>>>>>> http://clk.atdmt.com/FRM/go/206608211/direct/01/
>>>>>> _________________________________________________________________
>>>>>> Do you have a story that started on Hotmail? Tell us now
>>>>>> http://clk.atdmt.com/UKM/go/195013117/direct/01/
>>>>>> ---------------------------------------------------------------------
>>>>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>>>
>>>>>
>>>>> _________________________________________________________________
>>>>> Consultez gratuitement vos emails Orange, Gmail, Free, ... directement dans HOTMAIL !
>>>>> http://www.windowslive.fr/hotmail/agregation/
>>>> _________________________________________________________________
>>>> Do you have a story that started on Hotmail? Tell us now
>>>> http://clk.atdmt.com/UKM/go/195013117/direct/01/
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>
>>>
>>> _________________________________________________________________
>>> Découvrez comment SURFER DISCRETEMENT sur un site de rencontres !
>>> http://clk.atdmt.com/FRM/go/206608211/direct/01/
>> _________________________________________________________________
>> Got a cool Hotmail story? Tell us now
>> http://clk.atdmt.com/UKM/go/195013117/direct/01/
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>
> _________________________________________________________________
> Consultez gratuitement vos emails Orange, Gmail, Free, ... directement dans HOTMAIL !
> http://www.windowslive.fr/hotmail/agregation/ 		 	   		  
_________________________________________________________________
Got a cool Hotmail story? Tell us now
http://clk.atdmt.com/UKM/go/195013117/direct/01/
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: CRUD with a OneToMany association under Struts 2 / Hibernate 3

Posted by bruno grandjean <br...@live.fr>.
Thks a lot Adam it is now more concise:

 

Setting params 
Setting params id => [ 1 ] 
Setting params id => [ 1 ] method:saveOrUpdate => [ Submit ] name => [ Parent1 ] parent.values[0].id => [ 2 ] parent.values[0].name => [ Child2 ] parent.values[1].id => [ 1 ] parent.values[1].name => [ Child1 ]

 

Error setting value
ognl.NoSuchPropertyException: java.util.HashSet.0
at ognl.SetPropertyAccessor.getProperty(SetPropertyAccessor.java:67)
at com.opensymphony.xwork2.ognl.accessor.XWorkCollectionPropertyAccessor.getProperty(XWorkCollectionPropertyAccessor.java:80)
at java.lang.Thread.run(Unknown Source)
..
Error setting value
ognl.NoSuchPropertyException: java.util.HashSet.0
at ognl.SetPropertyAccessor.getProperty(SetPropertyAccessor.java:67)
..
Error setting value
ognl.NoSuchPropertyException: java.util.HashSet.1
at ognl.SetPropertyAccessor.getProperty(SetPropertyAccessor.java:67)
at com.opensymphony.xwork2.ognl.accessor.XWorkCollectionPropertyAccessor.getProperty(XWorkCollectionPropertyAccessor.java:80)
..
Error setting value
ognl.NoSuchPropertyException: java.util.HashSet.1
at ognl.SetPropertyAccessor.getProperty(SetPropertyAccessor.java:67)
at com.opensymphony.xwork2.ognl.accessor.XWorkCollectionPropertyAccessor.getProperty(XWorkCollectionPropertyAccessor.java:80)
at ognl.OgnlRuntime.getProperty(OgnlRuntime.java:1643)
..
 
Setting params 

Do u see something wrong??

 

 
> From: apinder@hotmail.co.uk
> To: user@struts.apache.org
> Subject: RE: CRUD with a OneToMany association under Struts 2 / Hibernate 3
> Date: Thu, 1 Apr 2010 13:54:58 +0100
> 
> 
> 
> set the rootlogger to warn
> 
> log4j.rootLogger=warn, stdout
> 
> rather than debug
> 
> you should only get a parameterinterceptor log entry every time you post something to the server
> 
> ----------------------------------------
> > From: brgrandjean@live.fr
> > To: user@struts.apache.org
> > Subject: RE: CRUD with a OneToMany association under Struts 2 / Hibernate 3
> > Date: Thu, 1 Apr 2010 14:51:40 +0200
> >
> >
> > thks adam but I got now thousand & thousand of lines
> >
> > I am afraid that I won't be able to read its before the end of the world in 2012..
> >
> >
> >
> > I saw very quicky an exception at the beginning..
> >
> > How can I limit this huge quantity of lines?
> >
> >
> >
> > here is my log4j.properties file:
> >
> >
> >
> > log4j.appender.stdout=org.apache.log4j.ConsoleAppender
> > log4j.appender.stdout.Target=System.out
> > log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
> > log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
> > log4j.rootLogger=debug, stdout
> > log4j.logger.com.opensymphony.xwork2.interceptor.ParametersInterceptor=debug
> >
> >
> >
> >
> >
> >
> >
> >> From: apinder@hotmail.co.uk
> >> To: user@struts.apache.org
> >> Subject: RE: CRUD with a OneToMany association under Struts 2 / Hibernate 3
> >> Date: Thu, 1 Apr 2010 12:57:39 +0100
> >>
> >>
> >>
> >>
> >> in log4j.properties file (same location as struts.xml and hibernate config files)
> >>
> >> add
> >>
> >> log4j.logger.com.opensymphony.xwork2.interceptor.ParametersInterceptor=debug
> >>
> >> this will output param name/value pairs being posted from your page.
> >>
> >>
> >>
> >> ----------------------------------------
> >>> From: brgrandjean@live.fr
> >>> To: user@struts.apache.org
> >>> Subject: RE: CRUD with a OneToMany association under Struts 2 / Hibernate 3
> >>> Date: Thu, 1 Apr 2010 13:54:33 +0200
> >>>
> >>>
> >>> Dear Adam,
> >>>
> >>>
> >>>
> >>> I just added a public Child getValues(int idx) in the Parent class definition but it is never called.
> >>>
> >>>
> >>>
> >>> Could u explain to me where and how can I turn on the parameterinterceptor logging? In the struts.xml file?
> >>>
> >>>
> >>>
> >>> thks a lot
> >>>
> >>>
> >>> bruno
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>> From: apinder@hotmail.co.uk
> >>>> To: user@struts.apache.org
> >>>> Subject: RE: CRUD with a OneToMany association under Struts 2 / Hibernate 3
> >>>> Date: Thu, 1 Apr 2010 12:18:48 +0100
> >>>>
> >>>>
> >>>>
> >>>>
> >>>> turn on the parameterinterceptor logging and make sure as mentioned that
> >>>>
> >>>> 1) the values you expect for each child are being sent to the server (id and name)
> >>>> 2) the parameter names are correct for setting each child
> >>>>
> >>>> i had some issues getting lists of items to be updated by form submission alone.
> >>>>
> >>>> for example does your parent object have a getValues method taking an index value
> >>>>
> >>>> getParent().getValues(1).setId(1)
> >>>> getParent().getValues(1).setName("bob")
> >>>>
> >>>> would be called by parameterinterceptor
> >>>>
> >>>>
> >>>> ----------------------------------------
> >>>>> From: brgrandjean@live.fr
> >>>>> To: user@struts.apache.org
> >>>>> Subject: RE: CRUD with a OneToMany association under Struts 2 / Hibernate 3
> >>>>> Date: Thu, 1 Apr 2010 12:16:09 +0200
> >>>>>
> >>>>>
> >>>>> Dear René
> >>>>>
> >>>>>
> >>>>>
> >>>>> I changed my jsp page so as to integrate the following block:
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>> which generates the following html code:
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>> I can display my complete Child Set but I got the same result after updating: my Child Set is empty.
> >>>>>
> >>>>>
> >>>>>
> >>>>> Is that necessary to modify my ParentAction as well? If yes what to do?
> >>>>>
> >>>>>
> >>>>>
> >>>>> public class ParentAction extends ActionSupport implements ModelDriven {
> >>>>>
> >>>>> private static final long serialVersionUID = -2662966220408285700L;
> >>>>> private Parent cl = new Parent();
> >>>>> private List clList = new ArrayList();
> >>>>> private ParentDAO clDAO = new ParentDAOImpl();
> >>>>>
> >>>>> @Override
> >>>>> public Parent getModel() {
> >>>>> return cl;
> >>>>> }
> >>>>>
> >>>>> public String saveOrUpdate()
> >>>>> { // cl.values is empty here!!
> >>>>> clDAO.saveOrUpdateParent(cl);
> >>>>> return SUCCESS;
> >>>>> }
> >>>>>
> >>>>> public String save()
> >>>>> {
> >>>>> clDAO.saveParent(cl);
> >>>>> return SUCCESS;
> >>>>> }
> >>>>>
> >>>>> public String list()
> >>>>> {
> >>>>> clList = clDAO.listParent();
> >>>>> return SUCCESS;
> >>>>> }
> >>>>>
> >>>>> public String delete()
> >>>>> {
> >>>>> HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
> >>>>> clDAO.deleteParent(Long.parseLong(request.getParameter("id")));
> >>>>> return SUCCESS;
> >>>>> }
> >>>>>
> >>>>> public String edit()
> >>>>> { // cl.values contains some valid Child elements here!!
> >>>>> HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
> >>>>> cl = clDAO.listParentById(Long.parseLong(request.getParameter("id")));
> >>>>> }
> >>>>> return SUCCESS;
> >>>>> }
> >>>>>
> >>>>> public Parent getParent() {
> >>>>> return cl;
> >>>>> }
> >>>>>
> >>>>> public void setParent(Parent cl) {
> >>>>> this.cl = cl;
> >>>>> }
> >>>>>
> >>>>> public List getParentList() {
> >>>>> return clList;
> >>>>> }
> >>>>>
> >>>>> public void setParentList(List clList) {
> >>>>> this.clList = clList;
> >>>>> }
> >>>>> }
> >>>>>
> >>>>>
> >>>>>
> >>>>>> Date: Thu, 1 Apr 2010 11:30:23 +0200
> >>>>>> From: gielen@it-neering.net
> >>>>>> To: user@struts.apache.org
> >>>>>> Subject: Re: CRUD with a OneToMany association under Struts 2 / Hibernate 3
> >>>>>>
> >>>>>> Given the model you presented in the first post, your problem seems to
> >>>>>> be that the posted values have not the correct name for the children's
> >>>>>> form fields. The parameters names you would need are
> >>>>>>
> >>>>>> id
> >>>>>> name
> >>>>>> values[0].id
> >>>>>> values[0].name
> >>>>>> values[1].id
> >>>>>> values[2].name
> >>>>>> ...
> >>>>>>
> >>>>>> for the parameters interceptor to work properly when applying the posted
> >>>>>> values.
> >>>>>>
> >>>>>> See here for more details:
> >>>>>> http://struts.apache.org/2.1.8/docs/tabular-inputs.html
> >>>>>>
> >>>>>> - René
> >>>>>>
> >>>>>> bruno grandjean schrieb:
> >>>>>>> Dear Rene,
> >>>>>>>
> >>>>>>> Thks a lot for replying to me because I am feeling a little bit alone with
> >>>>>>> my CRUD ;-). In fact I am trying to build a dynamic MetaCrud.
> >>>>>>> My pb is simple: in the same jsp page I would like to update a Parent
> >>>>>>> object
> >>>>>>> and its Childs (values):
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>>>> name="name" label="Nom" />
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>> From an existing Parent object with many Childs objects I can easily modify
> >>>>>>> parent.name for instance but the collection of Child objects (values) is
> >>>>>>> always empty in the ParentAction (saveOrUpdate() method) after submitting.
> >>>>>>> However I can display each values[i].name in the jsp page with the correct
> >>>>>>> value.
> >>>>>>> So it is not an issue with Hibernate but with the jsp or ModelDriven
> >>>>>>> interface I don't know..Do you have any idea?
> >>>>>>> Basically I was not able to find a struts or spring documentation about
> >>>>>>> CRUD
> >>>>>>> & association between two entities on the same jsp page.
> >>>>>>> best regards
> >>>>>>> bruno
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>> --------------------------------------------------
> >>>>>>> From: "Rene Gielen"
> >>>>>>> Sent: Wednesday, March 31, 2010 7:12 PM
> >>>>>>> To: "Struts Users Mailing List"
> >>>>>>> Subject: Re: CRUD with a OneToMany association under Struts 2 / Hibernate 3
> >>>>>>>
> >>>>>>>> I'm not sure if I understand what your actual question is, nor whether
> >>>>>>>> it is particularly Struts 2 related (rather than just Hibernate) - but
> >>>>>>>> you might want to have a look in the CRUD demo section of the Struts 2
> >>>>>>>> showcase application. Maybe you will also find this demo useful:
> >>>>>>>> http://github.com/rgielen/struts2crudevolutiondemo
> >>>>>>>>
> >>>>>>>> - René
> >>>>>>>>
> >>>>>>>> bruno grandjean schrieb:
> >>>>>>>>> Hi
> >>>>>>>>>
> >>>>>>>>> I am trying to implement a simple CRUD with a OneToMany association
> >>>>>>>>> under Struts 2 / Hibernate 3.
> >>>>>>>>> I have two entities Parent and Child:
> >>>>>>>>>
> >>>>>>>>> @Entity
> >>>>>>>>> @Table(name="PARENT")
> >>>>>>>>> public class Parent {
> >>>>>>>>> private Long id;
> >>>>>>>>> private Set values = new HashSet();
> >>>>>>>>> ..
> >>>>>>>>> @Entity
> >>>>>>>>> @Table(name="CHILD")
> >>>>>>>>> public class Child {
> >>>>>>>>> private Long id;
> >>>>>>>>> private String name;
> >>>>>>>>> ..
> >>>>>>>>>
> >>>>>>>>> I can easily create, delete Parent or read the Child Set (values) but
> >>>>>>>>> it is impossible to update Child Set.
> >>>>>>>>> The jsp page (see below) reinit the values Set, no record after
> >>>>>>>>> updating!
> >>>>>>>>> Could u explain to me what's wrong?
> >>>>>>>>>
> >>>>>>>>> here are my code:
> >>>>>>>>>
> >>>>>>>>> @Entity
> >>>>>>>>> @Table(name="PARENT")
> >>>>>>>>> public class Parent {
> >>>>>>>>> private Long id;
> >>>>>>>>> private Set values = new HashSet();
> >>>>>>>>> @Id
> >>>>>>>>> @GeneratedValue
> >>>>>>>>> @Column(name="PARENT_ID")
> >>>>>>>>> public Long getId() {
> >>>>>>>>> return id;
> >>>>>>>>> }
> >>>>>>>>> public void setId(Long id) {
> >>>>>>>>> this.id = id;
> >>>>>>>>> }
> >>>>>>>>> @ManyToMany(fetch = FetchType.EAGER)
> >>>>>>>>> @JoinTable(name = "PARENT_CHILD", joinColumns = { @JoinColumn(name =
> >>>>>>>>> "PARENT_ID") }, inverseJoinColumns = { @JoinColumn(name = "CHILD_ID") })
> >>>>>>>>> public Set getValues() {
> >>>>>>>>> return values;
> >>>>>>>>> }
> >>>>>>>>> public void setValues(Set lst) {
> >>>>>>>>> values = lst;
> >>>>>>>>> }
> >>>>>>>>> }
> >>>>>>>>>
> >>>>>>>>> @Entity
> >>>>>>>>> @Table(name="CHILD")
> >>>>>>>>> public class Child {
> >>>>>>>>> private Long id;
> >>>>>>>>> private String name;
> >>>>>>>>> @Id
> >>>>>>>>> @GeneratedValue
> >>>>>>>>> @Column(name="CHILD_ID")
> >>>>>>>>> public Long getId() {
> >>>>>>>>> return id;
> >>>>>>>>> }
> >>>>>>>>> public void setId(Long id) {
> >>>>>>>>> this.id = id;
> >>>>>>>>> }
> >>>>>>>>> @Column(name="NAME")
> >>>>>>>>> public String getName() {
> >>>>>>>>> return name;
> >>>>>>>>> }
> >>>>>>>>> public void setName(String val) {
> >>>>>>>>> name = val;
> >>>>>>>>> }
> >>>>>>>>> }
> >>>>>>>>>
> >>>>>>>>> public interface ParentDAO {
> >>>>>>>>> public void saveOrUpdateParent(Parent cl);
> >>>>>>>>> public void saveParent(Parent cl);
> >>>>>>>>> public List listParent();
> >>>>>>>>> public Parent listParentById(Long clId);
> >>>>>>>>> public void deleteParent(Long clId);
> >>>>>>>>> }
> >>>>>>>>>
> >>>>>>>>> public class ParentDAOImpl implements ParentDAO {
> >>>>>>>>> @SessionTarget
> >>>>>>>>> Session session;
> >>>>>>>>> @TransactionTarget
> >>>>>>>>> Transaction transaction;
> >>>>>>>>>
> >>>>>>>>> @Override
> >>>>>>>>> public void saveOrUpdateParent(Parent cl) {
> >>>>>>>>> try {
> >>>>>>>>> session.saveOrUpdate(cl);
> >>>>>>>>> } catch (Exception e) {
> >>>>>>>>> transaction.rollback();
> >>>>>>>>> e.printStackTrace();
> >>>>>>>>> }
> >>>>>>>>> }
> >>>>>>>>>
> >>>>>>>>> @Override
> >>>>>>>>> public void saveParent(Parent cl) {
> >>>>>>>>> try {
> >>>>>>>>> session.save(cl);
> >>>>>>>>> } catch (Exception e) {
> >>>>>>>>> transaction.rollback();
> >>>>>>>>> e.printStackTrace();
> >>>>>>>>> }
> >>>>>>>>> }
> >>>>>>>>>
> >>>>>>>>> @Override
> >>>>>>>>> public void deleteParent(Long clId) {
> >>>>>>>>> try {
> >>>>>>>>> Parent cl = (Parent) session.get(Parent.class, clId);
> >>>>>>>>> session.delete(cl);
> >>>>>>>>> } catch (Exception e) {
> >>>>>>>>> transaction.rollback();
> >>>>>>>>> e.printStackTrace();
> >>>>>>>>> }
> >>>>>>>>> }
> >>>>>>>>>
> >>>>>>>>> @SuppressWarnings("unchecked")
> >>>>>>>>> @Override
> >>>>>>>>> public List listParent() {
> >>>>>>>>> List courses = null;
> >>>>>>>>> try {
> >>>>>>>>> courses = session.createQuery("from Parent").list();
> >>>>>>>>> } catch (Exception e) {
> >>>>>>>>> e.printStackTrace();
> >>>>>>>>> }
> >>>>>>>>> return courses;
> >>>>>>>>> }
> >>>>>>>>>
> >>>>>>>>> @Override
> >>>>>>>>> public Parent listParentById(Long clId) {
> >>>>>>>>> Parent cl = null;
> >>>>>>>>> try {
> >>>>>>>>> cl = (Parent) session.get(Parent.class, clId);
> >>>>>>>>> } catch (Exception e) {
> >>>>>>>>> e.printStackTrace();
> >>>>>>>>> }
> >>>>>>>>> return cl;
> >>>>>>>>> }
> >>>>>>>>> }
> >>>>>>>>>
> >>>>>>>>> public class ParentAction extends ActionSupport implements
> >>>>>>>>> ModelDriven {
> >>>>>>>>>
> >>>>>>>>> private static final long serialVersionUID = -2662966220408285700L;
> >>>>>>>>> private Parent cl = new Parent();
> >>>>>>>>> private List clList = new ArrayList();
> >>>>>>>>> private ParentDAO clDAO = new ParentDAOImpl();
> >>>>>>>>>
> >>>>>>>>> @Override
> >>>>>>>>> public Parent getModel() {
> >>>>>>>>> return cl;
> >>>>>>>>> }
> >>>>>>>>>
> >>>>>>>>> public String saveOrUpdate()
> >>>>>>>>> {
> >>>>>>>>> clDAO.saveOrUpdateParent(cl);
> >>>>>>>>> return SUCCESS;
> >>>>>>>>> }
> >>>>>>>>>
> >>>>>>>>> public String save()
> >>>>>>>>> {
> >>>>>>>>> clDAO.saveParent(cl);
> >>>>>>>>> return SUCCESS;
> >>>>>>>>> }
> >>>>>>>>>
> >>>>>>>>> public String list()
> >>>>>>>>> {
> >>>>>>>>> clList = clDAO.listParent();
> >>>>>>>>> return SUCCESS;
> >>>>>>>>> }
> >>>>>>>>>
> >>>>>>>>> public String delete()
> >>>>>>>>> {
> >>>>>>>>> HttpServletRequest request = (HttpServletRequest)
> >>>>>>>>> ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
> >>>>>>>>> clDAO.deleteParent(Long.parseLong(request.getParameter("id")));
> >>>>>>>>> return SUCCESS;
> >>>>>>>>> }
> >>>>>>>>>
> >>>>>>>>> public String edit()
> >>>>>>>>> {
> >>>>>>>>> HttpServletRequest request = (HttpServletRequest)
> >>>>>>>>> ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
> >>>>>>>>> cl = clDAO.listParentById(Long.parseLong(request.getParameter("id")));
> >>>>>>>>> return SUCCESS;
> >>>>>>>>> }
> >>>>>>>>>
> >>>>>>>>> public Parent getParent() {
> >>>>>>>>> return cl;
> >>>>>>>>> }
> >>>>>>>>>
> >>>>>>>>> public void setParent(Parent cl) {
> >>>>>>>>> this.cl = cl;
> >>>>>>>>> }
> >>>>>>>>>
> >>>>>>>>> public List getParentList() {
> >>>>>>>>> return clList;
> >>>>>>>>> }
> >>>>>>>>>
> >>>>>>>>> public void setParentList(List clList) {
> >>>>>>>>> this.clList = clList;
> >>>>>>>>> }
> >>>>>>>>> }
> >>>>>>>>>
> >>>>>>>>> and finally the jsp page:
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>>>>>> "http://www.w3.org/TR/html4/loose.dtd">
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>
> >>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>
> >>>>>>>>>
> >>>>
> >>>>>>>>>
> >>>>
> >>>>
> >>>>>>>>>
> >>>> Child(s)
> >>>>>>>>>
> >>>>
> >>>>>>>>>
> >>>>>>>>>>>>>> class="oddeven">
> >>>>>>>>>
> >>>>
> >>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>
> >>>>>>>>>
> >>>>>>>>> Edit
> >>>>>>>>>
> >>>>
> >>>>>>>>>
> >>>>>>>>> Delete
> >>>>>>>>>
> >>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>
> >>>>>>>> --
> >>>>>>>> René Gielen
> >>>>>>>> IT-Neering.net
> >>>>>>>> Saarstrasse 100, 52062 Aachen, Germany
> >>>>>>>> Tel: +49-(0)241-4010770
> >>>>>>>> Fax: +49-(0)241-4010771
> >>>>>>>> Cel: +49-(0)163-2844164
> >>>>>>>> http://twitter.com/rgielen
> >>>>>>>>
> >>>>>>>> ---------------------------------------------------------------------
> >>>>>>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >>>>>>>> For additional commands, e-mail: user-help@struts.apache.org
> >>>>>>>>
> >>>>>>>>
> >>>>>>>
> >>>>>>> ---------------------------------------------------------------------
> >>>>>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >>>>>>> For additional commands, e-mail: user-help@struts.apache.org
> >>>>>>>
> >>>>>>
> >>>>>> --
> >>>>>> René Gielen
> >>>>>> IT-Neering.net
> >>>>>> Saarstrasse 100, 52062 Aachen, Germany
> >>>>>> Tel: +49-(0)241-4010770
> >>>>>> Fax: +49-(0)241-4010771
> >>>>>> Cel: +49-(0)163-2844164
> >>>>>> http://twitter.com/rgielen
> >>>>>>
> >>>>>> ---------------------------------------------------------------------
> >>>>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >>>>>> For additional commands, e-mail: user-help@struts.apache.org
> >>>>>>
> >>>>>
> >>>>> _________________________________________________________________
> >>>>> Découvrez comment SURFER DISCRETEMENT sur un site de rencontres !
> >>>>> http://clk.atdmt.com/FRM/go/206608211/direct/01/
> >>>> _________________________________________________________________
> >>>> Do you have a story that started on Hotmail? Tell us now
> >>>> http://clk.atdmt.com/UKM/go/195013117/direct/01/
> >>>> ---------------------------------------------------------------------
> >>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >>>> For additional commands, e-mail: user-help@struts.apache.org
> >>>>
> >>>
> >>> _________________________________________________________________
> >>> Consultez gratuitement vos emails Orange, Gmail, Free, ... directement dans HOTMAIL !
> >>> http://www.windowslive.fr/hotmail/agregation/
> >> _________________________________________________________________
> >> Do you have a story that started on Hotmail? Tell us now
> >> http://clk.atdmt.com/UKM/go/195013117/direct/01/
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >> For additional commands, e-mail: user-help@struts.apache.org
> >>
> >
> > _________________________________________________________________
> > Découvrez comment SURFER DISCRETEMENT sur un site de rencontres !
> > http://clk.atdmt.com/FRM/go/206608211/direct/01/ 
> _________________________________________________________________
> Got a cool Hotmail story? Tell us now
> http://clk.atdmt.com/UKM/go/195013117/direct/01/
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
 		 	   		  
_________________________________________________________________
Consultez gratuitement vos emails Orange, Gmail, Free, ... directement dans HOTMAIL !
http://www.windowslive.fr/hotmail/agregation/

RE: CRUD with a OneToMany association under Struts 2 / Hibernate 3

Posted by bruno grandjean <br...@live.fr>.
Here is my Child class definition:

@Entity
@Table(name="CHILD")
public class Child {
private Long id; 
private String name; 
@Id
@GeneratedValue
@Column(name="CHILD_ID") 
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@Column(name="NAME")
public String getName() { 
return name;
}
public void setName(String val) {
name = val;
} 
}

 

and Parent definition:

@Entity
@Table(name="PARENT")
public class Parent {
private Long id;
private String name;
private Set<Child> values = new HashSet<Child>(); 
@Id
@GeneratedValue
@Column(name="PARENT_ID") 
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@Column(name="NAME")
public String getName() { 
return name;
}
public void setName(String val) {
name = val;
} 
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) 
@JoinTable(name = "PARENT_CHILD", joinColumns = { @JoinColumn(name = "PARENT_ID") }, inverseJoinColumns = { @JoinColumn(name = "CHILD_ID") }) 
public Set<Child> getValues() { 
return values;
}
public Child getValues(Long idx) { // NEVER CALLED!
for ( Iterator<Child> iter = values.iterator(); iter.hasNext();) {
Child c = (Child) iter.next(); 
if (c.getId() == idx) return c;
} 
return null;
}
public void setValues(Set<Child> lst) {
values = lst; 
}
}

 

So I do not understand the ognl.NoSuchPropertyException I got after submission..


 
> From: apinder@hotmail.co.uk
> To: user@struts.apache.org
> Subject: RE: CRUD with a OneToMany association under Struts 2 / Hibernate 3
> Date: Thu, 1 Apr 2010 13:54:58 +0100
> 
> 
> 
> set the rootlogger to warn
> 
> log4j.rootLogger=warn, stdout
> 
> rather than debug
> 
> you should only get a parameterinterceptor log entry every time you post something to the server
> 
> ----------------------------------------
> > From: brgrandjean@live.fr
> > To: user@struts.apache.org
> > Subject: RE: CRUD with a OneToMany association under Struts 2 / Hibernate 3
> > Date: Thu, 1 Apr 2010 14:51:40 +0200
> >
> >
> > thks adam but I got now thousand & thousand of lines
> >
> > I am afraid that I won't be able to read its before the end of the world in 2012..
> >
> >
> >
> > I saw very quicky an exception at the beginning..
> >
> > How can I limit this huge quantity of lines?
> >
> >
> >
> > here is my log4j.properties file:
> >
> >
> >
> > log4j.appender.stdout=org.apache.log4j.ConsoleAppender
> > log4j.appender.stdout.Target=System.out
> > log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
> > log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
> > log4j.rootLogger=debug, stdout
> > log4j.logger.com.opensymphony.xwork2.interceptor.ParametersInterceptor=debug
> >
> >
> >
> >
> >
> >
> >
> >> From: apinder@hotmail.co.uk
> >> To: user@struts.apache.org
> >> Subject: RE: CRUD with a OneToMany association under Struts 2 / Hibernate 3
> >> Date: Thu, 1 Apr 2010 12:57:39 +0100
> >>
> >>
> >>
> >>
> >> in log4j.properties file (same location as struts.xml and hibernate config files)
> >>
> >> add
> >>
> >> log4j.logger.com.opensymphony.xwork2.interceptor.ParametersInterceptor=debug
> >>
> >> this will output param name/value pairs being posted from your page.
> >>
> >>
> >>
> >> ----------------------------------------
> >>> From: brgrandjean@live.fr
> >>> To: user@struts.apache.org
> >>> Subject: RE: CRUD with a OneToMany association under Struts 2 / Hibernate 3
> >>> Date: Thu, 1 Apr 2010 13:54:33 +0200
> >>>
> >>>
> >>> Dear Adam,
> >>>
> >>>
> >>>
> >>> I just added a public Child getValues(int idx) in the Parent class definition but it is never called.
> >>>
> >>>
> >>>
> >>> Could u explain to me where and how can I turn on the parameterinterceptor logging? In the struts.xml file?
> >>>
> >>>
> >>>
> >>> thks a lot
> >>>
> >>>
> >>> bruno
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>> From: apinder@hotmail.co.uk
> >>>> To: user@struts.apache.org
> >>>> Subject: RE: CRUD with a OneToMany association under Struts 2 / Hibernate 3
> >>>> Date: Thu, 1 Apr 2010 12:18:48 +0100
> >>>>
> >>>>
> >>>>
> >>>>
> >>>> turn on the parameterinterceptor logging and make sure as mentioned that
> >>>>
> >>>> 1) the values you expect for each child are being sent to the server (id and name)
> >>>> 2) the parameter names are correct for setting each child
> >>>>
> >>>> i had some issues getting lists of items to be updated by form submission alone.
> >>>>
> >>>> for example does your parent object have a getValues method taking an index value
> >>>>
> >>>> getParent().getValues(1).setId(1)
> >>>> getParent().getValues(1).setName("bob")
> >>>>
> >>>> would be called by parameterinterceptor
> >>>>
> >>>>
> >>>> ----------------------------------------
> >>>>> From: brgrandjean@live.fr
> >>>>> To: user@struts.apache.org
> >>>>> Subject: RE: CRUD with a OneToMany association under Struts 2 / Hibernate 3
> >>>>> Date: Thu, 1 Apr 2010 12:16:09 +0200
> >>>>>
> >>>>>
> >>>>> Dear René
> >>>>>
> >>>>>
> >>>>>
> >>>>> I changed my jsp page so as to integrate the following block:
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>> which generates the following html code:
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>> I can display my complete Child Set but I got the same result after updating: my Child Set is empty.
> >>>>>
> >>>>>
> >>>>>
> >>>>> Is that necessary to modify my ParentAction as well? If yes what to do?
> >>>>>
> >>>>>
> >>>>>
> >>>>> public class ParentAction extends ActionSupport implements ModelDriven {
> >>>>>
> >>>>> private static final long serialVersionUID = -2662966220408285700L;
> >>>>> private Parent cl = new Parent();
> >>>>> private List clList = new ArrayList();
> >>>>> private ParentDAO clDAO = new ParentDAOImpl();
> >>>>>
> >>>>> @Override
> >>>>> public Parent getModel() {
> >>>>> return cl;
> >>>>> }
> >>>>>
> >>>>> public String saveOrUpdate()
> >>>>> { // cl.values is empty here!!
> >>>>> clDAO.saveOrUpdateParent(cl);
> >>>>> return SUCCESS;
> >>>>> }
> >>>>>
> >>>>> public String save()
> >>>>> {
> >>>>> clDAO.saveParent(cl);
> >>>>> return SUCCESS;
> >>>>> }
> >>>>>
> >>>>> public String list()
> >>>>> {
> >>>>> clList = clDAO.listParent();
> >>>>> return SUCCESS;
> >>>>> }
> >>>>>
> >>>>> public String delete()
> >>>>> {
> >>>>> HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
> >>>>> clDAO.deleteParent(Long.parseLong(request.getParameter("id")));
> >>>>> return SUCCESS;
> >>>>> }
> >>>>>
> >>>>> public String edit()
> >>>>> { // cl.values contains some valid Child elements here!!
> >>>>> HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
> >>>>> cl = clDAO.listParentById(Long.parseLong(request.getParameter("id")));
> >>>>> }
> >>>>> return SUCCESS;
> >>>>> }
> >>>>>
> >>>>> public Parent getParent() {
> >>>>> return cl;
> >>>>> }
> >>>>>
> >>>>> public void setParent(Parent cl) {
> >>>>> this.cl = cl;
> >>>>> }
> >>>>>
> >>>>> public List getParentList() {
> >>>>> return clList;
> >>>>> }
> >>>>>
> >>>>> public void setParentList(List clList) {
> >>>>> this.clList = clList;
> >>>>> }
> >>>>> }
> >>>>>
> >>>>>
> >>>>>
> >>>>>> Date: Thu, 1 Apr 2010 11:30:23 +0200
> >>>>>> From: gielen@it-neering.net
> >>>>>> To: user@struts.apache.org
> >>>>>> Subject: Re: CRUD with a OneToMany association under Struts 2 / Hibernate 3
> >>>>>>
> >>>>>> Given the model you presented in the first post, your problem seems to
> >>>>>> be that the posted values have not the correct name for the children's
> >>>>>> form fields. The parameters names you would need are
> >>>>>>
> >>>>>> id
> >>>>>> name
> >>>>>> values[0].id
> >>>>>> values[0].name
> >>>>>> values[1].id
> >>>>>> values[2].name
> >>>>>> ...
> >>>>>>
> >>>>>> for the parameters interceptor to work properly when applying the posted
> >>>>>> values.
> >>>>>>
> >>>>>> See here for more details:
> >>>>>> http://struts.apache.org/2.1.8/docs/tabular-inputs.html
> >>>>>>
> >>>>>> - René
> >>>>>>
> >>>>>> bruno grandjean schrieb:
> >>>>>>> Dear Rene,
> >>>>>>>
> >>>>>>> Thks a lot for replying to me because I am feeling a little bit alone with
> >>>>>>> my CRUD ;-). In fact I am trying to build a dynamic MetaCrud.
> >>>>>>> My pb is simple: in the same jsp page I would like to update a Parent
> >>>>>>> object
> >>>>>>> and its Childs (values):
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>>>> name="name" label="Nom" />
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>> From an existing Parent object with many Childs objects I can easily modify
> >>>>>>> parent.name for instance but the collection of Child objects (values) is
> >>>>>>> always empty in the ParentAction (saveOrUpdate() method) after submitting.
> >>>>>>> However I can display each values[i].name in the jsp page with the correct
> >>>>>>> value.
> >>>>>>> So it is not an issue with Hibernate but with the jsp or ModelDriven
> >>>>>>> interface I don't know..Do you have any idea?
> >>>>>>> Basically I was not able to find a struts or spring documentation about
> >>>>>>> CRUD
> >>>>>>> & association between two entities on the same jsp page.
> >>>>>>> best regards
> >>>>>>> bruno
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>> --------------------------------------------------
> >>>>>>> From: "Rene Gielen"
> >>>>>>> Sent: Wednesday, March 31, 2010 7:12 PM
> >>>>>>> To: "Struts Users Mailing List"
> >>>>>>> Subject: Re: CRUD with a OneToMany association under Struts 2 / Hibernate 3
> >>>>>>>
> >>>>>>>> I'm not sure if I understand what your actual question is, nor whether
> >>>>>>>> it is particularly Struts 2 related (rather than just Hibernate) - but
> >>>>>>>> you might want to have a look in the CRUD demo section of the Struts 2
> >>>>>>>> showcase application. Maybe you will also find this demo useful:
> >>>>>>>> http://github.com/rgielen/struts2crudevolutiondemo
> >>>>>>>>
> >>>>>>>> - René
> >>>>>>>>
> >>>>>>>> bruno grandjean schrieb:
> >>>>>>>>> Hi
> >>>>>>>>>
> >>>>>>>>> I am trying to implement a simple CRUD with a OneToMany association
> >>>>>>>>> under Struts 2 / Hibernate 3.
> >>>>>>>>> I have two entities Parent and Child:
> >>>>>>>>>
> >>>>>>>>> @Entity
> >>>>>>>>> @Table(name="PARENT")
> >>>>>>>>> public class Parent {
> >>>>>>>>> private Long id;
> >>>>>>>>> private Set values = new HashSet();
> >>>>>>>>> ..
> >>>>>>>>> @Entity
> >>>>>>>>> @Table(name="CHILD")
> >>>>>>>>> public class Child {
> >>>>>>>>> private Long id;
> >>>>>>>>> private String name;
> >>>>>>>>> ..
> >>>>>>>>>
> >>>>>>>>> I can easily create, delete Parent or read the Child Set (values) but
> >>>>>>>>> it is impossible to update Child Set.
> >>>>>>>>> The jsp page (see below) reinit the values Set, no record after
> >>>>>>>>> updating!
> >>>>>>>>> Could u explain to me what's wrong?
> >>>>>>>>>
> >>>>>>>>> here are my code:
> >>>>>>>>>
> >>>>>>>>> @Entity
> >>>>>>>>> @Table(name="PARENT")
> >>>>>>>>> public class Parent {
> >>>>>>>>> private Long id;
> >>>>>>>>> private Set values = new HashSet();
> >>>>>>>>> @Id
> >>>>>>>>> @GeneratedValue
> >>>>>>>>> @Column(name="PARENT_ID")
> >>>>>>>>> public Long getId() {
> >>>>>>>>> return id;
> >>>>>>>>> }
> >>>>>>>>> public void setId(Long id) {
> >>>>>>>>> this.id = id;
> >>>>>>>>> }
> >>>>>>>>> @ManyToMany(fetch = FetchType.EAGER)
> >>>>>>>>> @JoinTable(name = "PARENT_CHILD", joinColumns = { @JoinColumn(name =
> >>>>>>>>> "PARENT_ID") }, inverseJoinColumns = { @JoinColumn(name = "CHILD_ID") })
> >>>>>>>>> public Set getValues() {
> >>>>>>>>> return values;
> >>>>>>>>> }
> >>>>>>>>> public void setValues(Set lst) {
> >>>>>>>>> values = lst;
> >>>>>>>>> }
> >>>>>>>>> }
> >>>>>>>>>
> >>>>>>>>> @Entity
> >>>>>>>>> @Table(name="CHILD")
> >>>>>>>>> public class Child {
> >>>>>>>>> private Long id;
> >>>>>>>>> private String name;
> >>>>>>>>> @Id
> >>>>>>>>> @GeneratedValue
> >>>>>>>>> @Column(name="CHILD_ID")
> >>>>>>>>> public Long getId() {
> >>>>>>>>> return id;
> >>>>>>>>> }
> >>>>>>>>> public void setId(Long id) {
> >>>>>>>>> this.id = id;
> >>>>>>>>> }
> >>>>>>>>> @Column(name="NAME")
> >>>>>>>>> public String getName() {
> >>>>>>>>> return name;
> >>>>>>>>> }
> >>>>>>>>> public void setName(String val) {
> >>>>>>>>> name = val;
> >>>>>>>>> }
> >>>>>>>>> }
> >>>>>>>>>
> >>>>>>>>> public interface ParentDAO {
> >>>>>>>>> public void saveOrUpdateParent(Parent cl);
> >>>>>>>>> public void saveParent(Parent cl);
> >>>>>>>>> public List listParent();
> >>>>>>>>> public Parent listParentById(Long clId);
> >>>>>>>>> public void deleteParent(Long clId);
> >>>>>>>>> }
> >>>>>>>>>
> >>>>>>>>> public class ParentDAOImpl implements ParentDAO {
> >>>>>>>>> @SessionTarget
> >>>>>>>>> Session session;
> >>>>>>>>> @TransactionTarget
> >>>>>>>>> Transaction transaction;
> >>>>>>>>>
> >>>>>>>>> @Override
> >>>>>>>>> public void saveOrUpdateParent(Parent cl) {
> >>>>>>>>> try {
> >>>>>>>>> session.saveOrUpdate(cl);
> >>>>>>>>> } catch (Exception e) {
> >>>>>>>>> transaction.rollback();
> >>>>>>>>> e.printStackTrace();
> >>>>>>>>> }
> >>>>>>>>> }
> >>>>>>>>>
> >>>>>>>>> @Override
> >>>>>>>>> public void saveParent(Parent cl) {
> >>>>>>>>> try {
> >>>>>>>>> session.save(cl);
> >>>>>>>>> } catch (Exception e) {
> >>>>>>>>> transaction.rollback();
> >>>>>>>>> e.printStackTrace();
> >>>>>>>>> }
> >>>>>>>>> }
> >>>>>>>>>
> >>>>>>>>> @Override
> >>>>>>>>> public void deleteParent(Long clId) {
> >>>>>>>>> try {
> >>>>>>>>> Parent cl = (Parent) session.get(Parent.class, clId);
> >>>>>>>>> session.delete(cl);
> >>>>>>>>> } catch (Exception e) {
> >>>>>>>>> transaction.rollback();
> >>>>>>>>> e.printStackTrace();
> >>>>>>>>> }
> >>>>>>>>> }
> >>>>>>>>>
> >>>>>>>>> @SuppressWarnings("unchecked")
> >>>>>>>>> @Override
> >>>>>>>>> public List listParent() {
> >>>>>>>>> List courses = null;
> >>>>>>>>> try {
> >>>>>>>>> courses = session.createQuery("from Parent").list();
> >>>>>>>>> } catch (Exception e) {
> >>>>>>>>> e.printStackTrace();
> >>>>>>>>> }
> >>>>>>>>> return courses;
> >>>>>>>>> }
> >>>>>>>>>
> >>>>>>>>> @Override
> >>>>>>>>> public Parent listParentById(Long clId) {
> >>>>>>>>> Parent cl = null;
> >>>>>>>>> try {
> >>>>>>>>> cl = (Parent) session.get(Parent.class, clId);
> >>>>>>>>> } catch (Exception e) {
> >>>>>>>>> e.printStackTrace();
> >>>>>>>>> }
> >>>>>>>>> return cl;
> >>>>>>>>> }
> >>>>>>>>> }
> >>>>>>>>>
> >>>>>>>>> public class ParentAction extends ActionSupport implements
> >>>>>>>>> ModelDriven {
> >>>>>>>>>
> >>>>>>>>> private static final long serialVersionUID = -2662966220408285700L;
> >>>>>>>>> private Parent cl = new Parent();
> >>>>>>>>> private List clList = new ArrayList();
> >>>>>>>>> private ParentDAO clDAO = new ParentDAOImpl();
> >>>>>>>>>
> >>>>>>>>> @Override
> >>>>>>>>> public Parent getModel() {
> >>>>>>>>> return cl;
> >>>>>>>>> }
> >>>>>>>>>
> >>>>>>>>> public String saveOrUpdate()
> >>>>>>>>> {
> >>>>>>>>> clDAO.saveOrUpdateParent(cl);
> >>>>>>>>> return SUCCESS;
> >>>>>>>>> }
> >>>>>>>>>
> >>>>>>>>> public String save()
> >>>>>>>>> {
> >>>>>>>>> clDAO.saveParent(cl);
> >>>>>>>>> return SUCCESS;
> >>>>>>>>> }
> >>>>>>>>>
> >>>>>>>>> public String list()
> >>>>>>>>> {
> >>>>>>>>> clList = clDAO.listParent();
> >>>>>>>>> return SUCCESS;
> >>>>>>>>> }
> >>>>>>>>>
> >>>>>>>>> public String delete()
> >>>>>>>>> {
> >>>>>>>>> HttpServletRequest request = (HttpServletRequest)
> >>>>>>>>> ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
> >>>>>>>>> clDAO.deleteParent(Long.parseLong(request.getParameter("id")));
> >>>>>>>>> return SUCCESS;
> >>>>>>>>> }
> >>>>>>>>>
> >>>>>>>>> public String edit()
> >>>>>>>>> {
> >>>>>>>>> HttpServletRequest request = (HttpServletRequest)
> >>>>>>>>> ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
> >>>>>>>>> cl = clDAO.listParentById(Long.parseLong(request.getParameter("id")));
> >>>>>>>>> return SUCCESS;
> >>>>>>>>> }
> >>>>>>>>>
> >>>>>>>>> public Parent getParent() {
> >>>>>>>>> return cl;
> >>>>>>>>> }
> >>>>>>>>>
> >>>>>>>>> public void setParent(Parent cl) {
> >>>>>>>>> this.cl = cl;
> >>>>>>>>> }
> >>>>>>>>>
> >>>>>>>>> public List getParentList() {
> >>>>>>>>> return clList;
> >>>>>>>>> }
> >>>>>>>>>
> >>>>>>>>> public void setParentList(List clList) {
> >>>>>>>>> this.clList = clList;
> >>>>>>>>> }
> >>>>>>>>> }
> >>>>>>>>>
> >>>>>>>>> and finally the jsp page:
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>>>>>> "http://www.w3.org/TR/html4/loose.dtd">
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>
> >>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>
> >>>>>>>>>
> >>>>
> >>>>>>>>>
> >>>>
> >>>>
> >>>>>>>>>
> >>>> Child(s)
> >>>>>>>>>
> >>>>
> >>>>>>>>>
> >>>>>>>>>>>>>> class="oddeven">
> >>>>>>>>>
> >>>>
> >>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>
> >>>>>>>>>
> >>>>>>>>> Edit
> >>>>>>>>>
> >>>>
> >>>>>>>>>
> >>>>>>>>> Delete
> >>>>>>>>>
> >>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>
> >>>>>>>> --
> >>>>>>>> René Gielen
> >>>>>>>> IT-Neering.net
> >>>>>>>> Saarstrasse 100, 52062 Aachen, Germany
> >>>>>>>> Tel: +49-(0)241-4010770
> >>>>>>>> Fax: +49-(0)241-4010771
> >>>>>>>> Cel: +49-(0)163-2844164
> >>>>>>>> http://twitter.com/rgielen
> >>>>>>>>
> >>>>>>>> ---------------------------------------------------------------------
> >>>>>>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >>>>>>>> For additional commands, e-mail: user-help@struts.apache.org
> >>>>>>>>
> >>>>>>>>
> >>>>>>>
> >>>>>>> ---------------------------------------------------------------------
> >>>>>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >>>>>>> For additional commands, e-mail: user-help@struts.apache.org
> >>>>>>>
> >>>>>>
> >>>>>> --
> >>>>>> René Gielen
> >>>>>> IT-Neering.net
> >>>>>> Saarstrasse 100, 52062 Aachen, Germany
> >>>>>> Tel: +49-(0)241-4010770
> >>>>>> Fax: +49-(0)241-4010771
> >>>>>> Cel: +49-(0)163-2844164
> >>>>>> http://twitter.com/rgielen
> >>>>>>
> >>>>>> ---------------------------------------------------------------------
> >>>>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >>>>>> For additional commands, e-mail: user-help@struts.apache.org
> >>>>>>
> >>>>>
> >>>>> _________________________________________________________________
> >>>>> Découvrez comment SURFER DISCRETEMENT sur un site de rencontres !
> >>>>> http://clk.atdmt.com/FRM/go/206608211/direct/01/
> >>>> _________________________________________________________________
> >>>> Do you have a story that started on Hotmail? Tell us now
> >>>> http://clk.atdmt.com/UKM/go/195013117/direct/01/
> >>>> ---------------------------------------------------------------------
> >>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >>>> For additional commands, e-mail: user-help@struts.apache.org
> >>>>
> >>>
> >>> _________________________________________________________________
> >>> Consultez gratuitement vos emails Orange, Gmail, Free, ... directement dans HOTMAIL !
> >>> http://www.windowslive.fr/hotmail/agregation/
> >> _________________________________________________________________
> >> Do you have a story that started on Hotmail? Tell us now
> >> http://clk.atdmt.com/UKM/go/195013117/direct/01/
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >> For additional commands, e-mail: user-help@struts.apache.org
> >>
> >
> > _________________________________________________________________
> > Découvrez comment SURFER DISCRETEMENT sur un site de rencontres !
> > http://clk.atdmt.com/FRM/go/206608211/direct/01/ 
> _________________________________________________________________
> Got a cool Hotmail story? Tell us now
> http://clk.atdmt.com/UKM/go/195013117/direct/01/
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
 		 	   		  
_________________________________________________________________
Découvrez comment SURFER DISCRETEMENT sur un site de rencontres !
http://clk.atdmt.com/FRM/go/206608211/direct/01/

RE: CRUD with a OneToMany association under Struts 2 / Hibernate 3

Posted by adam pinder <ap...@hotmail.co.uk>.
 
set the rootlogger to warn
 
log4j.rootLogger=warn, stdout

rather than debug
 
you should only get a parameterinterceptor log entry every time you post something to the server

----------------------------------------
> From: brgrandjean@live.fr
> To: user@struts.apache.org
> Subject: RE: CRUD with a OneToMany association under Struts 2 / Hibernate 3
> Date: Thu, 1 Apr 2010 14:51:40 +0200
>
>
> thks adam but I got now thousand & thousand of lines
>
> I am afraid that I won't be able to read its before the end of the world in 2012..
>
>
>
> I saw very quicky an exception at the beginning..
>
> How can I limit this huge quantity of lines?
>
>
>
> here is my log4j.properties file:
>
>
>
> log4j.appender.stdout=org.apache.log4j.ConsoleAppender
> log4j.appender.stdout.Target=System.out
> log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
> log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
> log4j.rootLogger=debug, stdout
> log4j.logger.com.opensymphony.xwork2.interceptor.ParametersInterceptor=debug
>
>
>
>
>
>
>
>> From: apinder@hotmail.co.uk
>> To: user@struts.apache.org
>> Subject: RE: CRUD with a OneToMany association under Struts 2 / Hibernate 3
>> Date: Thu, 1 Apr 2010 12:57:39 +0100
>>
>>
>>
>>
>> in log4j.properties file (same location as struts.xml and hibernate config files)
>>
>> add
>>
>> log4j.logger.com.opensymphony.xwork2.interceptor.ParametersInterceptor=debug
>>
>> this will output param name/value pairs being posted from your page.
>>
>>
>>
>> ----------------------------------------
>>> From: brgrandjean@live.fr
>>> To: user@struts.apache.org
>>> Subject: RE: CRUD with a OneToMany association under Struts 2 / Hibernate 3
>>> Date: Thu, 1 Apr 2010 13:54:33 +0200
>>>
>>>
>>> Dear Adam,
>>>
>>>
>>>
>>> I just added a public Child getValues(int idx) in the Parent class definition but it is never called.
>>>
>>>
>>>
>>> Could u explain to me where and how can I turn on the parameterinterceptor logging? In the struts.xml file?
>>>
>>>
>>>
>>> thks a lot
>>>
>>>
>>> bruno
>>>
>>>
>>>
>>>
>>>
>>>> From: apinder@hotmail.co.uk
>>>> To: user@struts.apache.org
>>>> Subject: RE: CRUD with a OneToMany association under Struts 2 / Hibernate 3
>>>> Date: Thu, 1 Apr 2010 12:18:48 +0100
>>>>
>>>>
>>>>
>>>>
>>>> turn on the parameterinterceptor logging and make sure as mentioned that
>>>>
>>>> 1) the values you expect for each child are being sent to the server (id and name)
>>>> 2) the parameter names are correct for setting each child
>>>>
>>>> i had some issues getting lists of items to be updated by form submission alone.
>>>>
>>>> for example does your parent object have a getValues method taking an index value
>>>>
>>>> getParent().getValues(1).setId(1)
>>>> getParent().getValues(1).setName("bob")
>>>>
>>>> would be called by parameterinterceptor
>>>>
>>>>
>>>> ----------------------------------------
>>>>> From: brgrandjean@live.fr
>>>>> To: user@struts.apache.org
>>>>> Subject: RE: CRUD with a OneToMany association under Struts 2 / Hibernate 3
>>>>> Date: Thu, 1 Apr 2010 12:16:09 +0200
>>>>>
>>>>>
>>>>> Dear René
>>>>>
>>>>>
>>>>>
>>>>> I changed my jsp page so as to integrate the following block:
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> which generates the following html code:
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> I can display my complete Child Set but I got the same result after updating: my Child Set is empty.
>>>>>
>>>>>
>>>>>
>>>>> Is that necessary to modify my ParentAction as well? If yes what to do?
>>>>>
>>>>>
>>>>>
>>>>> public class ParentAction extends ActionSupport implements ModelDriven {
>>>>>
>>>>> private static final long serialVersionUID = -2662966220408285700L;
>>>>> private Parent cl = new Parent();
>>>>> private List clList = new ArrayList();
>>>>> private ParentDAO clDAO = new ParentDAOImpl();
>>>>>
>>>>> @Override
>>>>> public Parent getModel() {
>>>>> return cl;
>>>>> }
>>>>>
>>>>> public String saveOrUpdate()
>>>>> { // cl.values is empty here!!
>>>>> clDAO.saveOrUpdateParent(cl);
>>>>> return SUCCESS;
>>>>> }
>>>>>
>>>>> public String save()
>>>>> {
>>>>> clDAO.saveParent(cl);
>>>>> return SUCCESS;
>>>>> }
>>>>>
>>>>> public String list()
>>>>> {
>>>>> clList = clDAO.listParent();
>>>>> return SUCCESS;
>>>>> }
>>>>>
>>>>> public String delete()
>>>>> {
>>>>> HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
>>>>> clDAO.deleteParent(Long.parseLong(request.getParameter("id")));
>>>>> return SUCCESS;
>>>>> }
>>>>>
>>>>> public String edit()
>>>>> { // cl.values contains some valid Child elements here!!
>>>>> HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
>>>>> cl = clDAO.listParentById(Long.parseLong(request.getParameter("id")));
>>>>> }
>>>>> return SUCCESS;
>>>>> }
>>>>>
>>>>> public Parent getParent() {
>>>>> return cl;
>>>>> }
>>>>>
>>>>> public void setParent(Parent cl) {
>>>>> this.cl = cl;
>>>>> }
>>>>>
>>>>> public List getParentList() {
>>>>> return clList;
>>>>> }
>>>>>
>>>>> public void setParentList(List clList) {
>>>>> this.clList = clList;
>>>>> }
>>>>> }
>>>>>
>>>>>
>>>>>
>>>>>> Date: Thu, 1 Apr 2010 11:30:23 +0200
>>>>>> From: gielen@it-neering.net
>>>>>> To: user@struts.apache.org
>>>>>> Subject: Re: CRUD with a OneToMany association under Struts 2 / Hibernate 3
>>>>>>
>>>>>> Given the model you presented in the first post, your problem seems to
>>>>>> be that the posted values have not the correct name for the children's
>>>>>> form fields. The parameters names you would need are
>>>>>>
>>>>>> id
>>>>>> name
>>>>>> values[0].id
>>>>>> values[0].name
>>>>>> values[1].id
>>>>>> values[2].name
>>>>>> ...
>>>>>>
>>>>>> for the parameters interceptor to work properly when applying the posted
>>>>>> values.
>>>>>>
>>>>>> See here for more details:
>>>>>> http://struts.apache.org/2.1.8/docs/tabular-inputs.html
>>>>>>
>>>>>> - René
>>>>>>
>>>>>> bruno grandjean schrieb:
>>>>>>> Dear Rene,
>>>>>>>
>>>>>>> Thks a lot for replying to me because I am feeling a little bit alone with
>>>>>>> my CRUD ;-). In fact I am trying to build a dynamic MetaCrud.
>>>>>>> My pb is simple: in the same jsp page I would like to update a Parent
>>>>>>> object
>>>>>>> and its Childs (values):
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>>>> name="name" label="Nom" />
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> From an existing Parent object with many Childs objects I can easily modify
>>>>>>> parent.name for instance but the collection of Child objects (values) is
>>>>>>> always empty in the ParentAction (saveOrUpdate() method) after submitting.
>>>>>>> However I can display each values[i].name in the jsp page with the correct
>>>>>>> value.
>>>>>>> So it is not an issue with Hibernate but with the jsp or ModelDriven
>>>>>>> interface I don't know..Do you have any idea?
>>>>>>> Basically I was not able to find a struts or spring documentation about
>>>>>>> CRUD
>>>>>>> & association between two entities on the same jsp page.
>>>>>>> best regards
>>>>>>> bruno
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> --------------------------------------------------
>>>>>>> From: "Rene Gielen"
>>>>>>> Sent: Wednesday, March 31, 2010 7:12 PM
>>>>>>> To: "Struts Users Mailing List"
>>>>>>> Subject: Re: CRUD with a OneToMany association under Struts 2 / Hibernate 3
>>>>>>>
>>>>>>>> I'm not sure if I understand what your actual question is, nor whether
>>>>>>>> it is particularly Struts 2 related (rather than just Hibernate) - but
>>>>>>>> you might want to have a look in the CRUD demo section of the Struts 2
>>>>>>>> showcase application. Maybe you will also find this demo useful:
>>>>>>>> http://github.com/rgielen/struts2crudevolutiondemo
>>>>>>>>
>>>>>>>> - René
>>>>>>>>
>>>>>>>> bruno grandjean schrieb:
>>>>>>>>> Hi
>>>>>>>>>
>>>>>>>>> I am trying to implement a simple CRUD with a OneToMany association
>>>>>>>>> under Struts 2 / Hibernate 3.
>>>>>>>>> I have two entities Parent and Child:
>>>>>>>>>
>>>>>>>>> @Entity
>>>>>>>>> @Table(name="PARENT")
>>>>>>>>> public class Parent {
>>>>>>>>> private Long id;
>>>>>>>>> private Set values = new HashSet();
>>>>>>>>> ..
>>>>>>>>> @Entity
>>>>>>>>> @Table(name="CHILD")
>>>>>>>>> public class Child {
>>>>>>>>> private Long id;
>>>>>>>>> private String name;
>>>>>>>>> ..
>>>>>>>>>
>>>>>>>>> I can easily create, delete Parent or read the Child Set (values) but
>>>>>>>>> it is impossible to update Child Set.
>>>>>>>>> The jsp page (see below) reinit the values Set, no record after
>>>>>>>>> updating!
>>>>>>>>> Could u explain to me what's wrong?
>>>>>>>>>
>>>>>>>>> here are my code:
>>>>>>>>>
>>>>>>>>> @Entity
>>>>>>>>> @Table(name="PARENT")
>>>>>>>>> public class Parent {
>>>>>>>>> private Long id;
>>>>>>>>> private Set values = new HashSet();
>>>>>>>>> @Id
>>>>>>>>> @GeneratedValue
>>>>>>>>> @Column(name="PARENT_ID")
>>>>>>>>> public Long getId() {
>>>>>>>>> return id;
>>>>>>>>> }
>>>>>>>>> public void setId(Long id) {
>>>>>>>>> this.id = id;
>>>>>>>>> }
>>>>>>>>> @ManyToMany(fetch = FetchType.EAGER)
>>>>>>>>> @JoinTable(name = "PARENT_CHILD", joinColumns = { @JoinColumn(name =
>>>>>>>>> "PARENT_ID") }, inverseJoinColumns = { @JoinColumn(name = "CHILD_ID") })
>>>>>>>>> public Set getValues() {
>>>>>>>>> return values;
>>>>>>>>> }
>>>>>>>>> public void setValues(Set lst) {
>>>>>>>>> values = lst;
>>>>>>>>> }
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>> @Entity
>>>>>>>>> @Table(name="CHILD")
>>>>>>>>> public class Child {
>>>>>>>>> private Long id;
>>>>>>>>> private String name;
>>>>>>>>> @Id
>>>>>>>>> @GeneratedValue
>>>>>>>>> @Column(name="CHILD_ID")
>>>>>>>>> public Long getId() {
>>>>>>>>> return id;
>>>>>>>>> }
>>>>>>>>> public void setId(Long id) {
>>>>>>>>> this.id = id;
>>>>>>>>> }
>>>>>>>>> @Column(name="NAME")
>>>>>>>>> public String getName() {
>>>>>>>>> return name;
>>>>>>>>> }
>>>>>>>>> public void setName(String val) {
>>>>>>>>> name = val;
>>>>>>>>> }
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>> public interface ParentDAO {
>>>>>>>>> public void saveOrUpdateParent(Parent cl);
>>>>>>>>> public void saveParent(Parent cl);
>>>>>>>>> public List listParent();
>>>>>>>>> public Parent listParentById(Long clId);
>>>>>>>>> public void deleteParent(Long clId);
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>> public class ParentDAOImpl implements ParentDAO {
>>>>>>>>> @SessionTarget
>>>>>>>>> Session session;
>>>>>>>>> @TransactionTarget
>>>>>>>>> Transaction transaction;
>>>>>>>>>
>>>>>>>>> @Override
>>>>>>>>> public void saveOrUpdateParent(Parent cl) {
>>>>>>>>> try {
>>>>>>>>> session.saveOrUpdate(cl);
>>>>>>>>> } catch (Exception e) {
>>>>>>>>> transaction.rollback();
>>>>>>>>> e.printStackTrace();
>>>>>>>>> }
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>> @Override
>>>>>>>>> public void saveParent(Parent cl) {
>>>>>>>>> try {
>>>>>>>>> session.save(cl);
>>>>>>>>> } catch (Exception e) {
>>>>>>>>> transaction.rollback();
>>>>>>>>> e.printStackTrace();
>>>>>>>>> }
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>> @Override
>>>>>>>>> public void deleteParent(Long clId) {
>>>>>>>>> try {
>>>>>>>>> Parent cl = (Parent) session.get(Parent.class, clId);
>>>>>>>>> session.delete(cl);
>>>>>>>>> } catch (Exception e) {
>>>>>>>>> transaction.rollback();
>>>>>>>>> e.printStackTrace();
>>>>>>>>> }
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>> @SuppressWarnings("unchecked")
>>>>>>>>> @Override
>>>>>>>>> public List listParent() {
>>>>>>>>> List courses = null;
>>>>>>>>> try {
>>>>>>>>> courses = session.createQuery("from Parent").list();
>>>>>>>>> } catch (Exception e) {
>>>>>>>>> e.printStackTrace();
>>>>>>>>> }
>>>>>>>>> return courses;
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>> @Override
>>>>>>>>> public Parent listParentById(Long clId) {
>>>>>>>>> Parent cl = null;
>>>>>>>>> try {
>>>>>>>>> cl = (Parent) session.get(Parent.class, clId);
>>>>>>>>> } catch (Exception e) {
>>>>>>>>> e.printStackTrace();
>>>>>>>>> }
>>>>>>>>> return cl;
>>>>>>>>> }
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>> public class ParentAction extends ActionSupport implements
>>>>>>>>> ModelDriven {
>>>>>>>>>
>>>>>>>>> private static final long serialVersionUID = -2662966220408285700L;
>>>>>>>>> private Parent cl = new Parent();
>>>>>>>>> private List clList = new ArrayList();
>>>>>>>>> private ParentDAO clDAO = new ParentDAOImpl();
>>>>>>>>>
>>>>>>>>> @Override
>>>>>>>>> public Parent getModel() {
>>>>>>>>> return cl;
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>> public String saveOrUpdate()
>>>>>>>>> {
>>>>>>>>> clDAO.saveOrUpdateParent(cl);
>>>>>>>>> return SUCCESS;
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>> public String save()
>>>>>>>>> {
>>>>>>>>> clDAO.saveParent(cl);
>>>>>>>>> return SUCCESS;
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>> public String list()
>>>>>>>>> {
>>>>>>>>> clList = clDAO.listParent();
>>>>>>>>> return SUCCESS;
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>> public String delete()
>>>>>>>>> {
>>>>>>>>> HttpServletRequest request = (HttpServletRequest)
>>>>>>>>> ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
>>>>>>>>> clDAO.deleteParent(Long.parseLong(request.getParameter("id")));
>>>>>>>>> return SUCCESS;
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>> public String edit()
>>>>>>>>> {
>>>>>>>>> HttpServletRequest request = (HttpServletRequest)
>>>>>>>>> ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
>>>>>>>>> cl = clDAO.listParentById(Long.parseLong(request.getParameter("id")));
>>>>>>>>> return SUCCESS;
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>> public Parent getParent() {
>>>>>>>>> return cl;
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>> public void setParent(Parent cl) {
>>>>>>>>> this.cl = cl;
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>> public List getParentList() {
>>>>>>>>> return clList;
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>> public void setParentList(List clList) {
>>>>>>>>> this.clList = clList;
>>>>>>>>> }
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>> and finally the jsp page:
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>>>>>> "http://www.w3.org/TR/html4/loose.dtd">
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>
>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>
>>>>>>>>>
>>>>
>>>>>>>>>
>>>>
>>>>
>>>>>>>>>
>>>> Child(s)
>>>>>>>>>
>>>>
>>>>>>>>>
>>>>>>>>>>>>>> class="oddeven">
>>>>>>>>>
>>>>
>>>>
>>>>>>>>>
>>>>>>>>>
>>>>
>>>>>>>>>
>>>>>>>>>
>>>>
>>>>>>>>>
>>>>>>>>> Edit
>>>>>>>>>
>>>>
>>>>>>>>>
>>>>>>>>> Delete
>>>>>>>>>
>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>
>>>>>>>> --
>>>>>>>> René Gielen
>>>>>>>> IT-Neering.net
>>>>>>>> Saarstrasse 100, 52062 Aachen, Germany
>>>>>>>> Tel: +49-(0)241-4010770
>>>>>>>> Fax: +49-(0)241-4010771
>>>>>>>> Cel: +49-(0)163-2844164
>>>>>>>> http://twitter.com/rgielen
>>>>>>>>
>>>>>>>> ---------------------------------------------------------------------
>>>>>>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>>>>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>> ---------------------------------------------------------------------
>>>>>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>>>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>>>>
>>>>>>
>>>>>> --
>>>>>> René Gielen
>>>>>> IT-Neering.net
>>>>>> Saarstrasse 100, 52062 Aachen, Germany
>>>>>> Tel: +49-(0)241-4010770
>>>>>> Fax: +49-(0)241-4010771
>>>>>> Cel: +49-(0)163-2844164
>>>>>> http://twitter.com/rgielen
>>>>>>
>>>>>> ---------------------------------------------------------------------
>>>>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>>>
>>>>>
>>>>> _________________________________________________________________
>>>>> Découvrez comment SURFER DISCRETEMENT sur un site de rencontres !
>>>>> http://clk.atdmt.com/FRM/go/206608211/direct/01/
>>>> _________________________________________________________________
>>>> Do you have a story that started on Hotmail? Tell us now
>>>> http://clk.atdmt.com/UKM/go/195013117/direct/01/
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>
>>>
>>> _________________________________________________________________
>>> Consultez gratuitement vos emails Orange, Gmail, Free, ... directement dans HOTMAIL !
>>> http://www.windowslive.fr/hotmail/agregation/
>> _________________________________________________________________
>> Do you have a story that started on Hotmail? Tell us now
>> http://clk.atdmt.com/UKM/go/195013117/direct/01/
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>
> _________________________________________________________________
> Découvrez comment SURFER DISCRETEMENT sur un site de rencontres !
> http://clk.atdmt.com/FRM/go/206608211/direct/01/ 		 	   		  
_________________________________________________________________
Got a cool Hotmail story? Tell us now
http://clk.atdmt.com/UKM/go/195013117/direct/01/
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: CRUD with a OneToMany association under Struts 2 / Hibernate 3

Posted by bruno grandjean <br...@live.fr>.
thks adam but I got now thousand & thousand of lines

I am afraid that I won't be able to read its before the end of the world in 2012..

 

I saw very quicky an exception at the beginning.. 

How can I limit this huge quantity of lines?

 

here is my log4j.properties file:

 

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
log4j.rootLogger=debug, stdout
log4j.logger.com.opensymphony.xwork2.interceptor.ParametersInterceptor=debug

 

 


 
> From: apinder@hotmail.co.uk
> To: user@struts.apache.org
> Subject: RE: CRUD with a OneToMany association under Struts 2 / Hibernate 3
> Date: Thu, 1 Apr 2010 12:57:39 +0100
> 
> 
> 
> 
> in log4j.properties file (same location as struts.xml and hibernate config files)
> 
> add
> 
> log4j.logger.com.opensymphony.xwork2.interceptor.ParametersInterceptor=debug
> 
> this will output param name/value pairs being posted from your page.
> 
> 
> 
> ----------------------------------------
> > From: brgrandjean@live.fr
> > To: user@struts.apache.org
> > Subject: RE: CRUD with a OneToMany association under Struts 2 / Hibernate 3
> > Date: Thu, 1 Apr 2010 13:54:33 +0200
> >
> >
> > Dear Adam,
> >
> >
> >
> > I just added a public Child getValues(int idx) in the Parent class definition but it is never called.
> >
> >
> >
> > Could u explain to me where and how can I turn on the parameterinterceptor logging? In the struts.xml file?
> >
> >
> >
> > thks a lot
> >
> >
> > bruno
> >
> >
> >
> >
> >
> >> From: apinder@hotmail.co.uk
> >> To: user@struts.apache.org
> >> Subject: RE: CRUD with a OneToMany association under Struts 2 / Hibernate 3
> >> Date: Thu, 1 Apr 2010 12:18:48 +0100
> >>
> >>
> >>
> >>
> >> turn on the parameterinterceptor logging and make sure as mentioned that
> >>
> >> 1) the values you expect for each child are being sent to the server (id and name)
> >> 2) the parameter names are correct for setting each child
> >>
> >> i had some issues getting lists of items to be updated by form submission alone.
> >>
> >> for example does your parent object have a getValues method taking an index value
> >>
> >> getParent().getValues(1).setId(1)
> >> getParent().getValues(1).setName("bob")
> >>
> >> would be called by parameterinterceptor
> >>
> >>
> >> ----------------------------------------
> >>> From: brgrandjean@live.fr
> >>> To: user@struts.apache.org
> >>> Subject: RE: CRUD with a OneToMany association under Struts 2 / Hibernate 3
> >>> Date: Thu, 1 Apr 2010 12:16:09 +0200
> >>>
> >>>
> >>> Dear René
> >>>
> >>>
> >>>
> >>> I changed my jsp page so as to integrate the following block:
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>> which generates the following html code:
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>> I can display my complete Child Set but I got the same result after updating: my Child Set is empty.
> >>>
> >>>
> >>>
> >>> Is that necessary to modify my ParentAction as well? If yes what to do?
> >>>
> >>>
> >>>
> >>> public class ParentAction extends ActionSupport implements ModelDriven {
> >>>
> >>> private static final long serialVersionUID = -2662966220408285700L;
> >>> private Parent cl = new Parent();
> >>> private List clList = new ArrayList();
> >>> private ParentDAO clDAO = new ParentDAOImpl();
> >>>
> >>> @Override
> >>> public Parent getModel() {
> >>> return cl;
> >>> }
> >>>
> >>> public String saveOrUpdate()
> >>> { // cl.values is empty here!!
> >>> clDAO.saveOrUpdateParent(cl);
> >>> return SUCCESS;
> >>> }
> >>>
> >>> public String save()
> >>> {
> >>> clDAO.saveParent(cl);
> >>> return SUCCESS;
> >>> }
> >>>
> >>> public String list()
> >>> {
> >>> clList = clDAO.listParent();
> >>> return SUCCESS;
> >>> }
> >>>
> >>> public String delete()
> >>> {
> >>> HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
> >>> clDAO.deleteParent(Long.parseLong(request.getParameter("id")));
> >>> return SUCCESS;
> >>> }
> >>>
> >>> public String edit()
> >>> { // cl.values contains some valid Child elements here!!
> >>> HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
> >>> cl = clDAO.listParentById(Long.parseLong(request.getParameter("id")));
> >>> }
> >>> return SUCCESS;
> >>> }
> >>>
> >>> public Parent getParent() {
> >>> return cl;
> >>> }
> >>>
> >>> public void setParent(Parent cl) {
> >>> this.cl = cl;
> >>> }
> >>>
> >>> public List getParentList() {
> >>> return clList;
> >>> }
> >>>
> >>> public void setParentList(List clList) {
> >>> this.clList = clList;
> >>> }
> >>> }
> >>>
> >>>
> >>>
> >>>> Date: Thu, 1 Apr 2010 11:30:23 +0200
> >>>> From: gielen@it-neering.net
> >>>> To: user@struts.apache.org
> >>>> Subject: Re: CRUD with a OneToMany association under Struts 2 / Hibernate 3
> >>>>
> >>>> Given the model you presented in the first post, your problem seems to
> >>>> be that the posted values have not the correct name for the children's
> >>>> form fields. The parameters names you would need are
> >>>>
> >>>> id
> >>>> name
> >>>> values[0].id
> >>>> values[0].name
> >>>> values[1].id
> >>>> values[2].name
> >>>> ...
> >>>>
> >>>> for the parameters interceptor to work properly when applying the posted
> >>>> values.
> >>>>
> >>>> See here for more details:
> >>>> http://struts.apache.org/2.1.8/docs/tabular-inputs.html
> >>>>
> >>>> - René
> >>>>
> >>>> bruno grandjean schrieb:
> >>>>> Dear Rene,
> >>>>>
> >>>>> Thks a lot for replying to me because I am feeling a little bit alone with
> >>>>> my CRUD ;-). In fact I am trying to build a dynamic MetaCrud.
> >>>>> My pb is simple: in the same jsp page I would like to update a Parent
> >>>>> object
> >>>>> and its Childs (values):
> >>>>>
> >>>>>
> >>>>>
> >>>>>>>> name="name" label="Nom" />
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>> From an existing Parent object with many Childs objects I can easily modify
> >>>>> parent.name for instance but the collection of Child objects (values) is
> >>>>> always empty in the ParentAction (saveOrUpdate() method) after submitting.
> >>>>> However I can display each values[i].name in the jsp page with the correct
> >>>>> value.
> >>>>> So it is not an issue with Hibernate but with the jsp or ModelDriven
> >>>>> interface I don't know..Do you have any idea?
> >>>>> Basically I was not able to find a struts or spring documentation about
> >>>>> CRUD
> >>>>> & association between two entities on the same jsp page.
> >>>>> best regards
> >>>>> bruno
> >>>>>
> >>>>>
> >>>>>
> >>>>> --------------------------------------------------
> >>>>> From: "Rene Gielen"
> >>>>> Sent: Wednesday, March 31, 2010 7:12 PM
> >>>>> To: "Struts Users Mailing List"
> >>>>> Subject: Re: CRUD with a OneToMany association under Struts 2 / Hibernate 3
> >>>>>
> >>>>>> I'm not sure if I understand what your actual question is, nor whether
> >>>>>> it is particularly Struts 2 related (rather than just Hibernate) - but
> >>>>>> you might want to have a look in the CRUD demo section of the Struts 2
> >>>>>> showcase application. Maybe you will also find this demo useful:
> >>>>>> http://github.com/rgielen/struts2crudevolutiondemo
> >>>>>>
> >>>>>> - René
> >>>>>>
> >>>>>> bruno grandjean schrieb:
> >>>>>>> Hi
> >>>>>>>
> >>>>>>> I am trying to implement a simple CRUD with a OneToMany association
> >>>>>>> under Struts 2 / Hibernate 3.
> >>>>>>> I have two entities Parent and Child:
> >>>>>>>
> >>>>>>> @Entity
> >>>>>>> @Table(name="PARENT")
> >>>>>>> public class Parent {
> >>>>>>> private Long id;
> >>>>>>> private Set values = new HashSet();
> >>>>>>> ..
> >>>>>>> @Entity
> >>>>>>> @Table(name="CHILD")
> >>>>>>> public class Child {
> >>>>>>> private Long id;
> >>>>>>> private String name;
> >>>>>>> ..
> >>>>>>>
> >>>>>>> I can easily create, delete Parent or read the Child Set (values) but
> >>>>>>> it is impossible to update Child Set.
> >>>>>>> The jsp page (see below) reinit the values Set, no record after
> >>>>>>> updating!
> >>>>>>> Could u explain to me what's wrong?
> >>>>>>>
> >>>>>>> here are my code:
> >>>>>>>
> >>>>>>> @Entity
> >>>>>>> @Table(name="PARENT")
> >>>>>>> public class Parent {
> >>>>>>> private Long id;
> >>>>>>> private Set values = new HashSet();
> >>>>>>> @Id
> >>>>>>> @GeneratedValue
> >>>>>>> @Column(name="PARENT_ID")
> >>>>>>> public Long getId() {
> >>>>>>> return id;
> >>>>>>> }
> >>>>>>> public void setId(Long id) {
> >>>>>>> this.id = id;
> >>>>>>> }
> >>>>>>> @ManyToMany(fetch = FetchType.EAGER)
> >>>>>>> @JoinTable(name = "PARENT_CHILD", joinColumns = { @JoinColumn(name =
> >>>>>>> "PARENT_ID") }, inverseJoinColumns = { @JoinColumn(name = "CHILD_ID") })
> >>>>>>> public Set getValues() {
> >>>>>>> return values;
> >>>>>>> }
> >>>>>>> public void setValues(Set lst) {
> >>>>>>> values = lst;
> >>>>>>> }
> >>>>>>> }
> >>>>>>>
> >>>>>>> @Entity
> >>>>>>> @Table(name="CHILD")
> >>>>>>> public class Child {
> >>>>>>> private Long id;
> >>>>>>> private String name;
> >>>>>>> @Id
> >>>>>>> @GeneratedValue
> >>>>>>> @Column(name="CHILD_ID")
> >>>>>>> public Long getId() {
> >>>>>>> return id;
> >>>>>>> }
> >>>>>>> public void setId(Long id) {
> >>>>>>> this.id = id;
> >>>>>>> }
> >>>>>>> @Column(name="NAME")
> >>>>>>> public String getName() {
> >>>>>>> return name;
> >>>>>>> }
> >>>>>>> public void setName(String val) {
> >>>>>>> name = val;
> >>>>>>> }
> >>>>>>> }
> >>>>>>>
> >>>>>>> public interface ParentDAO {
> >>>>>>> public void saveOrUpdateParent(Parent cl);
> >>>>>>> public void saveParent(Parent cl);
> >>>>>>> public List listParent();
> >>>>>>> public Parent listParentById(Long clId);
> >>>>>>> public void deleteParent(Long clId);
> >>>>>>> }
> >>>>>>>
> >>>>>>> public class ParentDAOImpl implements ParentDAO {
> >>>>>>> @SessionTarget
> >>>>>>> Session session;
> >>>>>>> @TransactionTarget
> >>>>>>> Transaction transaction;
> >>>>>>>
> >>>>>>> @Override
> >>>>>>> public void saveOrUpdateParent(Parent cl) {
> >>>>>>> try {
> >>>>>>> session.saveOrUpdate(cl);
> >>>>>>> } catch (Exception e) {
> >>>>>>> transaction.rollback();
> >>>>>>> e.printStackTrace();
> >>>>>>> }
> >>>>>>> }
> >>>>>>>
> >>>>>>> @Override
> >>>>>>> public void saveParent(Parent cl) {
> >>>>>>> try {
> >>>>>>> session.save(cl);
> >>>>>>> } catch (Exception e) {
> >>>>>>> transaction.rollback();
> >>>>>>> e.printStackTrace();
> >>>>>>> }
> >>>>>>> }
> >>>>>>>
> >>>>>>> @Override
> >>>>>>> public void deleteParent(Long clId) {
> >>>>>>> try {
> >>>>>>> Parent cl = (Parent) session.get(Parent.class, clId);
> >>>>>>> session.delete(cl);
> >>>>>>> } catch (Exception e) {
> >>>>>>> transaction.rollback();
> >>>>>>> e.printStackTrace();
> >>>>>>> }
> >>>>>>> }
> >>>>>>>
> >>>>>>> @SuppressWarnings("unchecked")
> >>>>>>> @Override
> >>>>>>> public List listParent() {
> >>>>>>> List courses = null;
> >>>>>>> try {
> >>>>>>> courses = session.createQuery("from Parent").list();
> >>>>>>> } catch (Exception e) {
> >>>>>>> e.printStackTrace();
> >>>>>>> }
> >>>>>>> return courses;
> >>>>>>> }
> >>>>>>>
> >>>>>>> @Override
> >>>>>>> public Parent listParentById(Long clId) {
> >>>>>>> Parent cl = null;
> >>>>>>> try {
> >>>>>>> cl = (Parent) session.get(Parent.class, clId);
> >>>>>>> } catch (Exception e) {
> >>>>>>> e.printStackTrace();
> >>>>>>> }
> >>>>>>> return cl;
> >>>>>>> }
> >>>>>>> }
> >>>>>>>
> >>>>>>> public class ParentAction extends ActionSupport implements
> >>>>>>> ModelDriven {
> >>>>>>>
> >>>>>>> private static final long serialVersionUID = -2662966220408285700L;
> >>>>>>> private Parent cl = new Parent();
> >>>>>>> private List clList = new ArrayList();
> >>>>>>> private ParentDAO clDAO = new ParentDAOImpl();
> >>>>>>>
> >>>>>>> @Override
> >>>>>>> public Parent getModel() {
> >>>>>>> return cl;
> >>>>>>> }
> >>>>>>>
> >>>>>>> public String saveOrUpdate()
> >>>>>>> {
> >>>>>>> clDAO.saveOrUpdateParent(cl);
> >>>>>>> return SUCCESS;
> >>>>>>> }
> >>>>>>>
> >>>>>>> public String save()
> >>>>>>> {
> >>>>>>> clDAO.saveParent(cl);
> >>>>>>> return SUCCESS;
> >>>>>>> }
> >>>>>>>
> >>>>>>> public String list()
> >>>>>>> {
> >>>>>>> clList = clDAO.listParent();
> >>>>>>> return SUCCESS;
> >>>>>>> }
> >>>>>>>
> >>>>>>> public String delete()
> >>>>>>> {
> >>>>>>> HttpServletRequest request = (HttpServletRequest)
> >>>>>>> ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
> >>>>>>> clDAO.deleteParent(Long.parseLong(request.getParameter("id")));
> >>>>>>> return SUCCESS;
> >>>>>>> }
> >>>>>>>
> >>>>>>> public String edit()
> >>>>>>> {
> >>>>>>> HttpServletRequest request = (HttpServletRequest)
> >>>>>>> ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
> >>>>>>> cl = clDAO.listParentById(Long.parseLong(request.getParameter("id")));
> >>>>>>> return SUCCESS;
> >>>>>>> }
> >>>>>>>
> >>>>>>> public Parent getParent() {
> >>>>>>> return cl;
> >>>>>>> }
> >>>>>>>
> >>>>>>> public void setParent(Parent cl) {
> >>>>>>> this.cl = cl;
> >>>>>>> }
> >>>>>>>
> >>>>>>> public List getParentList() {
> >>>>>>> return clList;
> >>>>>>> }
> >>>>>>>
> >>>>>>> public void setParentList(List clList) {
> >>>>>>> this.clList = clList;
> >>>>>>> }
> >>>>>>> }
> >>>>>>>
> >>>>>>> and finally the jsp page:
> >>>>>>>
> >>>>>>>
> >>>>>>>>>>>> "http://www.w3.org/TR/html4/loose.dtd">
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>
> >>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>
> >>>>>>>
> >>
> >>>>>>>
> >>
> >>
> >>>>>>>
> >> Child(s)
> >>>>>>>
> >>
> >>>>>>>
> >>>>>>>>>>>> class="oddeven">
> >>>>>>>
> >>
> >>
> >>>>>>>
> >>>>>>>
> >>
> >>>>>>>
> >>>>>>>
> >>
> >>>>>>>
> >>>>>>> Edit
> >>>>>>>
> >>
> >>>>>>>
> >>>>>>> Delete
> >>>>>>>
> >>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>
> >>>>>> --
> >>>>>> René Gielen
> >>>>>> IT-Neering.net
> >>>>>> Saarstrasse 100, 52062 Aachen, Germany
> >>>>>> Tel: +49-(0)241-4010770
> >>>>>> Fax: +49-(0)241-4010771
> >>>>>> Cel: +49-(0)163-2844164
> >>>>>> http://twitter.com/rgielen
> >>>>>>
> >>>>>> ---------------------------------------------------------------------
> >>>>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >>>>>> For additional commands, e-mail: user-help@struts.apache.org
> >>>>>>
> >>>>>>
> >>>>>
> >>>>> ---------------------------------------------------------------------
> >>>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >>>>> For additional commands, e-mail: user-help@struts.apache.org
> >>>>>
> >>>>
> >>>> --
> >>>> René Gielen
> >>>> IT-Neering.net
> >>>> Saarstrasse 100, 52062 Aachen, Germany
> >>>> Tel: +49-(0)241-4010770
> >>>> Fax: +49-(0)241-4010771
> >>>> Cel: +49-(0)163-2844164
> >>>> http://twitter.com/rgielen
> >>>>
> >>>> ---------------------------------------------------------------------
> >>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >>>> For additional commands, e-mail: user-help@struts.apache.org
> >>>>
> >>>
> >>> _________________________________________________________________
> >>> Découvrez comment SURFER DISCRETEMENT sur un site de rencontres !
> >>> http://clk.atdmt.com/FRM/go/206608211/direct/01/
> >> _________________________________________________________________
> >> Do you have a story that started on Hotmail? Tell us now
> >> http://clk.atdmt.com/UKM/go/195013117/direct/01/
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >> For additional commands, e-mail: user-help@struts.apache.org
> >>
> >
> > _________________________________________________________________
> > Consultez gratuitement vos emails Orange, Gmail, Free, ... directement dans HOTMAIL !
> > http://www.windowslive.fr/hotmail/agregation/ 
> _________________________________________________________________
> Do you have a story that started on Hotmail? Tell us now
> http://clk.atdmt.com/UKM/go/195013117/direct/01/
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
 		 	   		  
_________________________________________________________________
Découvrez comment SURFER DISCRETEMENT sur un site de rencontres !
http://clk.atdmt.com/FRM/go/206608211/direct/01/

RE: CRUD with a OneToMany association under Struts 2 / Hibernate 3

Posted by bruno grandjean <br...@live.fr>.
Here are exceptions I got after submitting:
 


Entering getProperty()
Error setting value
ognl.NoSuchPropertyException: java.util.HashSet.0
...
 


Entering getProperty()
Error setting value
ognl.NoSuchPropertyException: java.util.HashSet.0
at ognl.SetPropertyAccessor.getProperty(SetPropertyAccessor.java:67)
..


Entering getProperty()
Error setting value
ognl.NoSuchPropertyException: java.util.HashSet.1
at ognl.SetPropertyAccessor.getProperty(SetPropertyAccessor.java:67)
..


Entering getProperty()
Error setting value
ognl.NoSuchPropertyException: java.util.HashSet.1
at ognl.SetPropertyAccessor.getProperty(SetPropertyAccessor.java:67)
..



Hibernate Validation in class com.metacrud.web.ParentAction
Hibernate Validation found no erros.
Executing action method = saveOrUpdate
Redirecting to finalLocation /Metacrud/listParent
after Locale=fr
intercept } 
processing flush-time cascades
dirty checking collections
Collection found: [com.metacrud.domain.Parent.values#1], was: [<unreferenced>] (initialized)
Flushed: 0 insertions, 1 updates, 0 deletions to 1 objects
Flushed: 1 (re)creations, 0 updates, 1 removals to 1 collections
listing entities:
com.metacrud.domain.Parent{id=1, values=[], name=Parent1}
about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
update PARENT set NAME=? where PARENT_ID=?
Executing batch size: 1
about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
Deleting collection: [com.metacrud.domain.Parent.values#1]
about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
delete from PARENT_CHILD where PARENT_ID=?
done deleting collection

 

 

 


 
> From: apinder@hotmail.co.uk
> To: user@struts.apache.org
> Subject: RE: CRUD with a OneToMany association under Struts 2 / Hibernate 3
> Date: Thu, 1 Apr 2010 12:57:39 +0100
> 
> 
> 
> 
> in log4j.properties file (same location as struts.xml and hibernate config files)
> 
> add
> 
> log4j.logger.com.opensymphony.xwork2.interceptor.ParametersInterceptor=debug
> 
> this will output param name/value pairs being posted from your page.
> 
> 
> 
> ----------------------------------------
> > From: brgrandjean@live.fr
> > To: user@struts.apache.org
> > Subject: RE: CRUD with a OneToMany association under Struts 2 / Hibernate 3
> > Date: Thu, 1 Apr 2010 13:54:33 +0200
> >
> >
> > Dear Adam,
> >
> >
> >
> > I just added a public Child getValues(int idx) in the Parent class definition but it is never called.
> >
> >
> >
> > Could u explain to me where and how can I turn on the parameterinterceptor logging? In the struts.xml file?
> >
> >
> >
> > thks a lot
> >
> >
> > bruno
> >
> >
> >
> >
> >
> >> From: apinder@hotmail.co.uk
> >> To: user@struts.apache.org
> >> Subject: RE: CRUD with a OneToMany association under Struts 2 / Hibernate 3
> >> Date: Thu, 1 Apr 2010 12:18:48 +0100
> >>
> >>
> >>
> >>
> >> turn on the parameterinterceptor logging and make sure as mentioned that
> >>
> >> 1) the values you expect for each child are being sent to the server (id and name)
> >> 2) the parameter names are correct for setting each child
> >>
> >> i had some issues getting lists of items to be updated by form submission alone.
> >>
> >> for example does your parent object have a getValues method taking an index value
> >>
> >> getParent().getValues(1).setId(1)
> >> getParent().getValues(1).setName("bob")
> >>
> >> would be called by parameterinterceptor
> >>
> >>
> >> ----------------------------------------
> >>> From: brgrandjean@live.fr
> >>> To: user@struts.apache.org
> >>> Subject: RE: CRUD with a OneToMany association under Struts 2 / Hibernate 3
> >>> Date: Thu, 1 Apr 2010 12:16:09 +0200
> >>>
> >>>
> >>> Dear René
> >>>
> >>>
> >>>
> >>> I changed my jsp page so as to integrate the following block:
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>> which generates the following html code:
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>> I can display my complete Child Set but I got the same result after updating: my Child Set is empty.
> >>>
> >>>
> >>>
> >>> Is that necessary to modify my ParentAction as well? If yes what to do?
> >>>
> >>>
> >>>
> >>> public class ParentAction extends ActionSupport implements ModelDriven {
> >>>
> >>> private static final long serialVersionUID = -2662966220408285700L;
> >>> private Parent cl = new Parent();
> >>> private List clList = new ArrayList();
> >>> private ParentDAO clDAO = new ParentDAOImpl();
> >>>
> >>> @Override
> >>> public Parent getModel() {
> >>> return cl;
> >>> }
> >>>
> >>> public String saveOrUpdate()
> >>> { // cl.values is empty here!!
> >>> clDAO.saveOrUpdateParent(cl);
> >>> return SUCCESS;
> >>> }
> >>>
> >>> public String save()
> >>> {
> >>> clDAO.saveParent(cl);
> >>> return SUCCESS;
> >>> }
> >>>
> >>> public String list()
> >>> {
> >>> clList = clDAO.listParent();
> >>> return SUCCESS;
> >>> }
> >>>
> >>> public String delete()
> >>> {
> >>> HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
> >>> clDAO.deleteParent(Long.parseLong(request.getParameter("id")));
> >>> return SUCCESS;
> >>> }
> >>>
> >>> public String edit()
> >>> { // cl.values contains some valid Child elements here!!
> >>> HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
> >>> cl = clDAO.listParentById(Long.parseLong(request.getParameter("id")));
> >>> }
> >>> return SUCCESS;
> >>> }
> >>>
> >>> public Parent getParent() {
> >>> return cl;
> >>> }
> >>>
> >>> public void setParent(Parent cl) {
> >>> this.cl = cl;
> >>> }
> >>>
> >>> public List getParentList() {
> >>> return clList;
> >>> }
> >>>
> >>> public void setParentList(List clList) {
> >>> this.clList = clList;
> >>> }
> >>> }
> >>>
> >>>
> >>>
> >>>> Date: Thu, 1 Apr 2010 11:30:23 +0200
> >>>> From: gielen@it-neering.net
> >>>> To: user@struts.apache.org
> >>>> Subject: Re: CRUD with a OneToMany association under Struts 2 / Hibernate 3
> >>>>
> >>>> Given the model you presented in the first post, your problem seems to
> >>>> be that the posted values have not the correct name for the children's
> >>>> form fields. The parameters names you would need are
> >>>>
> >>>> id
> >>>> name
> >>>> values[0].id
> >>>> values[0].name
> >>>> values[1].id
> >>>> values[2].name
> >>>> ...
> >>>>
> >>>> for the parameters interceptor to work properly when applying the posted
> >>>> values.
> >>>>
> >>>> See here for more details:
> >>>> http://struts.apache.org/2.1.8/docs/tabular-inputs.html
> >>>>
> >>>> - René
> >>>>
> >>>> bruno grandjean schrieb:
> >>>>> Dear Rene,
> >>>>>
> >>>>> Thks a lot for replying to me because I am feeling a little bit alone with
> >>>>> my CRUD ;-). In fact I am trying to build a dynamic MetaCrud.
> >>>>> My pb is simple: in the same jsp page I would like to update a Parent
> >>>>> object
> >>>>> and its Childs (values):
> >>>>>
> >>>>>
> >>>>>
> >>>>>>>> name="name" label="Nom" />
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>> From an existing Parent object with many Childs objects I can easily modify
> >>>>> parent.name for instance but the collection of Child objects (values) is
> >>>>> always empty in the ParentAction (saveOrUpdate() method) after submitting.
> >>>>> However I can display each values[i].name in the jsp page with the correct
> >>>>> value.
> >>>>> So it is not an issue with Hibernate but with the jsp or ModelDriven
> >>>>> interface I don't know..Do you have any idea?
> >>>>> Basically I was not able to find a struts or spring documentation about
> >>>>> CRUD
> >>>>> & association between two entities on the same jsp page.
> >>>>> best regards
> >>>>> bruno
> >>>>>
> >>>>>
> >>>>>
> >>>>> --------------------------------------------------
> >>>>> From: "Rene Gielen"
> >>>>> Sent: Wednesday, March 31, 2010 7:12 PM
> >>>>> To: "Struts Users Mailing List"
> >>>>> Subject: Re: CRUD with a OneToMany association under Struts 2 / Hibernate 3
> >>>>>
> >>>>>> I'm not sure if I understand what your actual question is, nor whether
> >>>>>> it is particularly Struts 2 related (rather than just Hibernate) - but
> >>>>>> you might want to have a look in the CRUD demo section of the Struts 2
> >>>>>> showcase application. Maybe you will also find this demo useful:
> >>>>>> http://github.com/rgielen/struts2crudevolutiondemo
> >>>>>>
> >>>>>> - René
> >>>>>>
> >>>>>> bruno grandjean schrieb:
> >>>>>>> Hi
> >>>>>>>
> >>>>>>> I am trying to implement a simple CRUD with a OneToMany association
> >>>>>>> under Struts 2 / Hibernate 3.
> >>>>>>> I have two entities Parent and Child:
> >>>>>>>
> >>>>>>> @Entity
> >>>>>>> @Table(name="PARENT")
> >>>>>>> public class Parent {
> >>>>>>> private Long id;
> >>>>>>> private Set values = new HashSet();
> >>>>>>> ..
> >>>>>>> @Entity
> >>>>>>> @Table(name="CHILD")
> >>>>>>> public class Child {
> >>>>>>> private Long id;
> >>>>>>> private String name;
> >>>>>>> ..
> >>>>>>>
> >>>>>>> I can easily create, delete Parent or read the Child Set (values) but
> >>>>>>> it is impossible to update Child Set.
> >>>>>>> The jsp page (see below) reinit the values Set, no record after
> >>>>>>> updating!
> >>>>>>> Could u explain to me what's wrong?
> >>>>>>>
> >>>>>>> here are my code:
> >>>>>>>
> >>>>>>> @Entity
> >>>>>>> @Table(name="PARENT")
> >>>>>>> public class Parent {
> >>>>>>> private Long id;
> >>>>>>> private Set values = new HashSet();
> >>>>>>> @Id
> >>>>>>> @GeneratedValue
> >>>>>>> @Column(name="PARENT_ID")
> >>>>>>> public Long getId() {
> >>>>>>> return id;
> >>>>>>> }
> >>>>>>> public void setId(Long id) {
> >>>>>>> this.id = id;
> >>>>>>> }
> >>>>>>> @ManyToMany(fetch = FetchType.EAGER)
> >>>>>>> @JoinTable(name = "PARENT_CHILD", joinColumns = { @JoinColumn(name =
> >>>>>>> "PARENT_ID") }, inverseJoinColumns = { @JoinColumn(name = "CHILD_ID") })
> >>>>>>> public Set getValues() {
> >>>>>>> return values;
> >>>>>>> }
> >>>>>>> public void setValues(Set lst) {
> >>>>>>> values = lst;
> >>>>>>> }
> >>>>>>> }
> >>>>>>>
> >>>>>>> @Entity
> >>>>>>> @Table(name="CHILD")
> >>>>>>> public class Child {
> >>>>>>> private Long id;
> >>>>>>> private String name;
> >>>>>>> @Id
> >>>>>>> @GeneratedValue
> >>>>>>> @Column(name="CHILD_ID")
> >>>>>>> public Long getId() {
> >>>>>>> return id;
> >>>>>>> }
> >>>>>>> public void setId(Long id) {
> >>>>>>> this.id = id;
> >>>>>>> }
> >>>>>>> @Column(name="NAME")
> >>>>>>> public String getName() {
> >>>>>>> return name;
> >>>>>>> }
> >>>>>>> public void setName(String val) {
> >>>>>>> name = val;
> >>>>>>> }
> >>>>>>> }
> >>>>>>>
> >>>>>>> public interface ParentDAO {
> >>>>>>> public void saveOrUpdateParent(Parent cl);
> >>>>>>> public void saveParent(Parent cl);
> >>>>>>> public List listParent();
> >>>>>>> public Parent listParentById(Long clId);
> >>>>>>> public void deleteParent(Long clId);
> >>>>>>> }
> >>>>>>>
> >>>>>>> public class ParentDAOImpl implements ParentDAO {
> >>>>>>> @SessionTarget
> >>>>>>> Session session;
> >>>>>>> @TransactionTarget
> >>>>>>> Transaction transaction;
> >>>>>>>
> >>>>>>> @Override
> >>>>>>> public void saveOrUpdateParent(Parent cl) {
> >>>>>>> try {
> >>>>>>> session.saveOrUpdate(cl);
> >>>>>>> } catch (Exception e) {
> >>>>>>> transaction.rollback();
> >>>>>>> e.printStackTrace();
> >>>>>>> }
> >>>>>>> }
> >>>>>>>
> >>>>>>> @Override
> >>>>>>> public void saveParent(Parent cl) {
> >>>>>>> try {
> >>>>>>> session.save(cl);
> >>>>>>> } catch (Exception e) {
> >>>>>>> transaction.rollback();
> >>>>>>> e.printStackTrace();
> >>>>>>> }
> >>>>>>> }
> >>>>>>>
> >>>>>>> @Override
> >>>>>>> public void deleteParent(Long clId) {
> >>>>>>> try {
> >>>>>>> Parent cl = (Parent) session.get(Parent.class, clId);
> >>>>>>> session.delete(cl);
> >>>>>>> } catch (Exception e) {
> >>>>>>> transaction.rollback();
> >>>>>>> e.printStackTrace();
> >>>>>>> }
> >>>>>>> }
> >>>>>>>
> >>>>>>> @SuppressWarnings("unchecked")
> >>>>>>> @Override
> >>>>>>> public List listParent() {
> >>>>>>> List courses = null;
> >>>>>>> try {
> >>>>>>> courses = session.createQuery("from Parent").list();
> >>>>>>> } catch (Exception e) {
> >>>>>>> e.printStackTrace();
> >>>>>>> }
> >>>>>>> return courses;
> >>>>>>> }
> >>>>>>>
> >>>>>>> @Override
> >>>>>>> public Parent listParentById(Long clId) {
> >>>>>>> Parent cl = null;
> >>>>>>> try {
> >>>>>>> cl = (Parent) session.get(Parent.class, clId);
> >>>>>>> } catch (Exception e) {
> >>>>>>> e.printStackTrace();
> >>>>>>> }
> >>>>>>> return cl;
> >>>>>>> }
> >>>>>>> }
> >>>>>>>
> >>>>>>> public class ParentAction extends ActionSupport implements
> >>>>>>> ModelDriven {
> >>>>>>>
> >>>>>>> private static final long serialVersionUID = -2662966220408285700L;
> >>>>>>> private Parent cl = new Parent();
> >>>>>>> private List clList = new ArrayList();
> >>>>>>> private ParentDAO clDAO = new ParentDAOImpl();
> >>>>>>>
> >>>>>>> @Override
> >>>>>>> public Parent getModel() {
> >>>>>>> return cl;
> >>>>>>> }
> >>>>>>>
> >>>>>>> public String saveOrUpdate()
> >>>>>>> {
> >>>>>>> clDAO.saveOrUpdateParent(cl);
> >>>>>>> return SUCCESS;
> >>>>>>> }
> >>>>>>>
> >>>>>>> public String save()
> >>>>>>> {
> >>>>>>> clDAO.saveParent(cl);
> >>>>>>> return SUCCESS;
> >>>>>>> }
> >>>>>>>
> >>>>>>> public String list()
> >>>>>>> {
> >>>>>>> clList = clDAO.listParent();
> >>>>>>> return SUCCESS;
> >>>>>>> }
> >>>>>>>
> >>>>>>> public String delete()
> >>>>>>> {
> >>>>>>> HttpServletRequest request = (HttpServletRequest)
> >>>>>>> ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
> >>>>>>> clDAO.deleteParent(Long.parseLong(request.getParameter("id")));
> >>>>>>> return SUCCESS;
> >>>>>>> }
> >>>>>>>
> >>>>>>> public String edit()
> >>>>>>> {
> >>>>>>> HttpServletRequest request = (HttpServletRequest)
> >>>>>>> ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
> >>>>>>> cl = clDAO.listParentById(Long.parseLong(request.getParameter("id")));
> >>>>>>> return SUCCESS;
> >>>>>>> }
> >>>>>>>
> >>>>>>> public Parent getParent() {
> >>>>>>> return cl;
> >>>>>>> }
> >>>>>>>
> >>>>>>> public void setParent(Parent cl) {
> >>>>>>> this.cl = cl;
> >>>>>>> }
> >>>>>>>
> >>>>>>> public List getParentList() {
> >>>>>>> return clList;
> >>>>>>> }
> >>>>>>>
> >>>>>>> public void setParentList(List clList) {
> >>>>>>> this.clList = clList;
> >>>>>>> }
> >>>>>>> }
> >>>>>>>
> >>>>>>> and finally the jsp page:
> >>>>>>>
> >>>>>>>
> >>>>>>>>>>>> "http://www.w3.org/TR/html4/loose.dtd">
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>
> >>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>
> >>>>>>>
> >>
> >>>>>>>
> >>
> >>
> >>>>>>>
> >> Child(s)
> >>>>>>>
> >>
> >>>>>>>
> >>>>>>>>>>>> class="oddeven">
> >>>>>>>
> >>
> >>
> >>>>>>>
> >>>>>>>
> >>
> >>>>>>>
> >>>>>>>
> >>
> >>>>>>>
> >>>>>>> Edit
> >>>>>>>
> >>
> >>>>>>>
> >>>>>>> Delete
> >>>>>>>
> >>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>
> >>>>>> --
> >>>>>> René Gielen
> >>>>>> IT-Neering.net
> >>>>>> Saarstrasse 100, 52062 Aachen, Germany
> >>>>>> Tel: +49-(0)241-4010770
> >>>>>> Fax: +49-(0)241-4010771
> >>>>>> Cel: +49-(0)163-2844164
> >>>>>> http://twitter.com/rgielen
> >>>>>>
> >>>>>> ---------------------------------------------------------------------
> >>>>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >>>>>> For additional commands, e-mail: user-help@struts.apache.org
> >>>>>>
> >>>>>>
> >>>>>
> >>>>> ---------------------------------------------------------------------
> >>>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >>>>> For additional commands, e-mail: user-help@struts.apache.org
> >>>>>
> >>>>
> >>>> --
> >>>> René Gielen
> >>>> IT-Neering.net
> >>>> Saarstrasse 100, 52062 Aachen, Germany
> >>>> Tel: +49-(0)241-4010770
> >>>> Fax: +49-(0)241-4010771
> >>>> Cel: +49-(0)163-2844164
> >>>> http://twitter.com/rgielen
> >>>>
> >>>> ---------------------------------------------------------------------
> >>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >>>> For additional commands, e-mail: user-help@struts.apache.org
> >>>>
> >>>
> >>> _________________________________________________________________
> >>> Découvrez comment SURFER DISCRETEMENT sur un site de rencontres !
> >>> http://clk.atdmt.com/FRM/go/206608211/direct/01/
> >> _________________________________________________________________
> >> Do you have a story that started on Hotmail? Tell us now
> >> http://clk.atdmt.com/UKM/go/195013117/direct/01/
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >> For additional commands, e-mail: user-help@struts.apache.org
> >>
> >
> > _________________________________________________________________
> > Consultez gratuitement vos emails Orange, Gmail, Free, ... directement dans HOTMAIL !
> > http://www.windowslive.fr/hotmail/agregation/ 
> _________________________________________________________________
> Do you have a story that started on Hotmail? Tell us now
> http://clk.atdmt.com/UKM/go/195013117/direct/01/
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
 		 	   		  
_________________________________________________________________
Consultez gratuitement vos emails Orange, Gmail, Free, ... directement dans HOTMAIL !
http://www.windowslive.fr/hotmail/agregation/

RE: CRUD with a OneToMany association under Struts 2 / Hibernate 3

Posted by adam pinder <ap...@hotmail.co.uk>.
 
 
in log4j.properties file (same location as struts.xml and hibernate config files)
 
add
 
log4j.logger.com.opensymphony.xwork2.interceptor.ParametersInterceptor=debug
 
this will output param name/value pairs being posted from your page.
 


----------------------------------------
> From: brgrandjean@live.fr
> To: user@struts.apache.org
> Subject: RE: CRUD with a OneToMany association under Struts 2 / Hibernate 3
> Date: Thu, 1 Apr 2010 13:54:33 +0200
>
>
> Dear Adam,
>
>
>
> I just added a public Child getValues(int idx) in the Parent class definition but it is never called.
>
>
>
> Could u explain to me where and how can I turn on the parameterinterceptor logging? In the struts.xml file?
>
>
>
> thks a lot
>
>
> bruno
>
>
>
>
>
>> From: apinder@hotmail.co.uk
>> To: user@struts.apache.org
>> Subject: RE: CRUD with a OneToMany association under Struts 2 / Hibernate 3
>> Date: Thu, 1 Apr 2010 12:18:48 +0100
>>
>>
>>
>>
>> turn on the parameterinterceptor logging and make sure as mentioned that
>>
>> 1) the values you expect for each child are being sent to the server (id and name)
>> 2) the parameter names are correct for setting each child
>>
>> i had some issues getting lists of items to be updated by form submission alone.
>>
>> for example does your parent object have a getValues method taking an index value
>>
>> getParent().getValues(1).setId(1)
>> getParent().getValues(1).setName("bob")
>>
>> would be called by parameterinterceptor
>>
>>
>> ----------------------------------------
>>> From: brgrandjean@live.fr
>>> To: user@struts.apache.org
>>> Subject: RE: CRUD with a OneToMany association under Struts 2 / Hibernate 3
>>> Date: Thu, 1 Apr 2010 12:16:09 +0200
>>>
>>>
>>> Dear René
>>>
>>>
>>>
>>> I changed my jsp page so as to integrate the following block:
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> which generates the following html code:
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> I can display my complete Child Set but I got the same result after updating: my Child Set is empty.
>>>
>>>
>>>
>>> Is that necessary to modify my ParentAction as well? If yes what to do?
>>>
>>>
>>>
>>> public class ParentAction extends ActionSupport implements ModelDriven {
>>>
>>> private static final long serialVersionUID = -2662966220408285700L;
>>> private Parent cl = new Parent();
>>> private List clList = new ArrayList();
>>> private ParentDAO clDAO = new ParentDAOImpl();
>>>
>>> @Override
>>> public Parent getModel() {
>>> return cl;
>>> }
>>>
>>> public String saveOrUpdate()
>>> { // cl.values is empty here!!
>>> clDAO.saveOrUpdateParent(cl);
>>> return SUCCESS;
>>> }
>>>
>>> public String save()
>>> {
>>> clDAO.saveParent(cl);
>>> return SUCCESS;
>>> }
>>>
>>> public String list()
>>> {
>>> clList = clDAO.listParent();
>>> return SUCCESS;
>>> }
>>>
>>> public String delete()
>>> {
>>> HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
>>> clDAO.deleteParent(Long.parseLong(request.getParameter("id")));
>>> return SUCCESS;
>>> }
>>>
>>> public String edit()
>>> { // cl.values contains some valid Child elements here!!
>>> HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
>>> cl = clDAO.listParentById(Long.parseLong(request.getParameter("id")));
>>> }
>>> return SUCCESS;
>>> }
>>>
>>> public Parent getParent() {
>>> return cl;
>>> }
>>>
>>> public void setParent(Parent cl) {
>>> this.cl = cl;
>>> }
>>>
>>> public List getParentList() {
>>> return clList;
>>> }
>>>
>>> public void setParentList(List clList) {
>>> this.clList = clList;
>>> }
>>> }
>>>
>>>
>>>
>>>> Date: Thu, 1 Apr 2010 11:30:23 +0200
>>>> From: gielen@it-neering.net
>>>> To: user@struts.apache.org
>>>> Subject: Re: CRUD with a OneToMany association under Struts 2 / Hibernate 3
>>>>
>>>> Given the model you presented in the first post, your problem seems to
>>>> be that the posted values have not the correct name for the children's
>>>> form fields. The parameters names you would need are
>>>>
>>>> id
>>>> name
>>>> values[0].id
>>>> values[0].name
>>>> values[1].id
>>>> values[2].name
>>>> ...
>>>>
>>>> for the parameters interceptor to work properly when applying the posted
>>>> values.
>>>>
>>>> See here for more details:
>>>> http://struts.apache.org/2.1.8/docs/tabular-inputs.html
>>>>
>>>> - René
>>>>
>>>> bruno grandjean schrieb:
>>>>> Dear Rene,
>>>>>
>>>>> Thks a lot for replying to me because I am feeling a little bit alone with
>>>>> my CRUD ;-). In fact I am trying to build a dynamic MetaCrud.
>>>>> My pb is simple: in the same jsp page I would like to update a Parent
>>>>> object
>>>>> and its Childs (values):
>>>>>
>>>>>
>>>>>
>>>>>>>> name="name" label="Nom" />
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> From an existing Parent object with many Childs objects I can easily modify
>>>>> parent.name for instance but the collection of Child objects (values) is
>>>>> always empty in the ParentAction (saveOrUpdate() method) after submitting.
>>>>> However I can display each values[i].name in the jsp page with the correct
>>>>> value.
>>>>> So it is not an issue with Hibernate but with the jsp or ModelDriven
>>>>> interface I don't know..Do you have any idea?
>>>>> Basically I was not able to find a struts or spring documentation about
>>>>> CRUD
>>>>> & association between two entities on the same jsp page.
>>>>> best regards
>>>>> bruno
>>>>>
>>>>>
>>>>>
>>>>> --------------------------------------------------
>>>>> From: "Rene Gielen"
>>>>> Sent: Wednesday, March 31, 2010 7:12 PM
>>>>> To: "Struts Users Mailing List"
>>>>> Subject: Re: CRUD with a OneToMany association under Struts 2 / Hibernate 3
>>>>>
>>>>>> I'm not sure if I understand what your actual question is, nor whether
>>>>>> it is particularly Struts 2 related (rather than just Hibernate) - but
>>>>>> you might want to have a look in the CRUD demo section of the Struts 2
>>>>>> showcase application. Maybe you will also find this demo useful:
>>>>>> http://github.com/rgielen/struts2crudevolutiondemo
>>>>>>
>>>>>> - René
>>>>>>
>>>>>> bruno grandjean schrieb:
>>>>>>> Hi
>>>>>>>
>>>>>>> I am trying to implement a simple CRUD with a OneToMany association
>>>>>>> under Struts 2 / Hibernate 3.
>>>>>>> I have two entities Parent and Child:
>>>>>>>
>>>>>>> @Entity
>>>>>>> @Table(name="PARENT")
>>>>>>> public class Parent {
>>>>>>> private Long id;
>>>>>>> private Set values = new HashSet();
>>>>>>> ..
>>>>>>> @Entity
>>>>>>> @Table(name="CHILD")
>>>>>>> public class Child {
>>>>>>> private Long id;
>>>>>>> private String name;
>>>>>>> ..
>>>>>>>
>>>>>>> I can easily create, delete Parent or read the Child Set (values) but
>>>>>>> it is impossible to update Child Set.
>>>>>>> The jsp page (see below) reinit the values Set, no record after
>>>>>>> updating!
>>>>>>> Could u explain to me what's wrong?
>>>>>>>
>>>>>>> here are my code:
>>>>>>>
>>>>>>> @Entity
>>>>>>> @Table(name="PARENT")
>>>>>>> public class Parent {
>>>>>>> private Long id;
>>>>>>> private Set values = new HashSet();
>>>>>>> @Id
>>>>>>> @GeneratedValue
>>>>>>> @Column(name="PARENT_ID")
>>>>>>> public Long getId() {
>>>>>>> return id;
>>>>>>> }
>>>>>>> public void setId(Long id) {
>>>>>>> this.id = id;
>>>>>>> }
>>>>>>> @ManyToMany(fetch = FetchType.EAGER)
>>>>>>> @JoinTable(name = "PARENT_CHILD", joinColumns = { @JoinColumn(name =
>>>>>>> "PARENT_ID") }, inverseJoinColumns = { @JoinColumn(name = "CHILD_ID") })
>>>>>>> public Set getValues() {
>>>>>>> return values;
>>>>>>> }
>>>>>>> public void setValues(Set lst) {
>>>>>>> values = lst;
>>>>>>> }
>>>>>>> }
>>>>>>>
>>>>>>> @Entity
>>>>>>> @Table(name="CHILD")
>>>>>>> public class Child {
>>>>>>> private Long id;
>>>>>>> private String name;
>>>>>>> @Id
>>>>>>> @GeneratedValue
>>>>>>> @Column(name="CHILD_ID")
>>>>>>> public Long getId() {
>>>>>>> return id;
>>>>>>> }
>>>>>>> public void setId(Long id) {
>>>>>>> this.id = id;
>>>>>>> }
>>>>>>> @Column(name="NAME")
>>>>>>> public String getName() {
>>>>>>> return name;
>>>>>>> }
>>>>>>> public void setName(String val) {
>>>>>>> name = val;
>>>>>>> }
>>>>>>> }
>>>>>>>
>>>>>>> public interface ParentDAO {
>>>>>>> public void saveOrUpdateParent(Parent cl);
>>>>>>> public void saveParent(Parent cl);
>>>>>>> public List listParent();
>>>>>>> public Parent listParentById(Long clId);
>>>>>>> public void deleteParent(Long clId);
>>>>>>> }
>>>>>>>
>>>>>>> public class ParentDAOImpl implements ParentDAO {
>>>>>>> @SessionTarget
>>>>>>> Session session;
>>>>>>> @TransactionTarget
>>>>>>> Transaction transaction;
>>>>>>>
>>>>>>> @Override
>>>>>>> public void saveOrUpdateParent(Parent cl) {
>>>>>>> try {
>>>>>>> session.saveOrUpdate(cl);
>>>>>>> } catch (Exception e) {
>>>>>>> transaction.rollback();
>>>>>>> e.printStackTrace();
>>>>>>> }
>>>>>>> }
>>>>>>>
>>>>>>> @Override
>>>>>>> public void saveParent(Parent cl) {
>>>>>>> try {
>>>>>>> session.save(cl);
>>>>>>> } catch (Exception e) {
>>>>>>> transaction.rollback();
>>>>>>> e.printStackTrace();
>>>>>>> }
>>>>>>> }
>>>>>>>
>>>>>>> @Override
>>>>>>> public void deleteParent(Long clId) {
>>>>>>> try {
>>>>>>> Parent cl = (Parent) session.get(Parent.class, clId);
>>>>>>> session.delete(cl);
>>>>>>> } catch (Exception e) {
>>>>>>> transaction.rollback();
>>>>>>> e.printStackTrace();
>>>>>>> }
>>>>>>> }
>>>>>>>
>>>>>>> @SuppressWarnings("unchecked")
>>>>>>> @Override
>>>>>>> public List listParent() {
>>>>>>> List courses = null;
>>>>>>> try {
>>>>>>> courses = session.createQuery("from Parent").list();
>>>>>>> } catch (Exception e) {
>>>>>>> e.printStackTrace();
>>>>>>> }
>>>>>>> return courses;
>>>>>>> }
>>>>>>>
>>>>>>> @Override
>>>>>>> public Parent listParentById(Long clId) {
>>>>>>> Parent cl = null;
>>>>>>> try {
>>>>>>> cl = (Parent) session.get(Parent.class, clId);
>>>>>>> } catch (Exception e) {
>>>>>>> e.printStackTrace();
>>>>>>> }
>>>>>>> return cl;
>>>>>>> }
>>>>>>> }
>>>>>>>
>>>>>>> public class ParentAction extends ActionSupport implements
>>>>>>> ModelDriven {
>>>>>>>
>>>>>>> private static final long serialVersionUID = -2662966220408285700L;
>>>>>>> private Parent cl = new Parent();
>>>>>>> private List clList = new ArrayList();
>>>>>>> private ParentDAO clDAO = new ParentDAOImpl();
>>>>>>>
>>>>>>> @Override
>>>>>>> public Parent getModel() {
>>>>>>> return cl;
>>>>>>> }
>>>>>>>
>>>>>>> public String saveOrUpdate()
>>>>>>> {
>>>>>>> clDAO.saveOrUpdateParent(cl);
>>>>>>> return SUCCESS;
>>>>>>> }
>>>>>>>
>>>>>>> public String save()
>>>>>>> {
>>>>>>> clDAO.saveParent(cl);
>>>>>>> return SUCCESS;
>>>>>>> }
>>>>>>>
>>>>>>> public String list()
>>>>>>> {
>>>>>>> clList = clDAO.listParent();
>>>>>>> return SUCCESS;
>>>>>>> }
>>>>>>>
>>>>>>> public String delete()
>>>>>>> {
>>>>>>> HttpServletRequest request = (HttpServletRequest)
>>>>>>> ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
>>>>>>> clDAO.deleteParent(Long.parseLong(request.getParameter("id")));
>>>>>>> return SUCCESS;
>>>>>>> }
>>>>>>>
>>>>>>> public String edit()
>>>>>>> {
>>>>>>> HttpServletRequest request = (HttpServletRequest)
>>>>>>> ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
>>>>>>> cl = clDAO.listParentById(Long.parseLong(request.getParameter("id")));
>>>>>>> return SUCCESS;
>>>>>>> }
>>>>>>>
>>>>>>> public Parent getParent() {
>>>>>>> return cl;
>>>>>>> }
>>>>>>>
>>>>>>> public void setParent(Parent cl) {
>>>>>>> this.cl = cl;
>>>>>>> }
>>>>>>>
>>>>>>> public List getParentList() {
>>>>>>> return clList;
>>>>>>> }
>>>>>>>
>>>>>>> public void setParentList(List clList) {
>>>>>>> this.clList = clList;
>>>>>>> }
>>>>>>> }
>>>>>>>
>>>>>>> and finally the jsp page:
>>>>>>>
>>>>>>>
>>>>>>>>>>>> "http://www.w3.org/TR/html4/loose.dtd">
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>
>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>
>>>>>>>
>>
>>>>>>>
>>
>>
>>>>>>>
>> Child(s)
>>>>>>>
>>
>>>>>>>
>>>>>>>>>>>> class="oddeven">
>>>>>>>
>>
>>
>>>>>>>
>>>>>>>
>>
>>>>>>>
>>>>>>>
>>
>>>>>>>
>>>>>>> Edit
>>>>>>>
>>
>>>>>>>
>>>>>>> Delete
>>>>>>>
>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>
>>>>>> --
>>>>>> René Gielen
>>>>>> IT-Neering.net
>>>>>> Saarstrasse 100, 52062 Aachen, Germany
>>>>>> Tel: +49-(0)241-4010770
>>>>>> Fax: +49-(0)241-4010771
>>>>>> Cel: +49-(0)163-2844164
>>>>>> http://twitter.com/rgielen
>>>>>>
>>>>>> ---------------------------------------------------------------------
>>>>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>>>
>>>>>>
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>>
>>>>
>>>> --
>>>> René Gielen
>>>> IT-Neering.net
>>>> Saarstrasse 100, 52062 Aachen, Germany
>>>> Tel: +49-(0)241-4010770
>>>> Fax: +49-(0)241-4010771
>>>> Cel: +49-(0)163-2844164
>>>> http://twitter.com/rgielen
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>
>>>
>>> _________________________________________________________________
>>> Découvrez comment SURFER DISCRETEMENT sur un site de rencontres !
>>> http://clk.atdmt.com/FRM/go/206608211/direct/01/
>> _________________________________________________________________
>> Do you have a story that started on Hotmail? Tell us now
>> http://clk.atdmt.com/UKM/go/195013117/direct/01/
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>
> _________________________________________________________________
> Consultez gratuitement vos emails Orange, Gmail, Free, ... directement dans HOTMAIL !
> http://www.windowslive.fr/hotmail/agregation/ 		 	   		  
_________________________________________________________________
Do you have a story that started on Hotmail? Tell us now
http://clk.atdmt.com/UKM/go/195013117/direct/01/
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: CRUD with a OneToMany association under Struts 2 / Hibernate 3

Posted by bruno grandjean <br...@live.fr>.
Dear Adam,

 

I just added a public Child getValues(int idx) in the Parent class definition but it is never called.

 

Could u explain to me where and how can I turn on the parameterinterceptor logging? In the struts.xml file?

 

thks a lot


bruno

 


 
> From: apinder@hotmail.co.uk
> To: user@struts.apache.org
> Subject: RE: CRUD with a OneToMany association under Struts 2 / Hibernate 3
> Date: Thu, 1 Apr 2010 12:18:48 +0100
> 
> 
> 
> 
> turn on the parameterinterceptor logging and make sure as mentioned that 
> 
> 1) the values you expect for each child are being sent to the server (id and name)
> 2) the parameter names are correct for setting each child
> 
> i had some issues getting lists of items to be updated by form submission alone.
> 
> for example does your parent object have a getValues method taking an index value
> 
> getParent().getValues(1).setId(1)
> getParent().getValues(1).setName("bob")
> 
> would be called by parameterinterceptor
> 
> 
> ----------------------------------------
> > From: brgrandjean@live.fr
> > To: user@struts.apache.org
> > Subject: RE: CRUD with a OneToMany association under Struts 2 / Hibernate 3
> > Date: Thu, 1 Apr 2010 12:16:09 +0200
> >
> >
> > Dear René
> >
> >
> >
> > I changed my jsp page so as to integrate the following block:
> >
> >
> >
> > 
> > 
> > 
> > 
> >
> >
> >
> > which generates the following html code:
> >
> >
> >
> > 
> >
> > 
> >
> > 
> >
> > 
> >
> > 
> >
> > 
> >
> > 
> >
> > 
> >
> > 
> >
> > 
> >
> > 
> >
> >
> > I can display my complete Child Set but I got the same result after updating: my Child Set is empty.
> >
> >
> >
> > Is that necessary to modify my ParentAction as well? If yes what to do?
> >
> >
> >
> > public class ParentAction extends ActionSupport implements ModelDriven {
> >
> > private static final long serialVersionUID = -2662966220408285700L;
> > private Parent cl = new Parent();
> > private List clList = new ArrayList();
> > private ParentDAO clDAO = new ParentDAOImpl();
> >
> > @Override
> > public Parent getModel() {
> > return cl;
> > }
> >
> > public String saveOrUpdate()
> > { // cl.values is empty here!!
> > clDAO.saveOrUpdateParent(cl);
> > return SUCCESS;
> > }
> >
> > public String save()
> > {
> > clDAO.saveParent(cl);
> > return SUCCESS;
> > }
> >
> > public String list()
> > {
> > clList = clDAO.listParent();
> > return SUCCESS;
> > }
> >
> > public String delete()
> > {
> > HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
> > clDAO.deleteParent(Long.parseLong(request.getParameter("id")));
> > return SUCCESS;
> > }
> >
> > public String edit()
> > { // cl.values contains some valid Child elements here!!
> > HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
> > cl = clDAO.listParentById(Long.parseLong(request.getParameter("id")));
> > }
> > return SUCCESS;
> > }
> >
> > public Parent getParent() {
> > return cl;
> > }
> >
> > public void setParent(Parent cl) {
> > this.cl = cl;
> > }
> >
> > public List getParentList() {
> > return clList;
> > }
> >
> > public void setParentList(List clList) {
> > this.clList = clList;
> > }
> > }
> >
> >
> >
> >> Date: Thu, 1 Apr 2010 11:30:23 +0200
> >> From: gielen@it-neering.net
> >> To: user@struts.apache.org
> >> Subject: Re: CRUD with a OneToMany association under Struts 2 / Hibernate 3
> >>
> >> Given the model you presented in the first post, your problem seems to
> >> be that the posted values have not the correct name for the children's
> >> form fields. The parameters names you would need are
> >>
> >> id
> >> name
> >> values[0].id
> >> values[0].name
> >> values[1].id
> >> values[2].name
> >> ...
> >>
> >> for the parameters interceptor to work properly when applying the posted
> >> values.
> >>
> >> See here for more details:
> >> http://struts.apache.org/2.1.8/docs/tabular-inputs.html
> >>
> >> - René
> >>
> >> bruno grandjean schrieb:
> >>> Dear Rene,
> >>>
> >>> Thks a lot for replying to me because I am feeling a little bit alone with
> >>> my CRUD ;-). In fact I am trying to build a dynamic MetaCrud.
> >>> My pb is simple: in the same jsp page I would like to update a Parent
> >>> object
> >>> and its Childs (values):
> >>>
> >>> 
> >>> 
> >>>>>> name="name" label="Nom" />
> >>> 
> >>> 
> >>> 
> >>> 
> >>> 
> >>> 
> >>> 
> >>> 
> >>>
> >>> From an existing Parent object with many Childs objects I can easily modify
> >>> parent.name for instance but the collection of Child objects (values) is
> >>> always empty in the ParentAction (saveOrUpdate() method) after submitting.
> >>> However I can display each values[i].name in the jsp page with the correct
> >>> value.
> >>> So it is not an issue with Hibernate but with the jsp or ModelDriven
> >>> interface I don't know..Do you have any idea?
> >>> Basically I was not able to find a struts or spring documentation about
> >>> CRUD
> >>> & association between two entities on the same jsp page.
> >>> best regards
> >>> bruno
> >>>
> >>>
> >>>
> >>> --------------------------------------------------
> >>> From: "Rene Gielen" 
> >>> Sent: Wednesday, March 31, 2010 7:12 PM
> >>> To: "Struts Users Mailing List" 
> >>> Subject: Re: CRUD with a OneToMany association under Struts 2 / Hibernate 3
> >>>
> >>>> I'm not sure if I understand what your actual question is, nor whether
> >>>> it is particularly Struts 2 related (rather than just Hibernate) - but
> >>>> you might want to have a look in the CRUD demo section of the Struts 2
> >>>> showcase application. Maybe you will also find this demo useful:
> >>>> http://github.com/rgielen/struts2crudevolutiondemo
> >>>>
> >>>> - René
> >>>>
> >>>> bruno grandjean schrieb:
> >>>>> Hi
> >>>>>
> >>>>> I am trying to implement a simple CRUD with a OneToMany association
> >>>>> under Struts 2 / Hibernate 3.
> >>>>> I have two entities Parent and Child:
> >>>>>
> >>>>> @Entity
> >>>>> @Table(name="PARENT")
> >>>>> public class Parent {
> >>>>> private Long id;
> >>>>> private Set values = new HashSet();
> >>>>> ..
> >>>>> @Entity
> >>>>> @Table(name="CHILD")
> >>>>> public class Child {
> >>>>> private Long id;
> >>>>> private String name;
> >>>>> ..
> >>>>>
> >>>>> I can easily create, delete Parent or read the Child Set (values) but
> >>>>> it is impossible to update Child Set.
> >>>>> The jsp page (see below) reinit the values Set, no record after
> >>>>> updating!
> >>>>> Could u explain to me what's wrong?
> >>>>>
> >>>>> here are my code:
> >>>>>
> >>>>> @Entity
> >>>>> @Table(name="PARENT")
> >>>>> public class Parent {
> >>>>> private Long id;
> >>>>> private Set values = new HashSet();
> >>>>> @Id
> >>>>> @GeneratedValue
> >>>>> @Column(name="PARENT_ID")
> >>>>> public Long getId() {
> >>>>> return id;
> >>>>> }
> >>>>> public void setId(Long id) {
> >>>>> this.id = id;
> >>>>> }
> >>>>> @ManyToMany(fetch = FetchType.EAGER)
> >>>>> @JoinTable(name = "PARENT_CHILD", joinColumns = { @JoinColumn(name =
> >>>>> "PARENT_ID") }, inverseJoinColumns = { @JoinColumn(name = "CHILD_ID") })
> >>>>> public Set getValues() {
> >>>>> return values;
> >>>>> }
> >>>>> public void setValues(Set lst) {
> >>>>> values = lst;
> >>>>> }
> >>>>> }
> >>>>>
> >>>>> @Entity
> >>>>> @Table(name="CHILD")
> >>>>> public class Child {
> >>>>> private Long id;
> >>>>> private String name;
> >>>>> @Id
> >>>>> @GeneratedValue
> >>>>> @Column(name="CHILD_ID")
> >>>>> public Long getId() {
> >>>>> return id;
> >>>>> }
> >>>>> public void setId(Long id) {
> >>>>> this.id = id;
> >>>>> }
> >>>>> @Column(name="NAME")
> >>>>> public String getName() {
> >>>>> return name;
> >>>>> }
> >>>>> public void setName(String val) {
> >>>>> name = val;
> >>>>> }
> >>>>> }
> >>>>>
> >>>>> public interface ParentDAO {
> >>>>> public void saveOrUpdateParent(Parent cl);
> >>>>> public void saveParent(Parent cl);
> >>>>> public List listParent();
> >>>>> public Parent listParentById(Long clId);
> >>>>> public void deleteParent(Long clId);
> >>>>> }
> >>>>>
> >>>>> public class ParentDAOImpl implements ParentDAO {
> >>>>> @SessionTarget
> >>>>> Session session;
> >>>>> @TransactionTarget
> >>>>> Transaction transaction;
> >>>>>
> >>>>> @Override
> >>>>> public void saveOrUpdateParent(Parent cl) {
> >>>>> try {
> >>>>> session.saveOrUpdate(cl);
> >>>>> } catch (Exception e) {
> >>>>> transaction.rollback();
> >>>>> e.printStackTrace();
> >>>>> }
> >>>>> }
> >>>>>
> >>>>> @Override
> >>>>> public void saveParent(Parent cl) {
> >>>>> try {
> >>>>> session.save(cl);
> >>>>> } catch (Exception e) {
> >>>>> transaction.rollback();
> >>>>> e.printStackTrace();
> >>>>> }
> >>>>> }
> >>>>>
> >>>>> @Override
> >>>>> public void deleteParent(Long clId) {
> >>>>> try {
> >>>>> Parent cl = (Parent) session.get(Parent.class, clId);
> >>>>> session.delete(cl);
> >>>>> } catch (Exception e) {
> >>>>> transaction.rollback();
> >>>>> e.printStackTrace();
> >>>>> }
> >>>>> }
> >>>>>
> >>>>> @SuppressWarnings("unchecked")
> >>>>> @Override
> >>>>> public List listParent() {
> >>>>> List courses = null;
> >>>>> try {
> >>>>> courses = session.createQuery("from Parent").list();
> >>>>> } catch (Exception e) {
> >>>>> e.printStackTrace();
> >>>>> }
> >>>>> return courses;
> >>>>> }
> >>>>>
> >>>>> @Override
> >>>>> public Parent listParentById(Long clId) {
> >>>>> Parent cl = null;
> >>>>> try {
> >>>>> cl = (Parent) session.get(Parent.class, clId);
> >>>>> } catch (Exception e) {
> >>>>> e.printStackTrace();
> >>>>> }
> >>>>> return cl;
> >>>>> }
> >>>>> }
> >>>>>
> >>>>> public class ParentAction extends ActionSupport implements
> >>>>> ModelDriven {
> >>>>>
> >>>>> private static final long serialVersionUID = -2662966220408285700L;
> >>>>> private Parent cl = new Parent();
> >>>>> private List clList = new ArrayList();
> >>>>> private ParentDAO clDAO = new ParentDAOImpl();
> >>>>>
> >>>>> @Override
> >>>>> public Parent getModel() {
> >>>>> return cl;
> >>>>> }
> >>>>>
> >>>>> public String saveOrUpdate()
> >>>>> {
> >>>>> clDAO.saveOrUpdateParent(cl);
> >>>>> return SUCCESS;
> >>>>> }
> >>>>>
> >>>>> public String save()
> >>>>> {
> >>>>> clDAO.saveParent(cl);
> >>>>> return SUCCESS;
> >>>>> }
> >>>>>
> >>>>> public String list()
> >>>>> {
> >>>>> clList = clDAO.listParent();
> >>>>> return SUCCESS;
> >>>>> }
> >>>>>
> >>>>> public String delete()
> >>>>> {
> >>>>> HttpServletRequest request = (HttpServletRequest)
> >>>>> ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
> >>>>> clDAO.deleteParent(Long.parseLong(request.getParameter("id")));
> >>>>> return SUCCESS;
> >>>>> }
> >>>>>
> >>>>> public String edit()
> >>>>> {
> >>>>> HttpServletRequest request = (HttpServletRequest)
> >>>>> ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
> >>>>> cl = clDAO.listParentById(Long.parseLong(request.getParameter("id")));
> >>>>> return SUCCESS;
> >>>>> }
> >>>>>
> >>>>> public Parent getParent() {
> >>>>> return cl;
> >>>>> }
> >>>>>
> >>>>> public void setParent(Parent cl) {
> >>>>> this.cl = cl;
> >>>>> }
> >>>>>
> >>>>> public List getParentList() {
> >>>>> return clList;
> >>>>> }
> >>>>>
> >>>>> public void setParentList(List clList) {
> >>>>> this.clList = clList;
> >>>>> }
> >>>>> }
> >>>>>
> >>>>> and finally the jsp page:
> >>>>>
> >>>>> 
> >>>>>>>>>> "http://www.w3.org/TR/html4/loose.dtd">
> >>>>> 
> >>>>> 
> >>>>> 
> >>>>> 
> >>>>> 
> >>>>> 
> >>>>> 
> 
> 
> >>>>> 
> >>>>> 
> >>>>> 
> >>>>> 
> >>>>> 
> >>>>> 
> >>>>> 
> >>>>> 
> >>>>> 
> >>>>> 
> >>>>> 
> >>>>> 
> >>>>> 
> >>>>>
> >>>>> 
> >>>>> 
> 
> >>>>> 
> 
> >>>>> 
> 
> 
> >>>>> 
> Child(s)
> >>>>> 
> 
> >>>>> 
> >>>>>>>>>> class="oddeven">
> >>>>> 
> 
> 
> >>>>> 
> >>>>> 
> 
> >>>>> 
> >>>>> 
> 
> >>>>> 
> >>>>> Edit
> >>>>> 
> 
> >>>>> 
> >>>>> Delete
> >>>>> 
> 
> >>>>> 
> >>>>> 
> >>>>> 
> >>>>> 
> >>>>> 
> >>>>> 
> >>>>>
> >>>>
> >>>> --
> >>>> René Gielen
> >>>> IT-Neering.net
> >>>> Saarstrasse 100, 52062 Aachen, Germany
> >>>> Tel: +49-(0)241-4010770
> >>>> Fax: +49-(0)241-4010771
> >>>> Cel: +49-(0)163-2844164
> >>>> http://twitter.com/rgielen
> >>>>
> >>>> ---------------------------------------------------------------------
> >>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >>>> For additional commands, e-mail: user-help@struts.apache.org
> >>>>
> >>>>
> >>>
> >>> ---------------------------------------------------------------------
> >>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >>> For additional commands, e-mail: user-help@struts.apache.org
> >>>
> >>
> >> --
> >> René Gielen
> >> IT-Neering.net
> >> Saarstrasse 100, 52062 Aachen, Germany
> >> Tel: +49-(0)241-4010770
> >> Fax: +49-(0)241-4010771
> >> Cel: +49-(0)163-2844164
> >> http://twitter.com/rgielen
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >> For additional commands, e-mail: user-help@struts.apache.org
> >>
> >
> > _________________________________________________________________
> > Découvrez comment SURFER DISCRETEMENT sur un site de rencontres !
> > http://clk.atdmt.com/FRM/go/206608211/direct/01/ 
> _________________________________________________________________
> Do you have a story that started on Hotmail? Tell us now
> http://clk.atdmt.com/UKM/go/195013117/direct/01/
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
 		 	   		  
_________________________________________________________________
Consultez gratuitement vos emails Orange, Gmail, Free, ... directement dans HOTMAIL !
http://www.windowslive.fr/hotmail/agregation/

RE: CRUD with a OneToMany association under Struts 2 / Hibernate 3

Posted by adam pinder <ap...@hotmail.co.uk>.
 
 
turn on the parameterinterceptor logging and make sure as mentioned that 
 
1) the values you expect for each child are being sent to the server (id and name)
2) the parameter names are correct for setting each child
 
i had some issues getting lists of items to be updated by form submission alone.
 
for example does your parent object have a getValues method taking an index value
 
getParent().getValues(1).setId(1)
getParent().getValues(1).setName("bob")
 
would be called by parameterinterceptor


----------------------------------------
> From: brgrandjean@live.fr
> To: user@struts.apache.org
> Subject: RE: CRUD with a OneToMany association under Struts 2 / Hibernate 3
> Date: Thu, 1 Apr 2010 12:16:09 +0200
>
>
> Dear René
>
>
>
> I changed my jsp page so as to integrate the following block:
>
>
>
> 
> 
> 
> 
>
>
>
> which generates the following html code:
>
>
>
> 
>
> 
>
> 
>
> 
>
> 
>
> 
>
> 
>
> 
>
> 
>
> 
>
> 
>
>
> I can display my complete Child Set but I got the same result after updating: my Child Set is empty.
>
>
>
> Is that necessary to modify my ParentAction as well? If yes what to do?
>
>
>
> public class ParentAction extends ActionSupport implements ModelDriven {
>
> private static final long serialVersionUID = -2662966220408285700L;
> private Parent cl = new Parent();
> private List clList = new ArrayList();
> private ParentDAO clDAO = new ParentDAOImpl();
>
> @Override
> public Parent getModel() {
> return cl;
> }
>
> public String saveOrUpdate()
> { // cl.values is empty here!!
> clDAO.saveOrUpdateParent(cl);
> return SUCCESS;
> }
>
> public String save()
> {
> clDAO.saveParent(cl);
> return SUCCESS;
> }
>
> public String list()
> {
> clList = clDAO.listParent();
> return SUCCESS;
> }
>
> public String delete()
> {
> HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
> clDAO.deleteParent(Long.parseLong(request.getParameter("id")));
> return SUCCESS;
> }
>
> public String edit()
> { // cl.values contains some valid Child elements here!!
> HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
> cl = clDAO.listParentById(Long.parseLong(request.getParameter("id")));
> }
> return SUCCESS;
> }
>
> public Parent getParent() {
> return cl;
> }
>
> public void setParent(Parent cl) {
> this.cl = cl;
> }
>
> public List getParentList() {
> return clList;
> }
>
> public void setParentList(List clList) {
> this.clList = clList;
> }
> }
>
>
>
>> Date: Thu, 1 Apr 2010 11:30:23 +0200
>> From: gielen@it-neering.net
>> To: user@struts.apache.org
>> Subject: Re: CRUD with a OneToMany association under Struts 2 / Hibernate 3
>>
>> Given the model you presented in the first post, your problem seems to
>> be that the posted values have not the correct name for the children's
>> form fields. The parameters names you would need are
>>
>> id
>> name
>> values[0].id
>> values[0].name
>> values[1].id
>> values[2].name
>> ...
>>
>> for the parameters interceptor to work properly when applying the posted
>> values.
>>
>> See here for more details:
>> http://struts.apache.org/2.1.8/docs/tabular-inputs.html
>>
>> - René
>>
>> bruno grandjean schrieb:
>>> Dear Rene,
>>>
>>> Thks a lot for replying to me because I am feeling a little bit alone with
>>> my CRUD ;-). In fact I am trying to build a dynamic MetaCrud.
>>> My pb is simple: in the same jsp page I would like to update a Parent
>>> object
>>> and its Childs (values):
>>>
>>> 
>>> 
>>>>>> name="name" label="Nom" />
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>>
>>> From an existing Parent object with many Childs objects I can easily modify
>>> parent.name for instance but the collection of Child objects (values) is
>>> always empty in the ParentAction (saveOrUpdate() method) after submitting.
>>> However I can display each values[i].name in the jsp page with the correct
>>> value.
>>> So it is not an issue with Hibernate but with the jsp or ModelDriven
>>> interface I don't know..Do you have any idea?
>>> Basically I was not able to find a struts or spring documentation about
>>> CRUD
>>> & association between two entities on the same jsp page.
>>> best regards
>>> bruno
>>>
>>>
>>>
>>> --------------------------------------------------
>>> From: "Rene Gielen" 
>>> Sent: Wednesday, March 31, 2010 7:12 PM
>>> To: "Struts Users Mailing List" 
>>> Subject: Re: CRUD with a OneToMany association under Struts 2 / Hibernate 3
>>>
>>>> I'm not sure if I understand what your actual question is, nor whether
>>>> it is particularly Struts 2 related (rather than just Hibernate) - but
>>>> you might want to have a look in the CRUD demo section of the Struts 2
>>>> showcase application. Maybe you will also find this demo useful:
>>>> http://github.com/rgielen/struts2crudevolutiondemo
>>>>
>>>> - René
>>>>
>>>> bruno grandjean schrieb:
>>>>> Hi
>>>>>
>>>>> I am trying to implement a simple CRUD with a OneToMany association
>>>>> under Struts 2 / Hibernate 3.
>>>>> I have two entities Parent and Child:
>>>>>
>>>>> @Entity
>>>>> @Table(name="PARENT")
>>>>> public class Parent {
>>>>> private Long id;
>>>>> private Set values = new HashSet();
>>>>> ..
>>>>> @Entity
>>>>> @Table(name="CHILD")
>>>>> public class Child {
>>>>> private Long id;
>>>>> private String name;
>>>>> ..
>>>>>
>>>>> I can easily create, delete Parent or read the Child Set (values) but
>>>>> it is impossible to update Child Set.
>>>>> The jsp page (see below) reinit the values Set, no record after
>>>>> updating!
>>>>> Could u explain to me what's wrong?
>>>>>
>>>>> here are my code:
>>>>>
>>>>> @Entity
>>>>> @Table(name="PARENT")
>>>>> public class Parent {
>>>>> private Long id;
>>>>> private Set values = new HashSet();
>>>>> @Id
>>>>> @GeneratedValue
>>>>> @Column(name="PARENT_ID")
>>>>> public Long getId() {
>>>>> return id;
>>>>> }
>>>>> public void setId(Long id) {
>>>>> this.id = id;
>>>>> }
>>>>> @ManyToMany(fetch = FetchType.EAGER)
>>>>> @JoinTable(name = "PARENT_CHILD", joinColumns = { @JoinColumn(name =
>>>>> "PARENT_ID") }, inverseJoinColumns = { @JoinColumn(name = "CHILD_ID") })
>>>>> public Set getValues() {
>>>>> return values;
>>>>> }
>>>>> public void setValues(Set lst) {
>>>>> values = lst;
>>>>> }
>>>>> }
>>>>>
>>>>> @Entity
>>>>> @Table(name="CHILD")
>>>>> public class Child {
>>>>> private Long id;
>>>>> private String name;
>>>>> @Id
>>>>> @GeneratedValue
>>>>> @Column(name="CHILD_ID")
>>>>> public Long getId() {
>>>>> return id;
>>>>> }
>>>>> public void setId(Long id) {
>>>>> this.id = id;
>>>>> }
>>>>> @Column(name="NAME")
>>>>> public String getName() {
>>>>> return name;
>>>>> }
>>>>> public void setName(String val) {
>>>>> name = val;
>>>>> }
>>>>> }
>>>>>
>>>>> public interface ParentDAO {
>>>>> public void saveOrUpdateParent(Parent cl);
>>>>> public void saveParent(Parent cl);
>>>>> public List listParent();
>>>>> public Parent listParentById(Long clId);
>>>>> public void deleteParent(Long clId);
>>>>> }
>>>>>
>>>>> public class ParentDAOImpl implements ParentDAO {
>>>>> @SessionTarget
>>>>> Session session;
>>>>> @TransactionTarget
>>>>> Transaction transaction;
>>>>>
>>>>> @Override
>>>>> public void saveOrUpdateParent(Parent cl) {
>>>>> try {
>>>>> session.saveOrUpdate(cl);
>>>>> } catch (Exception e) {
>>>>> transaction.rollback();
>>>>> e.printStackTrace();
>>>>> }
>>>>> }
>>>>>
>>>>> @Override
>>>>> public void saveParent(Parent cl) {
>>>>> try {
>>>>> session.save(cl);
>>>>> } catch (Exception e) {
>>>>> transaction.rollback();
>>>>> e.printStackTrace();
>>>>> }
>>>>> }
>>>>>
>>>>> @Override
>>>>> public void deleteParent(Long clId) {
>>>>> try {
>>>>> Parent cl = (Parent) session.get(Parent.class, clId);
>>>>> session.delete(cl);
>>>>> } catch (Exception e) {
>>>>> transaction.rollback();
>>>>> e.printStackTrace();
>>>>> }
>>>>> }
>>>>>
>>>>> @SuppressWarnings("unchecked")
>>>>> @Override
>>>>> public List listParent() {
>>>>> List courses = null;
>>>>> try {
>>>>> courses = session.createQuery("from Parent").list();
>>>>> } catch (Exception e) {
>>>>> e.printStackTrace();
>>>>> }
>>>>> return courses;
>>>>> }
>>>>>
>>>>> @Override
>>>>> public Parent listParentById(Long clId) {
>>>>> Parent cl = null;
>>>>> try {
>>>>> cl = (Parent) session.get(Parent.class, clId);
>>>>> } catch (Exception e) {
>>>>> e.printStackTrace();
>>>>> }
>>>>> return cl;
>>>>> }
>>>>> }
>>>>>
>>>>> public class ParentAction extends ActionSupport implements
>>>>> ModelDriven {
>>>>>
>>>>> private static final long serialVersionUID = -2662966220408285700L;
>>>>> private Parent cl = new Parent();
>>>>> private List clList = new ArrayList();
>>>>> private ParentDAO clDAO = new ParentDAOImpl();
>>>>>
>>>>> @Override
>>>>> public Parent getModel() {
>>>>> return cl;
>>>>> }
>>>>>
>>>>> public String saveOrUpdate()
>>>>> {
>>>>> clDAO.saveOrUpdateParent(cl);
>>>>> return SUCCESS;
>>>>> }
>>>>>
>>>>> public String save()
>>>>> {
>>>>> clDAO.saveParent(cl);
>>>>> return SUCCESS;
>>>>> }
>>>>>
>>>>> public String list()
>>>>> {
>>>>> clList = clDAO.listParent();
>>>>> return SUCCESS;
>>>>> }
>>>>>
>>>>> public String delete()
>>>>> {
>>>>> HttpServletRequest request = (HttpServletRequest)
>>>>> ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
>>>>> clDAO.deleteParent(Long.parseLong(request.getParameter("id")));
>>>>> return SUCCESS;
>>>>> }
>>>>>
>>>>> public String edit()
>>>>> {
>>>>> HttpServletRequest request = (HttpServletRequest)
>>>>> ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
>>>>> cl = clDAO.listParentById(Long.parseLong(request.getParameter("id")));
>>>>> return SUCCESS;
>>>>> }
>>>>>
>>>>> public Parent getParent() {
>>>>> return cl;
>>>>> }
>>>>>
>>>>> public void setParent(Parent cl) {
>>>>> this.cl = cl;
>>>>> }
>>>>>
>>>>> public List getParentList() {
>>>>> return clList;
>>>>> }
>>>>>
>>>>> public void setParentList(List clList) {
>>>>> this.clList = clList;
>>>>> }
>>>>> }
>>>>>
>>>>> and finally the jsp page:
>>>>>
>>>>> 
>>>>>>>>>> "http://www.w3.org/TR/html4/loose.dtd">
>>>>> 
>>>>> 
>>>>> 
>>>>> 
>>>>> 
>>>>> 
>>>>> 


>>>>> 
>>>>> 
>>>>> 
>>>>> 
>>>>> 
>>>>> 
>>>>> 
>>>>> 
>>>>> 
>>>>> 
>>>>> 
>>>>> 
>>>>> 
>>>>>
>>>>> 
>>>>> 

>>>>> 

>>>>> 


>>>>> 
Child(s)
>>>>> 

>>>>> 
>>>>>>>>>> class="oddeven">
>>>>> 


>>>>> 
>>>>> 

>>>>> 
>>>>> 

>>>>> 
>>>>> Edit
>>>>> 

>>>>> 
>>>>> Delete
>>>>> 

>>>>> 
>>>>> 
>>>>> 
>>>>> 
>>>>> 
>>>>> 
>>>>>
>>>>
>>>> --
>>>> René Gielen
>>>> IT-Neering.net
>>>> Saarstrasse 100, 52062 Aachen, Germany
>>>> Tel: +49-(0)241-4010770
>>>> Fax: +49-(0)241-4010771
>>>> Cel: +49-(0)163-2844164
>>>> http://twitter.com/rgielen
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>> For additional commands, e-mail: user-help@struts.apache.org
>>>
>>
>> --
>> René Gielen
>> IT-Neering.net
>> Saarstrasse 100, 52062 Aachen, Germany
>> Tel: +49-(0)241-4010770
>> Fax: +49-(0)241-4010771
>> Cel: +49-(0)163-2844164
>> http://twitter.com/rgielen
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>
> _________________________________________________________________
> Découvrez comment SURFER DISCRETEMENT sur un site de rencontres !
> http://clk.atdmt.com/FRM/go/206608211/direct/01/ 		 	   		  
_________________________________________________________________
Do you have a story that started on Hotmail? Tell us now
http://clk.atdmt.com/UKM/go/195013117/direct/01/
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: CRUD with a OneToMany association under Struts 2 / Hibernate 3

Posted by bruno grandjean <br...@live.fr>.
Dear René

 

I changed my jsp page so as to integrate the following block:

 

<s:iterator value="parent.values" status="rowstatus">
<s:hidden name="parent.values[%{#rowstatus.index}].id" value="%{id}" />
<s:textfield name="parent.values[%{#rowstatus.index}].name" value="%{name}" /> 
</s:iterator>

 

which generates the following html code:

 

<input type="hidden" name="parent.values[0].id" value="1" id="saveOrUpdateParent_parent_values_0__id"/>

<tr>

<td class="tdLabel"></td>

<td><input type="text" name="parent.values[0].name" value="Child1" id="saveOrUpdateParent_parent_values_0__name"/></td>

</tr>  

<input type="hidden" name="parent.values[1].id" value="2" id="saveOrUpdateParent_parent_values_1__id"/>

<tr>

<td class="tdLabel"></td>

<td>

<input type="text" name="parent.values[1].name" value="Child2" id="saveOrUpdateParent_parent_values_1__name"/></td>

</tr>
  

I can display my complete Child Set but I got the same result after updating: my Child Set is empty.

 

Is that necessary to modify my ParentAction as well? If yes what to do?

 

public class ParentAction extends ActionSupport implements ModelDriven<Parent> {

private static final long serialVersionUID = -2662966220408285700L;
private Parent cl = new Parent();
private List<Parent> clList = new ArrayList<Parent>(); 
private ParentDAO clDAO = new ParentDAOImpl();

@Override
public Parent getModel() {
return cl;
}

public String saveOrUpdate()
{ // cl.values is empty here!!
clDAO.saveOrUpdateParent(cl); 
return SUCCESS;
}

public String save()
{ 
clDAO.saveParent(cl); 
return SUCCESS;
}

public String list()
{
clList = clDAO.listParent();
return SUCCESS;
}

public String delete()
{
HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
clDAO.deleteParent(Long.parseLong(request.getParameter("id")));
return SUCCESS;
}

public String edit()
{ // cl.values contains some valid Child elements here!!
HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
cl = clDAO.listParentById(Long.parseLong(request.getParameter("id")));
} 
return SUCCESS;
}

public Parent getParent() {
return cl;
}

public void setParent(Parent cl) {
this.cl = cl;
}

public List<Parent> getParentList() {
return clList;
}

public void setParentList(List<Parent> clList) {
this.clList = clList;
}
}


 
> Date: Thu, 1 Apr 2010 11:30:23 +0200
> From: gielen@it-neering.net
> To: user@struts.apache.org
> Subject: Re: CRUD with a OneToMany association under Struts 2 / Hibernate 3
> 
> Given the model you presented in the first post, your problem seems to
> be that the posted values have not the correct name for the children's
> form fields. The parameters names you would need are
> 
> id
> name
> values[0].id
> values[0].name
> values[1].id
> values[2].name
> ...
> 
> for the parameters interceptor to work properly when applying the posted
> values.
> 
> See here for more details:
> http://struts.apache.org/2.1.8/docs/tabular-inputs.html
> 
> - René
> 
> bruno grandjean schrieb:
> > Dear Rene,
> > 
> > Thks a lot for replying to me because I am feeling a little bit alone with
> > my CRUD ;-). In fact I am trying to build a dynamic MetaCrud.
> > My pb is simple: in the same jsp page I would like to update a Parent
> > object
> > and its Childs (values):
> > 
> > <s:form action="saveOrUpdateParent">
> > <s:push value="parent">
> > <s:hidden name="id" /> <s:textfield
> > name="name" label="Nom" />
> > <s:push value="values">
> > <s:iterator id="p" value="values">
> > <s:textfield label="Nom" name="#name" value="%{name}"/>
> > </s:iterator>
> > </s:push>
> > <s:submit />
> > </s:push>
> > </s:form>
> > 
> > From an existing Parent object with many Childs objects I can easily modify
> > parent.name for instance but the collection of Child objects (values) is
> > always empty in the ParentAction (saveOrUpdate() method) after submitting.
> > However I can display each values[i].name in the jsp page with the correct
> > value.
> > So it is not an issue with Hibernate but with the jsp or ModelDriven
> > interface I don't know..Do you have any idea?
> > Basically I was not able to find a struts or spring documentation about
> > CRUD
> > & association between two entities on the same jsp page.
> > best regards
> > bruno
> > 
> > 
> > 
> > --------------------------------------------------
> > From: "Rene Gielen" <gi...@it-neering.net>
> > Sent: Wednesday, March 31, 2010 7:12 PM
> > To: "Struts Users Mailing List" <us...@struts.apache.org>
> > Subject: Re: CRUD with a OneToMany association under Struts 2 / Hibernate 3
> > 
> >> I'm not sure if I understand what your actual question is, nor whether
> >> it is particularly Struts 2 related (rather than just Hibernate) - but
> >> you might want to have a look in the CRUD demo section of the Struts 2
> >> showcase application. Maybe you will also find this demo useful:
> >> http://github.com/rgielen/struts2crudevolutiondemo
> >>
> >> - René
> >>
> >> bruno grandjean schrieb:
> >>> Hi
> >>>
> >>> I am trying to implement a simple CRUD with a OneToMany association
> >>> under Struts 2 / Hibernate 3.
> >>> I have two entities Parent and Child:
> >>>
> >>> @Entity
> >>> @Table(name="PARENT")
> >>> public class Parent {
> >>> private Long id;
> >>> private Set<Child> values = new HashSet<Child>();
> >>> ..
> >>> @Entity
> >>> @Table(name="CHILD")
> >>> public class Child {
> >>> private Long id;
> >>> private String name;
> >>> ..
> >>>
> >>> I can easily create, delete Parent or read the Child Set (values) but
> >>> it is impossible to update Child Set.
> >>> The jsp page (see below) reinit the values Set, no record after
> >>> updating!
> >>> Could u explain to me what's wrong?
> >>>
> >>> here are my code:
> >>>
> >>> @Entity
> >>> @Table(name="PARENT")
> >>> public class Parent {
> >>> private Long id;
> >>> private Set<Child> values = new HashSet<Child>();
> >>> @Id
> >>> @GeneratedValue
> >>> @Column(name="PARENT_ID")
> >>> public Long getId() {
> >>> return id;
> >>> }
> >>> public void setId(Long id) {
> >>> this.id = id;
> >>> }
> >>> @ManyToMany(fetch = FetchType.EAGER)
> >>> @JoinTable(name = "PARENT_CHILD", joinColumns = { @JoinColumn(name =
> >>> "PARENT_ID") }, inverseJoinColumns = { @JoinColumn(name = "CHILD_ID") })
> >>> public Set<Child> getValues() {
> >>> return values;
> >>> }
> >>> public void setValues(Set<Child> lst) {
> >>> values = lst;
> >>> }
> >>> }
> >>>
> >>> @Entity
> >>> @Table(name="CHILD")
> >>> public class Child {
> >>> private Long id;
> >>> private String name;
> >>> @Id
> >>> @GeneratedValue
> >>> @Column(name="CHILD_ID")
> >>> public Long getId() {
> >>> return id;
> >>> }
> >>> public void setId(Long id) {
> >>> this.id = id;
> >>> }
> >>> @Column(name="NAME")
> >>> public String getName() {
> >>> return name;
> >>> }
> >>> public void setName(String val) {
> >>> name = val;
> >>> }
> >>> }
> >>>
> >>> public interface ParentDAO {
> >>> public void saveOrUpdateParent(Parent cl);
> >>> public void saveParent(Parent cl);
> >>> public List<Parent> listParent();
> >>> public Parent listParentById(Long clId);
> >>> public void deleteParent(Long clId);
> >>> }
> >>>
> >>> public class ParentDAOImpl implements ParentDAO {
> >>> @SessionTarget
> >>> Session session;
> >>> @TransactionTarget
> >>> Transaction transaction;
> >>>
> >>> @Override
> >>> public void saveOrUpdateParent(Parent cl) {
> >>> try {
> >>> session.saveOrUpdate(cl);
> >>> } catch (Exception e) {
> >>> transaction.rollback();
> >>> e.printStackTrace();
> >>> }
> >>> }
> >>>
> >>> @Override
> >>> public void saveParent(Parent cl) {
> >>> try {
> >>> session.save(cl);
> >>> } catch (Exception e) {
> >>> transaction.rollback();
> >>> e.printStackTrace();
> >>> }
> >>> }
> >>>
> >>> @Override
> >>> public void deleteParent(Long clId) {
> >>> try {
> >>> Parent cl = (Parent) session.get(Parent.class, clId);
> >>> session.delete(cl);
> >>> } catch (Exception e) {
> >>> transaction.rollback();
> >>> e.printStackTrace();
> >>> }
> >>> }
> >>>
> >>> @SuppressWarnings("unchecked")
> >>> @Override
> >>> public List<Parent> listParent() {
> >>> List<Parent> courses = null;
> >>> try {
> >>> courses = session.createQuery("from Parent").list();
> >>> } catch (Exception e) {
> >>> e.printStackTrace();
> >>> }
> >>> return courses;
> >>> }
> >>>
> >>> @Override
> >>> public Parent listParentById(Long clId) {
> >>> Parent cl = null;
> >>> try {
> >>> cl = (Parent) session.get(Parent.class, clId);
> >>> } catch (Exception e) {
> >>> e.printStackTrace();
> >>> }
> >>> return cl;
> >>> }
> >>> }
> >>>
> >>> public class ParentAction extends ActionSupport implements
> >>> ModelDriven<Parent> {
> >>>
> >>> private static final long serialVersionUID = -2662966220408285700L;
> >>> private Parent cl = new Parent();
> >>> private List<Parent> clList = new ArrayList<Parent>();
> >>> private ParentDAO clDAO = new ParentDAOImpl();
> >>>
> >>> @Override
> >>> public Parent getModel() {
> >>> return cl;
> >>> }
> >>>
> >>> public String saveOrUpdate()
> >>> {
> >>> clDAO.saveOrUpdateParent(cl);
> >>> return SUCCESS;
> >>> }
> >>>
> >>> public String save()
> >>> {
> >>> clDAO.saveParent(cl);
> >>> return SUCCESS;
> >>> }
> >>>
> >>> public String list()
> >>> {
> >>> clList = clDAO.listParent();
> >>> return SUCCESS;
> >>> }
> >>>
> >>> public String delete()
> >>> {
> >>> HttpServletRequest request = (HttpServletRequest)
> >>> ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
> >>> clDAO.deleteParent(Long.parseLong(request.getParameter("id")));
> >>> return SUCCESS;
> >>> }
> >>>
> >>> public String edit()
> >>> {
> >>> HttpServletRequest request = (HttpServletRequest)
> >>> ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
> >>> cl = clDAO.listParentById(Long.parseLong(request.getParameter("id")));
> >>> return SUCCESS;
> >>> }
> >>>
> >>> public Parent getParent() {
> >>> return cl;
> >>> }
> >>>
> >>> public void setParent(Parent cl) {
> >>> this.cl = cl;
> >>> }
> >>>
> >>> public List<Parent> getParentList() {
> >>> return clList;
> >>> }
> >>>
> >>> public void setParentList(List<Parent> clList) {
> >>> this.clList = clList;
> >>> }
> >>> }
> >>>
> >>> and finally the jsp page:
> >>>
> >>> <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
> >>> pageEncoding="ISO-8859-1"%>
> >>> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
> >>> "http://www.w3.org/TR/html4/loose.dtd">
> >>> <%@taglib uri="/struts-tags" prefix="s"%>
> >>> <html>
> >>> <head>
> >>> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
> >>> <title>Parent Registration Page</title>
> >>> <s:head />
> >>> <style type="text/css">
> >>> @import url(style.css);
> >>> </style>
> >>> </head>
> >>> <body>
> >>> <s:form action="saveOrUpdateParent">
> >>> <s:push value="parent">
> >>> <s:hidden name="id" />
> >>> <s:push value="values">
> >>> <s:iterator id="p" value="values">
> >>> <s:textfield label="Nom" name="values(%{id}).name" value="%{name}"/>
> >>> </s:iterator>
> >>> </s:push>
> >>> <s:submit />
> >>> </s:push>
> >>> </s:form>
> >>>
> >>> <s:if test="parentList.size() > 0">
> >>> <div class="content">
> >>> <table class="userTable" cellpadding="5px">
> >>> <tr class="even">
> >>> <th>Child(s)</th>
> >>> </tr>
> >>> <s:iterator value="parentList" status="userStatus">
> >>> <tr
> >>> class="<s:if test="#userStatus.odd == true
> >>> ">odd</s:if><s:else>even</s:else>">
> >>> <td><s:property value="values.size()" /></td>
> >>> <s:iterator value="values">
> >>> <td><s:property value="name" /></td>
> >>> </s:iterator>
> >>> <td><s:url id="editURL" action="editParent">
> >>> <s:param name="id" value="%{id}"></s:param>
> >>> </s:url> <s:a href="%{editURL}">Edit</s:a></td>
> >>> <td><s:url id="deleteURL" action="deleteParent">
> >>> <s:param name="id" value="%{id}"></s:param>
> >>> </s:url> <s:a href="%{deleteURL}">Delete</s:a></td>
> >>> </tr>
> >>> </s:iterator>
> >>> </table>
> >>> </div>
> >>> </s:if>
> >>> </body>
> >>> </html>
> >>>
> >>
> >> -- 
> >> René Gielen
> >> IT-Neering.net
> >> Saarstrasse 100, 52062 Aachen, Germany
> >> Tel: +49-(0)241-4010770
> >> Fax: +49-(0)241-4010771
> >> Cel: +49-(0)163-2844164
> >> http://twitter.com/rgielen
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >> For additional commands, e-mail: user-help@struts.apache.org
> >>
> >>
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> > 
> 
> -- 
> René Gielen
> IT-Neering.net
> Saarstrasse 100, 52062 Aachen, Germany
> Tel: +49-(0)241-4010770
> Fax: +49-(0)241-4010771
> Cel: +49-(0)163-2844164
> http://twitter.com/rgielen
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
 		 	   		  
_________________________________________________________________
Découvrez comment SURFER DISCRETEMENT sur un site de rencontres !
http://clk.atdmt.com/FRM/go/206608211/direct/01/

Re: CRUD with a OneToMany association under Struts 2 / Hibernate 3

Posted by Rene Gielen <gi...@it-neering.net>.
Given the model you presented in the first post, your problem seems to
be that the posted values have not the correct name for the children's
form fields. The parameters names you would need are

id
name
values[0].id
values[0].name
values[1].id
values[2].name
...

for the parameters interceptor to work properly when applying the posted
values.

See here for more details:
http://struts.apache.org/2.1.8/docs/tabular-inputs.html

- René

bruno grandjean schrieb:
> Dear Rene,
> 
> Thks a lot for replying to me because I am feeling a little bit alone with
> my CRUD ;-). In fact I am trying to build a dynamic MetaCrud.
> My pb is simple: in the same jsp page I would like to update a Parent
> object
> and its Childs (values):
> 
> <s:form action="saveOrUpdateParent">
> <s:push value="parent">
> <s:hidden name="id" /> <s:textfield
> name="name" label="Nom" />
> <s:push value="values">
>  <s:iterator id="p" value="values">
>    <s:textfield label="Nom" name="#name" value="%{name}"/>
>                                </s:iterator>
> </s:push>
> <s:submit />
> </s:push>
> </s:form>
> 
> From an existing Parent object with many Childs objects I can easily modify
> parent.name for instance but the collection of Child objects (values) is
> always empty in the ParentAction (saveOrUpdate() method) after submitting.
> However I can display each values[i].name in the jsp page with the correct
> value.
> So it is not an issue with Hibernate but with the jsp or ModelDriven
> interface I don't know..Do you have any idea?
> Basically I was not able to find a struts or spring documentation about
> CRUD
> & association between two entities on the same jsp page.
> best regards
> bruno
> 
> 
> 
> --------------------------------------------------
> From: "Rene Gielen" <gi...@it-neering.net>
> Sent: Wednesday, March 31, 2010 7:12 PM
> To: "Struts Users Mailing List" <us...@struts.apache.org>
> Subject: Re: CRUD with a OneToMany association under Struts 2 / Hibernate 3
> 
>> I'm not sure if I understand what your actual question is, nor whether
>> it is particularly Struts 2 related (rather than just Hibernate) - but
>> you might want to have a look in the CRUD demo section of the Struts 2
>> showcase application. Maybe you will also find this demo useful:
>> http://github.com/rgielen/struts2crudevolutiondemo
>>
>> - René
>>
>> bruno grandjean schrieb:
>>> Hi
>>>
>>> I am trying to implement a simple CRUD with a OneToMany association
>>> under Struts 2 / Hibernate 3.
>>> I have two entities Parent and Child:
>>>
>>> @Entity
>>> @Table(name="PARENT")
>>> public class Parent {
>>>  private Long id;
>>>  private Set<Child> values = new HashSet<Child>();
>>> ..
>>> @Entity
>>> @Table(name="CHILD")
>>> public class Child {
>>>  private Long id;
>>>  private String name;
>>> ..
>>>
>>> I can easily create, delete Parent or read the Child Set (values) but
>>> it is impossible to update Child Set.
>>> The jsp page (see below) reinit the values Set, no record after
>>> updating!
>>> Could u explain to me what's wrong?
>>>
>>> here are my code:
>>>
>>> @Entity
>>> @Table(name="PARENT")
>>> public class Parent {
>>>  private Long id;
>>>  private Set<Child> values = new HashSet<Child>();
>>>  @Id
>>>  @GeneratedValue
>>>  @Column(name="PARENT_ID")
>>>  public Long getId() {
>>>   return id;
>>>  }
>>>  public void setId(Long id) {
>>>   this.id = id;
>>>  }
>>>  @ManyToMany(fetch = FetchType.EAGER)
>>>  @JoinTable(name = "PARENT_CHILD", joinColumns = { @JoinColumn(name =
>>> "PARENT_ID") }, inverseJoinColumns = { @JoinColumn(name = "CHILD_ID") })
>>>  public Set<Child> getValues() {
>>>   return values;
>>>  }
>>>  public void setValues(Set<Child> lst) {
>>>   values = lst;
>>>  }
>>> }
>>>
>>> @Entity
>>> @Table(name="CHILD")
>>> public class Child {
>>>  private Long id;
>>>  private String name;
>>>  @Id
>>>  @GeneratedValue
>>>  @Column(name="CHILD_ID")
>>>  public Long getId() {
>>>   return id;
>>>  }
>>>  public void setId(Long id) {
>>>   this.id = id;
>>>  }
>>>  @Column(name="NAME")
>>>  public String getName() {
>>>   return name;
>>>  }
>>>  public void setName(String val) {
>>>   name = val;
>>>  }
>>> }
>>>
>>> public interface ParentDAO {
>>>  public void saveOrUpdateParent(Parent cl);
>>>  public void saveParent(Parent cl);
>>>  public List<Parent> listParent();
>>>  public Parent listParentById(Long clId);
>>>  public void deleteParent(Long clId);
>>> }
>>>
>>> public class ParentDAOImpl implements ParentDAO {
>>>  @SessionTarget
>>>  Session session;
>>>  @TransactionTarget
>>>  Transaction transaction;
>>>
>>>  @Override
>>>  public void saveOrUpdateParent(Parent cl) {
>>>   try {
>>>    session.saveOrUpdate(cl);
>>>   } catch (Exception e) {
>>>    transaction.rollback();
>>>    e.printStackTrace();
>>>   }
>>>  }
>>>
>>>  @Override
>>>  public void saveParent(Parent cl) {
>>>   try {
>>>    session.save(cl);
>>>   } catch (Exception e) {
>>>    transaction.rollback();
>>>    e.printStackTrace();
>>>   }
>>>  }
>>>
>>>  @Override
>>>  public void deleteParent(Long clId) {
>>>   try {
>>>    Parent cl = (Parent) session.get(Parent.class, clId);
>>>    session.delete(cl);
>>>   } catch (Exception e) {
>>>    transaction.rollback();
>>>    e.printStackTrace();
>>>   }
>>>  }
>>>
>>>  @SuppressWarnings("unchecked")
>>>  @Override
>>>  public List<Parent> listParent() {
>>>   List<Parent> courses = null;
>>>   try {
>>>    courses = session.createQuery("from Parent").list();
>>>    } catch (Exception e) {
>>>    e.printStackTrace();
>>>   }
>>>   return courses;
>>>  }
>>>
>>>  @Override
>>>  public Parent listParentById(Long clId) {
>>>   Parent cl = null;
>>>   try {
>>>    cl = (Parent) session.get(Parent.class, clId);
>>>   } catch (Exception e) {
>>>    e.printStackTrace();
>>>   }
>>>   return cl;
>>>  }
>>> }
>>>
>>> public class ParentAction  extends ActionSupport implements
>>> ModelDriven<Parent> {
>>>
>>>  private static final long serialVersionUID = -2662966220408285700L;
>>>  private Parent cl = new Parent();
>>>  private List<Parent> clList = new ArrayList<Parent>();
>>>  private ParentDAO clDAO = new ParentDAOImpl();
>>>
>>>  @Override
>>>  public Parent getModel() {
>>>   return cl;
>>>  }
>>>
>>>  public String saveOrUpdate()
>>>  {
>>>   clDAO.saveOrUpdateParent(cl);
>>>   return SUCCESS;
>>>  }
>>>
>>>  public String save()
>>>  {
>>>   clDAO.saveParent(cl);
>>>   return SUCCESS;
>>>  }
>>>
>>>  public String list()
>>>  {
>>>   clList = clDAO.listParent();
>>>   return SUCCESS;
>>>  }
>>>
>>>  public String delete()
>>>  {
>>>   HttpServletRequest request = (HttpServletRequest)
>>> ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
>>>   clDAO.deleteParent(Long.parseLong(request.getParameter("id")));
>>>   return SUCCESS;
>>>  }
>>>
>>>  public String edit()
>>>  {
>>>   HttpServletRequest request = (HttpServletRequest)
>>> ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
>>>   cl = clDAO.listParentById(Long.parseLong(request.getParameter("id")));
>>>   return SUCCESS;
>>>  }
>>>
>>>  public Parent getParent() {
>>>   return cl;
>>>  }
>>>
>>>  public void setParent(Parent cl) {
>>>   this.cl = cl;
>>>  }
>>>
>>>  public List<Parent> getParentList() {
>>>   return clList;
>>>  }
>>>
>>>  public void setParentList(List<Parent> clList) {
>>>   this.clList = clList;
>>>  }
>>> }
>>>
>>> and finally the jsp page:
>>>
>>> <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
>>>  pageEncoding="ISO-8859-1"%>
>>> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
>>> "http://www.w3.org/TR/html4/loose.dtd">
>>> <%@taglib uri="/struts-tags" prefix="s"%>
>>> <html>
>>> <head>
>>> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
>>> <title>Parent Registration Page</title>
>>> <s:head />
>>> <style type="text/css">
>>> @import url(style.css);
>>> </style>
>>> </head>
>>> <body>
>>> <s:form action="saveOrUpdateParent">
>>>  <s:push value="parent">
>>>   <s:hidden name="id" />
>>>    <s:push value="values">
>>>    <s:iterator id="p" value="values">
>>>    <s:textfield label="Nom" name="values(%{id}).name" value="%{name}"/>
>>>         </s:iterator>
>>>   </s:push>
>>>     <s:submit />
>>>  </s:push>
>>> </s:form>
>>>
>>> <s:if test="parentList.size() > 0">
>>>  <div class="content">
>>>  <table class="userTable" cellpadding="5px">
>>>   <tr class="even">
>>>    <th>Child(s)</th>
>>>   </tr>
>>>   <s:iterator value="parentList" status="userStatus">
>>>    <tr
>>>     class="<s:if test="#userStatus.odd == true
>>> ">odd</s:if><s:else>even</s:else>">
>>>     <td><s:property value="values.size()" /></td>
>>>     <s:iterator value="values">
>>>      <td><s:property value="name" /></td>
>>>     </s:iterator>
>>>     <td><s:url id="editURL" action="editParent">
>>>      <s:param name="id" value="%{id}"></s:param>
>>>     </s:url> <s:a href="%{editURL}">Edit</s:a></td>
>>>     <td><s:url id="deleteURL" action="deleteParent">
>>>      <s:param name="id" value="%{id}"></s:param>
>>>     </s:url> <s:a href="%{deleteURL}">Delete</s:a></td>
>>>    </tr>
>>>   </s:iterator>
>>>  </table>
>>>  </div>
>>> </s:if>
>>> </body>
>>> </html>
>>>
>>
>> -- 
>> René Gielen
>> IT-Neering.net
>> Saarstrasse 100, 52062 Aachen, Germany
>> Tel: +49-(0)241-4010770
>> Fax: +49-(0)241-4010771
>> Cel: +49-(0)163-2844164
>> http://twitter.com/rgielen
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 

-- 
René Gielen
IT-Neering.net
Saarstrasse 100, 52062 Aachen, Germany
Tel: +49-(0)241-4010770
Fax: +49-(0)241-4010771
Cel: +49-(0)163-2844164
http://twitter.com/rgielen

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: CRUD with a OneToMany association under Struts 2 / Hibernate 3

Posted by bruno grandjean <br...@live.fr>.
Dear Rene,

Thks a lot for replying to me because I am feeling a little bit alone with
my CRUD ;-). In fact I am trying to build a dynamic MetaCrud.
My pb is simple: in the same jsp page I would like to update a Parent object
and its Childs (values):

<s:form action="saveOrUpdateParent">
<s:push value="parent">
<s:hidden name="id" /> <s:textfield
name="name" label="Nom" />
<s:push value="values">
  <s:iterator id="p" value="values">
    <s:textfield label="Nom" name="#name" value="%{name}"/>
                                </s:iterator>
</s:push>
<s:submit />
</s:push>
</s:form>

>From an existing Parent object with many Childs objects I can easily modify
parent.name for instance but the collection of Child objects (values) is
always empty in the ParentAction (saveOrUpdate() method) after submitting.
However I can display each values[i].name in the jsp page with the correct
value.
So it is not an issue with Hibernate but with the jsp or ModelDriven
interface I don't know..Do you have any idea?
Basically I was not able to find a struts or spring documentation about CRUD
& association between two entities on the same jsp page.
best regards
bruno



--------------------------------------------------
From: "Rene Gielen" <gi...@it-neering.net>
Sent: Wednesday, March 31, 2010 7:12 PM
To: "Struts Users Mailing List" <us...@struts.apache.org>
Subject: Re: CRUD with a OneToMany association under Struts 2 / Hibernate 3

> I'm not sure if I understand what your actual question is, nor whether
> it is particularly Struts 2 related (rather than just Hibernate) - but
> you might want to have a look in the CRUD demo section of the Struts 2
> showcase application. Maybe you will also find this demo useful:
> http://github.com/rgielen/struts2crudevolutiondemo
>
> - René
>
> bruno grandjean schrieb:
>> Hi
>>
>> I am trying to implement a simple CRUD with a OneToMany association under 
>> Struts 2 / Hibernate 3.
>> I have two entities Parent and Child:
>>
>> @Entity
>> @Table(name="PARENT")
>> public class Parent {
>>  private Long id;
>>  private Set<Child> values = new HashSet<Child>();
>> ..
>> @Entity
>> @Table(name="CHILD")
>> public class Child {
>>  private Long id;
>>  private String name;
>> ..
>>
>> I can easily create, delete Parent or read the Child Set (values) but it 
>> is impossible to update Child Set.
>> The jsp page (see below) reinit the values Set, no record after updating!
>> Could u explain to me what's wrong?
>>
>> here are my code:
>>
>> @Entity
>> @Table(name="PARENT")
>> public class Parent {
>>  private Long id;
>>  private Set<Child> values = new HashSet<Child>();
>>  @Id
>>  @GeneratedValue
>>  @Column(name="PARENT_ID")
>>  public Long getId() {
>>   return id;
>>  }
>>  public void setId(Long id) {
>>   this.id = id;
>>  }
>>  @ManyToMany(fetch = FetchType.EAGER)
>>  @JoinTable(name = "PARENT_CHILD", joinColumns = { @JoinColumn(name = 
>> "PARENT_ID") }, inverseJoinColumns = { @JoinColumn(name = "CHILD_ID") })
>>  public Set<Child> getValues() {
>>   return values;
>>  }
>>  public void setValues(Set<Child> lst) {
>>   values = lst;
>>  }
>> }
>>
>> @Entity
>> @Table(name="CHILD")
>> public class Child {
>>  private Long id;
>>  private String name;
>>  @Id
>>  @GeneratedValue
>>  @Column(name="CHILD_ID")
>>  public Long getId() {
>>   return id;
>>  }
>>  public void setId(Long id) {
>>   this.id = id;
>>  }
>>  @Column(name="NAME")
>>  public String getName() {
>>   return name;
>>  }
>>  public void setName(String val) {
>>   name = val;
>>  }
>> }
>>
>> public interface ParentDAO {
>>  public void saveOrUpdateParent(Parent cl);
>>  public void saveParent(Parent cl);
>>  public List<Parent> listParent();
>>  public Parent listParentById(Long clId);
>>  public void deleteParent(Long clId);
>> }
>>
>> public class ParentDAOImpl implements ParentDAO {
>>  @SessionTarget
>>  Session session;
>>  @TransactionTarget
>>  Transaction transaction;
>>
>>  @Override
>>  public void saveOrUpdateParent(Parent cl) {
>>   try {
>>    session.saveOrUpdate(cl);
>>   } catch (Exception e) {
>>    transaction.rollback();
>>    e.printStackTrace();
>>   }
>>  }
>>
>>  @Override
>>  public void saveParent(Parent cl) {
>>   try {
>>    session.save(cl);
>>   } catch (Exception e) {
>>    transaction.rollback();
>>    e.printStackTrace();
>>   }
>>  }
>>
>>  @Override
>>  public void deleteParent(Long clId) {
>>   try {
>>    Parent cl = (Parent) session.get(Parent.class, clId);
>>    session.delete(cl);
>>   } catch (Exception e) {
>>    transaction.rollback();
>>    e.printStackTrace();
>>   }
>>  }
>>
>>  @SuppressWarnings("unchecked")
>>  @Override
>>  public List<Parent> listParent() {
>>   List<Parent> courses = null;
>>   try {
>>    courses = session.createQuery("from Parent").list();
>>    } catch (Exception e) {
>>    e.printStackTrace();
>>   }
>>   return courses;
>>  }
>>
>>  @Override
>>  public Parent listParentById(Long clId) {
>>   Parent cl = null;
>>   try {
>>    cl = (Parent) session.get(Parent.class, clId);
>>   } catch (Exception e) {
>>    e.printStackTrace();
>>   }
>>   return cl;
>>  }
>> }
>>
>> public class ParentAction  extends ActionSupport implements 
>> ModelDriven<Parent> {
>>
>>  private static final long serialVersionUID = -2662966220408285700L;
>>  private Parent cl = new Parent();
>>  private List<Parent> clList = new ArrayList<Parent>();
>>  private ParentDAO clDAO = new ParentDAOImpl();
>>
>>  @Override
>>  public Parent getModel() {
>>   return cl;
>>  }
>>
>>  public String saveOrUpdate()
>>  {
>>   clDAO.saveOrUpdateParent(cl);
>>   return SUCCESS;
>>  }
>>
>>  public String save()
>>  {
>>   clDAO.saveParent(cl);
>>   return SUCCESS;
>>  }
>>
>>  public String list()
>>  {
>>   clList = clDAO.listParent();
>>   return SUCCESS;
>>  }
>>
>>  public String delete()
>>  {
>>   HttpServletRequest request = (HttpServletRequest) 
>> ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
>>   clDAO.deleteParent(Long.parseLong(request.getParameter("id")));
>>   return SUCCESS;
>>  }
>>
>>  public String edit()
>>  {
>>   HttpServletRequest request = (HttpServletRequest) 
>> ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
>>   cl = clDAO.listParentById(Long.parseLong(request.getParameter("id")));
>>   return SUCCESS;
>>  }
>>
>>  public Parent getParent() {
>>   return cl;
>>  }
>>
>>  public void setParent(Parent cl) {
>>   this.cl = cl;
>>  }
>>
>>  public List<Parent> getParentList() {
>>   return clList;
>>  }
>>
>>  public void setParentList(List<Parent> clList) {
>>   this.clList = clList;
>>  }
>> }
>>
>> and finally the jsp page:
>>
>> <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
>>  pageEncoding="ISO-8859-1"%>
>> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
>> "http://www.w3.org/TR/html4/loose.dtd">
>> <%@taglib uri="/struts-tags" prefix="s"%>
>> <html>
>> <head>
>> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
>> <title>Parent Registration Page</title>
>> <s:head />
>> <style type="text/css">
>> @import url(style.css);
>> </style>
>> </head>
>> <body>
>> <s:form action="saveOrUpdateParent">
>>  <s:push value="parent">
>>   <s:hidden name="id" />
>>    <s:push value="values">
>>    <s:iterator id="p" value="values">
>>    <s:textfield label="Nom" name="values(%{id}).name" value="%{name}"/>
>>         </s:iterator>
>>   </s:push>
>>     <s:submit />
>>  </s:push>
>> </s:form>
>>
>> <s:if test="parentList.size() > 0">
>>  <div class="content">
>>  <table class="userTable" cellpadding="5px">
>>   <tr class="even">
>>    <th>Child(s)</th>
>>   </tr>
>>   <s:iterator value="parentList" status="userStatus">
>>    <tr
>>     class="<s:if test="#userStatus.odd == true 
>> ">odd</s:if><s:else>even</s:else>">
>>     <td><s:property value="values.size()" /></td>
>>     <s:iterator value="values">
>>      <td><s:property value="name" /></td>
>>     </s:iterator>
>>     <td><s:url id="editURL" action="editParent">
>>      <s:param name="id" value="%{id}"></s:param>
>>     </s:url> <s:a href="%{editURL}">Edit</s:a></td>
>>     <td><s:url id="deleteURL" action="deleteParent">
>>      <s:param name="id" value="%{id}"></s:param>
>>     </s:url> <s:a href="%{deleteURL}">Delete</s:a></td>
>>    </tr>
>>   </s:iterator>
>>  </table>
>>  </div>
>> </s:if>
>> </body>
>> </html>
>>
>
> -- 
> René Gielen
> IT-Neering.net
> Saarstrasse 100, 52062 Aachen, Germany
> Tel: +49-(0)241-4010770
> Fax: +49-(0)241-4010771
> Cel: +49-(0)163-2844164
> http://twitter.com/rgielen
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: CRUD with a OneToMany association under Struts 2 / Hibernate 3

Posted by Rene Gielen <gi...@it-neering.net>.
I'm not sure if I understand what your actual question is, nor whether
it is particularly Struts 2 related (rather than just Hibernate) - but
you might want to have a look in the CRUD demo section of the Struts 2
showcase application. Maybe you will also find this demo useful:
http://github.com/rgielen/struts2crudevolutiondemo

- René

bruno grandjean schrieb:
> Hi
> 
> I am trying to implement a simple CRUD with a OneToMany association under Struts 2 / Hibernate 3.
> I have two entities Parent and Child:
> 
> @Entity
> @Table(name="PARENT")
> public class Parent {
>  private Long id;
>  private Set<Child> values = new HashSet<Child>();  
> ..
> @Entity
> @Table(name="CHILD")
> public class Child {
>  private Long id; 
>  private String name; 
> ..
> 
> I can easily create, delete Parent or read the Child Set (values) but it is impossible to update Child Set.
> The jsp page (see below) reinit the values Set, no record after updating!
> Could u explain to me what's wrong?
> 
> here are my code:
> 
> @Entity
> @Table(name="PARENT")
> public class Parent {
>  private Long id;
>  private Set<Child> values = new HashSet<Child>();  
>  @Id
>  @GeneratedValue
>  @Column(name="PARENT_ID") 
>  public Long getId() {
>   return id;
>  }
>  public void setId(Long id) {
>   this.id = id;
>  }
>  @ManyToMany(fetch = FetchType.EAGER)    
>  @JoinTable(name = "PARENT_CHILD", joinColumns = { @JoinColumn(name = "PARENT_ID") }, inverseJoinColumns = { @JoinColumn(name = "CHILD_ID") })  
>  public Set<Child> getValues() {  
>   return values;
>  }
>  public void setValues(Set<Child> lst) {
>   values = lst;  
>  }
> }
> 
> @Entity
> @Table(name="CHILD")
> public class Child {
>  private Long id; 
>  private String name; 
>  @Id
>  @GeneratedValue
>  @Column(name="CHILD_ID") 
>  public Long getId() {
>   return id;
>  }
>  public void setId(Long id) {
>   this.id = id;
>  }
>  @Column(name="NAME")
>  public String getName() {  
>   return name;
>  }
>  public void setName(String val) {
>   name = val;
>  } 
> }
> 
> public interface ParentDAO {
>  public void saveOrUpdateParent(Parent cl);
>  public void saveParent(Parent cl);
>  public List<Parent> listParent();
>  public Parent listParentById(Long clId);
>  public void deleteParent(Long clId);
> }
> 
> public class ParentDAOImpl implements ParentDAO {
>  @SessionTarget
>  Session session;
>  @TransactionTarget
>  Transaction transaction;
> 
>  @Override
>  public void saveOrUpdateParent(Parent cl) {  
>   try {
>    session.saveOrUpdate(cl);
>   } catch (Exception e) {
>    transaction.rollback(); 
>    e.printStackTrace();
>   }
>  }
> 
>  @Override
>  public void saveParent(Parent cl) {
>   try {
>    session.save(cl);
>   } catch (Exception e) {
>    transaction.rollback();
>    e.printStackTrace();
>   }
>  }
>  
>  @Override
>  public void deleteParent(Long clId) {
>   try {
>    Parent cl = (Parent) session.get(Parent.class, clId);
>    session.delete(cl);
>   } catch (Exception e) {
>    transaction.rollback();
>    e.printStackTrace();
>   } 
>  }
>  
>  @SuppressWarnings("unchecked")
>  @Override
>  public List<Parent> listParent() {
>   List<Parent> courses = null;
>   try {
>    courses = session.createQuery("from Parent").list();
>    } catch (Exception e) {
>    e.printStackTrace();
>   }
>   return courses;
>  }
> 
>  @Override
>  public Parent listParentById(Long clId) {
>   Parent cl = null;
>   try {
>    cl = (Parent) session.get(Parent.class, clId);
>   } catch (Exception e) {
>    e.printStackTrace();
>   }
>   return cl;
>  }
> }
> 
> public class ParentAction  extends ActionSupport implements ModelDriven<Parent> {
> 
>  private static final long serialVersionUID = -2662966220408285700L;
>  private Parent cl = new Parent();
>  private List<Parent> clList = new ArrayList<Parent>(); 
>  private ParentDAO clDAO = new ParentDAOImpl();
>  
>  @Override
>  public Parent getModel() {
>   return cl;
>  }
>  
>  public String saveOrUpdate()
>  {
>   clDAO.saveOrUpdateParent(cl);  
>   return SUCCESS;
>  }
> 
>  public String save()
>  {  
>   clDAO.saveParent(cl);  
>   return SUCCESS;
>  }
> 
>  public String list()
>  {
>   clList = clDAO.listParent();
>   return SUCCESS;
>  }
>  
>  public String delete()
>  {
>   HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
>   clDAO.deleteParent(Long.parseLong(request.getParameter("id")));
>   return SUCCESS;
>  }
> 
>  public String edit()
>  {
>   HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
>   cl = clDAO.listParentById(Long.parseLong(request.getParameter("id")));
>   return SUCCESS;
>  }
>  
>  public Parent getParent() {
>   return cl;
>  }
> 
>  public void setParent(Parent cl) {
>   this.cl = cl;
>  }
> 
>  public List<Parent> getParentList() {
>   return clList;
>  }
> 
>  public void setParentList(List<Parent> clList) {
>   this.clList = clList;
>  }
> }
> 
> and finally the jsp page:
> 
> <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
>  pageEncoding="ISO-8859-1"%>
> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
> <%@taglib uri="/struts-tags" prefix="s"%>
> <html>
> <head>
> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
> <title>Parent Registration Page</title>
> <s:head />
> <style type="text/css">
> @import url(style.css);
> </style>
> </head>
> <body>
> <s:form action="saveOrUpdateParent">
>  <s:push value="parent">
>   <s:hidden name="id" />  
>    <s:push value="values">
>    <s:iterator id="p" value="values">
>    <s:textfield label="Nom" name="values(%{id}).name" value="%{name}"/>
>         </s:iterator>
>   </s:push>
>     <s:submit />
>  </s:push>
> </s:form>
> 
> <s:if test="parentList.size() > 0">
>  <div class="content">
>  <table class="userTable" cellpadding="5px">
>   <tr class="even">
>    <th>Child(s)</th>
>   </tr>
>   <s:iterator value="parentList" status="userStatus">
>    <tr
>     class="<s:if test="#userStatus.odd == true ">odd</s:if><s:else>even</s:else>">
>     <td><s:property value="values.size()" /></td>
>     <s:iterator value="values">
>      <td><s:property value="name" /></td>
>     </s:iterator>
>     <td><s:url id="editURL" action="editParent">
>      <s:param name="id" value="%{id}"></s:param>
>     </s:url> <s:a href="%{editURL}">Edit</s:a></td>
>     <td><s:url id="deleteURL" action="deleteParent">
>      <s:param name="id" value="%{id}"></s:param>
>     </s:url> <s:a href="%{deleteURL}">Delete</s:a></td>
>    </tr>
>   </s:iterator>
>  </table>
>  </div>
> </s:if>
> </body>
> </html>
> 

-- 
René Gielen
IT-Neering.net
Saarstrasse 100, 52062 Aachen, Germany
Tel: +49-(0)241-4010770
Fax: +49-(0)241-4010771
Cel: +49-(0)163-2844164
http://twitter.com/rgielen

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org