Results 1 to 2 of 2

Thread: Delete objects in the collections with Hibernate

  1. #1
    Join Date
    Nov 2009
    Posts
    583

    Delete objects in the collections with Hibernate

    Introduction :
    Hibernate is a framework for managing the persistence famous and widely known that allows a lot of things and with which one can tear a lot of hair. Hibernate to the "unfortunate" tendency to use collection types that are specific to managing any respect list, set etc.. The attributes of type list and set are replaced by objects of type PersistentList and PersistentSet. This allows for example to dynamically load the hibernate collection when called as a method size () add () or remove () for example a collection mapped with lazy loading. To summarize, as we did not need the contents of the list, it is replaced by a proxy who is willing to load the first request.


    What happens :
    When using Hibernate in the context of an application with a client-server, Hibernate classes that are accessible only at the server side, database. But in a client-server architecture is made pass business objects java from either side via the network (eg using Spring HTTP remoteing), but under one condition: That all items sent be available in two projects dependencies. But as I explained just before, Hibernate replaces the lists of objects that are clean and which are accessible via the server project at Bookstore hibernate (hibernate3.jar eg lib directory of the server). So if we send the client a business cluster containing lists after extraction from the database using hibernate, it will be a problem and we will see it blossom in the console the error message "Exception: I do not know the class PersistentSet"

  2. #2
    Join Date
    Nov 2009
    Posts
    583

    Re: Delete objects in the collections with Hibernate

    Description :
    Perhaps that is not impacted by this problem because it is customary to use DTOs serve and processors to route the items on the network and therefore the specific types of hibernate are processed automatically (by processors) . In case we have no layer of DTOs serve, can be used to replace the mappers and PersistentList PersistentSet in ArrayList and HashpSet example. In short, once the objects recovered processed (without PersistentXXX) on the client, we play with, or modifies and it may be necessary to remove items from a list. And that's where the plot thickens as it may, no one really knows why, that Hibernate can not detect the deletion of an element when saving. Indeed, since we replace the list manager to hibernate when the sauce returns the cluster server side, it does not realize that there has been striking even with options such delete-orphan all-delete-orphan in the mapping. The only solution remaining is the last chance to map the list of a very different way.


    A common problem :
    An object Removed year from a collection mapped with cascade = "all" the goal object Was Not deleted. cascade = 'all' the cascade delete () operation from parent to child. If This Is a one-to-many association, try using cascade = "all, delete-orphan". Another Solution Is To model your child objects as composite elements (a kind of value type) Rather Than entities. Value types are gold Always PERSISTED Removed Along with Their parent entity. So you would use a Mapping for the element of a class INSTEAD mapping.


    any example :
    Here is the mapping of the content in item list :
    Code:
    set name="lst" table="element" lazy="true">
    <key column="cl" not-null="true" />
    <composite-element class="address here">
    <parent name="tr"/>
    
    <property name="iden" type="java.lang.Integer">
    <column name="clid" />
    </ Property>
    
    <property name="comment" type="java.lang.String">
    <column name="clcomment" length="254" />
    </ Property>
    
    <property name="date" type="timestamp">
    <column name="cldate" />
    </ Property>
    
    </ Composite-element>
    </ Set>

    Instead if it is written in this way :

    Code:
    <list name="lst" lazy="true" cascade="persist, save-update, evict, merge, all-delete-orphan">
    <key column="clid" not-null="true" />
    <Voice column="clnm" />
    <one-to-many class="Element" />
    </ List>

    Good disadvantages are obvious, it is necessary to map the list in the file mapping object and container in case the objects of the list are used in multiple objects are duplicated not very professional as they say, so better to avoid. But hey it works and objects are things within days and especially when you save the deleted object container.

Similar Threads

  1. Collections available in FrontierVille
    By Meditation in forum Video Games
    Replies: 4
    Last Post: 07-02-2011, 10:16 AM
  2. Hibernate delete query using criterion
    By NinjaZxR in forum Software Development
    Replies: 4
    Last Post: 23-06-2010, 04:06 PM
  3. Delete some objects in SortedSet
    By Miles Runner in forum Software Development
    Replies: 5
    Last Post: 03-03-2010, 09:36 AM
  4. Collections in c#
    By Jagdish Gada in forum Software Development
    Replies: 5
    Last Post: 20-01-2010, 10:12 AM
  5. OU delegation, permission to move but not delete objects
    By Nickason in forum Active Directory
    Replies: 2
    Last Post: 23-09-2008, 03:26 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,710,828,163.72248 seconds with 16 queries