Re: Struts2-json-plugin serialization issue with a Hibernate backed JPA entity
I need the root object to be "list" so this isn't going to help. I'm pretty sure it is not trying to serialize the EJB service, the json plugin will only try to serialize properties which have getters. According the debugger there seems to be a public property directly in the entity called $JAVASSIST_READ_WRITE_HANDLER, I'm quite confident that is in the attempt to serialize this object the issue occurs. To be extra sure I set list as the root and the issue still occurs. On Wed, 2011-09-07 at 07:59 +0200, Maurizio Cucchiara wrote: > You might take a look at [1], particoularly the section called "root > object". > That's because I'm afraid that json plugin is trying to serialize your EJB > service. > HTH > > [1] struts.apache.org/2.2.3/docs/json-plugin.html > > Maurizio Cucchiara > > Il giorno 07/set/2011 07.43, "Ken McWilliams" ha > scritto: > > I have a JPA entity, which hibernate is proxying. > > > > The following action works as it explicitly states the properties to > > include, however what I would much rather do is use excludeProperties to > > remove the problematic property. The problem property when serialized > > causes a "Positioned Update not supported" exception. > > > > The interesting thing is, all the properties on the entity class are > > persisted correctly if explicitly included. > > > > Looking in the the debugger shows there is a property called > > "$JAVASSIST_READ_WRITE_HANDLER" of type FieldInterceptorImpl which > > Hibernate/JPA adds to the entity. I'm pretty sure this is what is > > causing it to fail. > > > > > > I've tried the following: > > @Action(value = "list-clients", results = { > > @Result(type = "json", params = { > > "excludeProperties", > > "list\\[.*\\]\\.\\$JAVASSIST_READ_WRITE_HANDLER.*" > > }) > > }) > > > > but with no luck. Following is my action and the entity class. > > > > > > > > Here is my action (In a _working_ state): > > / > > @ParentPackage("json-default") > > @Result(type = "json") > > public class ListTable extends ActionSupport { > > > > @EJB > > private ClientService clientService; > > private List list; > > > > @Action(value = "list-clients", results = { > > @Result(type = "json", params = { > > "includeProperties", > > "list\\[.*\\]\\.name, list\\[.*\\]\\.id, list\\[.*\\]\ > > \.timelogCollection\\..*" > > }) > > }) > > public String listClients() { > > list = clientService.list(); > > return SUCCESS; > > } > > > > public List getList() { > > return list; > > } > > } > > / > > > > Here is the entity: > > / > > @Entity > > @Table(name = "client") > > @XmlRootElement > > @NamedQueries({ > > @NamedQuery(name = "Client.findAll", query = "SELECT c FROM Client > > c"), > > @NamedQuery(name = "Client.findById", query = "SELECT c FROM Client > > c WHERE c.id = :id"), > > @NamedQuery(name = "Client.findByName", query = "SELECT c FROM > > Client c WHERE c.name = :name")}) > > public class Client implements Serializable { > > private static final long serialVersionUID = 1L; > > @Id > > @GeneratedValue(strategy = GenerationType.IDENTITY) > > @Basic(optional = false) > > @NotNull > > @Column(name = "id") > > private Integer id; > > @Size(max = 45) > > @Column(name = "name") > > private String name; > > @OneToMany(cascade = CascadeType.ALL, mappedBy = "clientId") > > private Collection timelogCollection; > > > > public Client() { > > } > > > > public Client(Integer id) { > > this.id = id; > > } > > > > public Integer getId() { > > return id; > > } > > > > public void setId(Integer id) { > > this.id = id; > > } > > > > public String getName() { > > return name; > > } > > > > public void setName(String name) { > > this.name = name; > > } > > > > @XmlTransient > > public Collection getTimelogCollection() { > > return timelogCollection; > > } > > > > public void setTimelogCollection(Collection > > timelogCollection) { > > this.timelogCollection = timelogCollection; > > } > > > > @Override > > public int hashCode() { > > int hash = 0; > > hash += (id != null ? id.hashCode() : 0); > > return hash; > > } > > > > @Override > > public boolean equals(Object object) { > > // TODO: Warning - this method won't work in the case the id > > fields are not set > > if (!(object instanceof Client)) { > > return false; > > } > > Client other = (Client) object; > > if ((this.id == null && other.id != null) || (this.id != null > > && !this.id.equals(other.id))) { > > return false; > > } > > return true; > > } > > > > @Override > > public String toString() { > > return "com.aerose.kentimekeeper.db.Client[ id=" + id + " ]"; > > } > > > > } > > / > > > > > > - > > To unsubscribe, e-mail: user-unsubscr...@struts.apache.org > > For additional commands, e-mail: user-h...@struts.apache.org > > - To unsubscribe, e-mail: user-unsubscr..
Re: Struts2-json-plugin serialization issue with a Hibernate backed JPA entity
Solved! I've seen a number of posts relating to this issue but none with solutions... In searching for how $JAVASSIST_READ_WRITE_HANDLER came into existence we find: http://www.docjar.com/html/api/org/hibernate/tool/instrument/javassist/FieldTransformer.java.html There we can see the getter for "$JAVASSIST_READ_WRITE_HANDLER" is actually "getFieldHandler" so the exclude parameter becomes: @Action(value = "list-clients", results = { @Result(type = "json", params = { "excludeProperties", "^list\\[.*\\]\\.fieldHandler\\..*" }) }) And it all works... Just tested the shorter ".*\\.fieldHandler\\..*" and it works too, which is much better because now there is one solution for all such instrumented entities! On Tue, 2011-09-06 at 22:20 -0600, Ken McWilliams wrote: > I have a JPA entity, which hibernate is proxying. > > The following action works as it explicitly states the properties to > include, however what I would much rather do is use excludeProperties to > remove the problematic property. The problem property when serialized > causes a "Positioned Update not supported" exception. > > The interesting thing is, all the properties on the entity class are > persisted correctly if explicitly included. > > Looking in the the debugger shows there is a property called > "$JAVASSIST_READ_WRITE_HANDLER" of type FieldInterceptorImpl which > Hibernate/JPA adds to the entity. I'm pretty sure this is what is > causing it to fail. > > > I've tried the following: > @Action(value = "list-clients", results = { > @Result(type = "json", params = { > "excludeProperties", > "list\\[.*\\]\\.\\$JAVASSIST_READ_WRITE_HANDLER.*" > }) > }) > > but with no luck. Following is my action and the entity class. > > > > Here is my action (In a _working_ state): > / > @ParentPackage("json-default") > @Result(type = "json") > public class ListTable extends ActionSupport { > > @EJB > private ClientService clientService; > private List list; > > @Action(value = "list-clients", results = { > @Result(type = "json", params = { > "includeProperties", > "list\\[.*\\]\\.name, list\\[.*\\]\\.id, list\\[.*\\]\ > \.timelogCollection\\..*" > }) > }) > public String listClients() { > list = clientService.list(); > return SUCCESS; > } > > public List getList() { > return list; > } > } > / > > Here is the entity: > / > @Entity > @Table(name = "client") > @XmlRootElement > @NamedQueries({ > @NamedQuery(name = "Client.findAll", query = "SELECT c FROM Client > c"), > @NamedQuery(name = "Client.findById", query = "SELECT c FROM Client > c WHERE c.id = :id"), > @NamedQuery(name = "Client.findByName", query = "SELECT c FROM > Client c WHERE c.name = :name")}) > public class Client implements Serializable { > private static final long serialVersionUID = 1L; > @Id > @GeneratedValue(strategy = GenerationType.IDENTITY) > @Basic(optional = false) > @NotNull > @Column(name = "id") > private Integer id; > @Size(max = 45) > @Column(name = "name") > private String name; > @OneToMany(cascade = CascadeType.ALL, mappedBy = "clientId") > private Collection timelogCollection; > > public Client() { > } > > public Client(Integer id) { > this.id = id; > } > > public Integer getId() { > return id; > } > > public void setId(Integer id) { > this.id = id; > } > > public String getName() { > return name; > } > > public void setName(String name) { > this.name = name; > } > > @XmlTransient > public Collection getTimelogCollection() { > return timelogCollection; > } > > public void setTimelogCollection(Collection > timelogCollection) { > this.timelogCollection = timelogCollection; > } > > @Override > public int hashCode() { > int hash = 0; > hash += (id != null ? id.hashCode() : 0); > return hash; > } > > @Override > public boolean equals(Object object) { > // TODO: Warning - this method won't work in the case the id > fields are not set > if (!(object instanceof Client)) { > return false; > } > Client other = (Client) object; > if ((this.id == null && other.id != null) || (this.id != null > && !this.id.equals(other.id))) { > return false; > } > return true; > } > > @Override > public String toString() { > return "com.aerose.kentimekeeper.db.Client[ id=" + id + " ]"; > } > > } > / > > > - > To unsubscribe, e-mail: user-unsubscr...@struts.apache.o
Re: Struts2-json-plugin serialization issue with a Hibernate backed JPA entity
You might take a look at [1], particoularly the section called "root object". That's because I'm afraid that json plugin is trying to serialize your EJB service. HTH [1] struts.apache.org/2.2.3/docs/json-plugin.html Maurizio Cucchiara Il giorno 07/set/2011 07.43, "Ken McWilliams" ha scritto: > I have a JPA entity, which hibernate is proxying. > > The following action works as it explicitly states the properties to > include, however what I would much rather do is use excludeProperties to > remove the problematic property. The problem property when serialized > causes a "Positioned Update not supported" exception. > > The interesting thing is, all the properties on the entity class are > persisted correctly if explicitly included. > > Looking in the the debugger shows there is a property called > "$JAVASSIST_READ_WRITE_HANDLER" of type FieldInterceptorImpl which > Hibernate/JPA adds to the entity. I'm pretty sure this is what is > causing it to fail. > > > I've tried the following: > @Action(value = "list-clients", results = { > @Result(type = "json", params = { > "excludeProperties", > "list\\[.*\\]\\.\\$JAVASSIST_READ_WRITE_HANDLER.*" > }) > }) > > but with no luck. Following is my action and the entity class. > > > > Here is my action (In a _working_ state): > / > @ParentPackage("json-default") > @Result(type = "json") > public class ListTable extends ActionSupport { > > @EJB > private ClientService clientService; > private List list; > > @Action(value = "list-clients", results = { > @Result(type = "json", params = { > "includeProperties", > "list\\[.*\\]\\.name, list\\[.*\\]\\.id, list\\[.*\\]\ > \.timelogCollection\\..*" > }) > }) > public String listClients() { > list = clientService.list(); > return SUCCESS; > } > > public List getList() { > return list; > } > } > / > > Here is the entity: > / > @Entity > @Table(name = "client") > @XmlRootElement > @NamedQueries({ > @NamedQuery(name = "Client.findAll", query = "SELECT c FROM Client > c"), > @NamedQuery(name = "Client.findById", query = "SELECT c FROM Client > c WHERE c.id = :id"), > @NamedQuery(name = "Client.findByName", query = "SELECT c FROM > Client c WHERE c.name = :name")}) > public class Client implements Serializable { > private static final long serialVersionUID = 1L; > @Id > @GeneratedValue(strategy = GenerationType.IDENTITY) > @Basic(optional = false) > @NotNull > @Column(name = "id") > private Integer id; > @Size(max = 45) > @Column(name = "name") > private String name; > @OneToMany(cascade = CascadeType.ALL, mappedBy = "clientId") > private Collection timelogCollection; > > public Client() { > } > > public Client(Integer id) { > this.id = id; > } > > public Integer getId() { > return id; > } > > public void setId(Integer id) { > this.id = id; > } > > public String getName() { > return name; > } > > public void setName(String name) { > this.name = name; > } > > @XmlTransient > public Collection getTimelogCollection() { > return timelogCollection; > } > > public void setTimelogCollection(Collection > timelogCollection) { > this.timelogCollection = timelogCollection; > } > > @Override > public int hashCode() { > int hash = 0; > hash += (id != null ? id.hashCode() : 0); > return hash; > } > > @Override > public boolean equals(Object object) { > // TODO: Warning - this method won't work in the case the id > fields are not set > if (!(object instanceof Client)) { > return false; > } > Client other = (Client) object; > if ((this.id == null && other.id != null) || (this.id != null > && !this.id.equals(other.id))) { > return false; > } > return true; > } > > @Override > public String toString() { > return "com.aerose.kentimekeeper.db.Client[ id=" + id + " ]"; > } > > } > / > > > - > To unsubscribe, e-mail: user-unsubscr...@struts.apache.org > For additional commands, e-mail: user-h...@struts.apache.org >
Struts2-json-plugin serialization issue with a Hibernate backed JPA entity
I have a JPA entity, which hibernate is proxying. The following action works as it explicitly states the properties to include, however what I would much rather do is use excludeProperties to remove the problematic property. The problem property when serialized causes a "Positioned Update not supported" exception. The interesting thing is, all the properties on the entity class are persisted correctly if explicitly included. Looking in the the debugger shows there is a property called "$JAVASSIST_READ_WRITE_HANDLER" of type FieldInterceptorImpl which Hibernate/JPA adds to the entity. I'm pretty sure this is what is causing it to fail. I've tried the following: @Action(value = "list-clients", results = { @Result(type = "json", params = { "excludeProperties", "list\\[.*\\]\\.\\$JAVASSIST_READ_WRITE_HANDLER.*" }) }) but with no luck. Following is my action and the entity class. Here is my action (In a _working_ state): / @ParentPackage("json-default") @Result(type = "json") public class ListTable extends ActionSupport { @EJB private ClientService clientService; private List list; @Action(value = "list-clients", results = { @Result(type = "json", params = { "includeProperties", "list\\[.*\\]\\.name, list\\[.*\\]\\.id, list\\[.*\\]\ \.timelogCollection\\..*" }) }) public String listClients() { list = clientService.list(); return SUCCESS; } public List getList() { return list; } } / Here is the entity: / @Entity @Table(name = "client") @XmlRootElement @NamedQueries({ @NamedQuery(name = "Client.findAll", query = "SELECT c FROM Client c"), @NamedQuery(name = "Client.findById", query = "SELECT c FROM Client c WHERE c.id = :id"), @NamedQuery(name = "Client.findByName", query = "SELECT c FROM Client c WHERE c.name = :name")}) public class Client implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Basic(optional = false) @NotNull @Column(name = "id") private Integer id; @Size(max = 45) @Column(name = "name") private String name; @OneToMany(cascade = CascadeType.ALL, mappedBy = "clientId") private Collection timelogCollection; public Client() { } public Client(Integer id) { this.id = id; } public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } @XmlTransient public Collection getTimelogCollection() { return timelogCollection; } public void setTimelogCollection(Collection timelogCollection) { this.timelogCollection = timelogCollection; } @Override public int hashCode() { int hash = 0; hash += (id != null ? id.hashCode() : 0); return hash; } @Override public boolean equals(Object object) { // TODO: Warning - this method won't work in the case the id fields are not set if (!(object instanceof Client)) { return false; } Client other = (Client) object; if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) { return false; } return true; } @Override public String toString() { return "com.aerose.kentimekeeper.db.Client[ id=" + id + " ]"; } } / - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org