Hello,
First of all I'm really sorry for the cross-posting (I post the same message to domaindrivendesign ---
http://groups.yahoo.com/group/domaindri ... ssage/1014).
I'd like to know if there's such "Unit of Work implementation in Hibernate? To give context for this discussion, here's the link to explanation about "Unit of Work" --
http://domaindrivendesign.org/discussio ... fWork.html
I was told by someone that most ORM tool have this feature (although they might name it differently) --
http://groups.yahoo.com/group/domaindri ... ssage/1013.
This link explains how I got into this "Unit of Work" question:
http://groups.yahoo.com/group/domaindri ... essage/997
Finally, here's my question to this forum (thanks in advance):
-----
Hmm, "unit of work"? Ok, my search on google lead me to these pages:
- RepositoryAndUnitOfWork (
http://domaindrivendesign.org/discussio ... fWork.html)
- Hibernate API (
http://www.hibernate.org/hib_docs/api/n ... ction.html)
- Spring API (
http://www.springframework.org/docs/api ... essor.html)
At this moment I don't know how they're interrelated. Nick's post that mentioned "unit of work" (
http://groups.yahoo.com/group/domaindri ... ssage/1002) gave me the impression that it's equal to Transaction (?). And the hibernate API that mentions "unit of work" strengthen that impression.
Before I go further crawling for more info on the web, could you help me by clarifying the effect of "unit of work"? Your explanation suggest that it's an ability of ORM tool (like Hibernate) to call "session.save(anObject)" after we do something on that object that makes it dirty [the session.save() call takes place when tx.commit() is called], right?
Like this:
---
net.sf.hibernate.Transaction tx = hibernateSession.beginTransaction();
Object anObject = hibernateSession.load(AClass.class, new Long(123));
anObject.doSomething(); //doSomething change the value of some attributes of anObject
tx.commit();//all the changes we've made to anObject will be saved.
---
???
All this time I always call session.saveOrUpdate(anObject) manually after modifying its state. Like this:
---
net.sf.hibernate.Transaction tx = hibernateSession.beginTransaction();
Object anObject = hibernateSession.load(AClass.class, new Long(123));
anObject.doSomething(); //doSomething change the value of some attributes of anObject
hibernateSession.update(anObject);
tx.commit();
---
Oooppss.... so I've been using Hibernate the wrong way then (?). Is there anything I need to set in Hibernate configuration to activate this "unit of work" feature?
Best regards,
Raka (
http://www.jroller.com/page/donraka &
http://www.geocities.com/wirama_putra/w ... rmasastra/)