Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to update the collection of @onetomany relationship
    primarykey
    data
    text
    <p>I have the following code:</p> <pre><code>public class Parent{ @OneToMany(mappedBy="parent", targetEntity= Child.class, fetch = FetchType.LAZY, cascade= CascadeType.ALL, orphanRemoval=true) List&lt;Child&gt; children; } public class Child{ @ManyToOne( targetEntity=Cotizacion.class, optional=false, fetch=FetchType.LAZY ) @JoinColumn( name = "ID_PARENT", nullable = false ) private Parent parent; } </code></pre> <p>Now in the client side i'm using GWT editor framework to edit the whole parent object, i mean.</p> <pre><code>Editor&lt;ParentProxy&gt; ListEditor&lt;List&lt;ChildProxy&gt;&gt; </code></pre> <p>I have the requirement to edit the whole object on the same editor, so if i update a Child from the Parent and then flush() the driver the changes are propagated correctly.</p> <p>The problem. On the server side i get the Parent with the children collection as persistedbag as null. (the Locator find() method is called for every Children). So if i do a change in the client side that is not propagated to the server side into the data base.</p> <p>Note 1.- I check the whole object on the client side and the changes were made by the editor driver.</p> <p>Note 2.- I tryed to retreive the whole object on the find() method of the Locator and doesn't work.</p> <p>Note 3.- If i send the list as other parameter in my RequestContext and then update every child on the server side (DAO) it updates them correctly.</p> <p><strong>UPDATE:</strong> if i add a null to the children i get the whole list on server side instead of the persistedbag and the the update on the Child ocurrs.</p> <p>Ex. parent.getChilds().add(null);</p> <p>How RequestFactory makes the delta changes on the entities?</p> <p>Any help would be apreciated.</p> <p><strong>UPDATE 2:</strong>solution of thomas.</p> <p>The classes (listeners):</p> <pre><code> public class HibernateUtil implements ServletContextListener {} public class AppSessionManager implements Filter {} </code></pre> <p>The line that hibernate needs:</p> <pre><code> &lt;property name="current_session_context_class"&gt;thread&lt;/property&gt; </code></pre> <p>The web.xml config:</p> <pre><code> &lt;!-- Servlet context listerner --&gt; &lt;listener&gt; &lt;listener-class&gt;xxx.yyy.server.tools.HibernateUtil&lt;/listener-class&gt; &lt;/listener&gt; &lt;!-- Servlet for filter --&gt; &lt;filter&gt; &lt;filter-name&gt;HibernateFilter&lt;/filter-name&gt; &lt;filter-class&gt;xxx.yyy.server.tools.AppSessionManager&lt;/filter-class&gt; &lt;/filter&gt; &lt;filter-mapping&gt; &lt;filter-name&gt;HibernateFilter&lt;/filter-name&gt; &lt;url-pattern&gt;/gwtRequest&lt;/url-pattern&gt; &lt;/filter-mapping&gt; </code></pre> <p>the entity locator:</p> <pre><code>public class BaseEntityLocator extends Locator&lt;BaseEntity, Integer&gt; { /* * Method to fetch an object and merge the updates * * @see com.google.web.bindery.requestfactory.shared.Locator#find(java.lang.Class, java.lang.Object) */ @Override public BaseEntity find(Class&lt;? extends BaseEntity&gt; clazz, Integer id) { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); try { BaseEntity baseEntity = (BaseEntity) session.get(clazz, id); return baseEntity; } catch (RuntimeException e) { throw e; } } ... } </code></pre> <p>Result? no more LazyInitializationException and other problems updating relations of type one to many. Hope this helps some one else.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload