Dear All,
Please find the below links:
MANY-TO-MANY ANNOTATIONS
MANY-TO-MANY XML MAPPING
MANY-TO-MANY ONE MORE EXAMPLE
ONE-TO-MANY BI DIRECTIONAL EXAMPLE
Download all the projects and import them into eclipse IDE. Execute the projects.
If you have any doubts please post the query as comment.
Thanks & regards,
Vikram Y.
Please find the below links:
MANY-TO-MANY ANNOTATIONS
MANY-TO-MANY XML MAPPING
MANY-TO-MANY ONE MORE EXAMPLE
ONE-TO-MANY BI DIRECTIONAL EXAMPLE
Download all the projects and import them into eclipse IDE. Execute the projects.
If you have any doubts please post the query as comment.
Thanks & regards,
Vikram Y.
Sir i am one of ur hibernate class student,Currently i am out of hyderabad.can u please let me know if there is a class for us on sunday.if so,maximum i will manage things here and try to move up by today night.please consider this request
ReplyDeleteHi ravi teja. The morning batch course is completed on saturday. Please check my blog for related infromation for the last class.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteHello sir, i am santosh..attended your hibernate classes(7 am)..
ReplyDeletesir i have one problem..
===================================================
org.hibernate.ObjectDeletedException: deleted object would be re-saved by cascade (remove deleted object from associations): [san.farm.adminuser.entity.AssignCropToSiteRefEntity#18]
at org.hibernate.impl.SessionImpl.forceFlush(SessionImpl.java:1041)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:188)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:117)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:534)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1027)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:365)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:137)
at san.farm.adminuser.service.AssignCropToSiteRefService.deleteAssignCropToSiteRef(AssignCropToSiteRefService.java:94)
at san.farm.adminuser.controller.AssignCropToSiteController.doProcess(AssignCropToSiteController.java:79)
at san.farm.adminuser.controller.AssignCropToSiteController.doPost(AssignCropToSiteController.java:124)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
======================================================
How to solve??
Thank you in advance..
Hi santosh,
ReplyDeleteI'm sorry for late response. I'm out of station so i can't able to browse net. anyway find the solutions here.
What this exception really means is you are telling Hibernate to remove object from database but at the same time this object still exist (that means still exist in java or database) in mapped collection via Persistent entity which has CascadeType.PERSIST annotated over it.
It's like having something tied through elastic rubber on the window and then poke it hoping it will drop. Hibernate is smart it is saving you from doing meaningless stuff, it tells you what to do
deleted object would be re-saved by cascade (remove deleted object from associations)
Now there are more than one solution that I can think of here
Use cascade={CascadeType.PERSIST,CascadeType.REMOVE} or cascade=CascadeType.ALL
As mentioned in hibernate document here
It doesn't usually make sense to enable cascade on a @ManyToOne or @ManyToMany association. Cascade is often useful for @OneToOne and @OneToMany associations.
remove cascade from mapping
may you have FetchType.EAGER in mapping with cascade specified it is little complicated for interpret the behaviour of hibernate. by using FetchType.LAZY am not sure if it will work out for you.
You can do session.saveOrUpdate(upper object) on all the upper class which has this sub object and then go for session.delete(sub object);
Hope you this would solve your problem.
thank you sir,my problem is resolved.i was struggling from last few days for this problem.
ReplyDeleteYou are welcome.
Delete