I have a parent and child relationship. Both are of type Person. I need to know how to update the child's parent. Currently I am loading the parent and child from the database and then set the parent to the child and update the child. Is there an simple update statement for the same. My current code is
where the named query is
I need query like
But instead of the type String, in my case it is Person. Should I need to load new and old Peron to make a update statement.
You could use NativeQuery for update data in Hibernate..
perhaps it's simpler than we have to use HQL..
the NativeQuery in Hibernate is executed like this :
you could use the parameters also for dynamic query..
Hope this help..
Correct me if i'm wrong..
Thanks..
Sorry, perhaps my english language isn't too good.. Prepare for SCJP 6, Please God help me.. ☼
References : [Java.Boot] [JavaChamp] [JavaPrepare]
Currently I am doing that only. Instead of the name, I have another entity that needs to be loaded from the data base. So it is like 2 select statements to load the child and Parent (both of type person). and another statement to update the child with the new parent set in it. There are 3 sql statement executed in the database.
And as you suggest if we are going to use NativeSqlStatement, there is only one sql statement executed in the DB. This should increase the performance.
My doubt here is does using HQL always result in performance hit when compared to native sql.
Its could be arranged in the fetch property value set to LAZY...
While we set the fetch property to LAZY, then the hibernate force to generate only the "Parent"..
For further information you can read book Java Persistence with Hibernate..
Thanks,..
Sorry, perhaps my english language isn't too good.. Prepare for SCJP 6, Please God help me.. ☼
References : [Java.Boot] [JavaChamp] [JavaPrepare]