Posts

Showing posts with the label Hibernate

Hibernate Exceptions Errors and Causes

The following section will list the general exception that we get while dealing with hibernate. org.hibernate.ObjectDeletedException:deleted object would be re-saved by cascade when we try to delete the child object and don't remove the association, for instance we loaded a parent object with list of child and then we deleted one of the child object but did not removed the child from the parent. Example, Box gotBox =(Box)dao.load(Box.class, box.getBoxId()); List boxitem = new ArrayList(gotBox.getBoxItems()); BoxItem deleteItem = boxitem.get(0); dao.deletItem(deleteItem.getItemName()); Solution is, remove the transient instance from the parent object(Box) like.   gotBox.getBoxItems().remove(deleteItem); OR use   @Cascade(value=org.hibernate.annotations.CascadeType.DELETE_ORPHAN) on the child object. ------------------------------------------------------------------------------------------------- No Dialect mapping for JDBC type: -1 We get th...

Effect of Select Strategies in Hibernate How and When

STUDY : Hibernate Common Issues and Tips Effect of Select Strategies in Hibernate (How and When) Hibernate is one of the most popular ORM tools. In my own experience I have found that in the application development life cycle we often get some common hibernate related issues, be it performance related issues or Exception generated by hibernate. I have tried to capture the exception or problems we get while  using hibernate in the data access layer. The overall finding is divided in to different scene's. In Hibernate 3 when we load a particular object from db, only that object is loaded and the associated objects are not loaded.  For example if we have a relationship like      Director   ---> Movies(many) If we now load the director all the movies will not be retrieved from data base . We can control this behavior like whether to load the related objects(movies in this case) using fetching strategies. By default all the related o...