Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is data aliasing effect in hibernate?

Tags:

hibernate

I'm planing to use this StatelessSession interface in hibernate. But do not know what data aliasing effect as explained here

like image 720
ruwan.jayaweera Avatar asked Nov 23 '12 06:11

ruwan.jayaweera


1 Answers

consider data like

table parent
id | name
---------
1  | 'foo'

table child
id | parent_id
--------------
1  | 1
2  | 1

and a query

session.query("from child").list();

then the following will fail for StatelessSession session but not for Session session

childs.get(0).getParent().setName("bar");

assertEqual("bar", childs.get(1).getParent().getName());

Update:

StatelessSession does not "remember" the objects it loaded so while dehydration the second child it doesn't know it already created the parent object it refers to and will create another parent object which has the same values but not the same references.

like image 119
Firo Avatar answered Nov 17 '22 07:11

Firo