-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 12 posts ] 
Author Message
 Post subject: No Default Constructor and Getters / Setters using Memento?
PostPosted: Tue Mar 15, 2005 6:55 am 
Newbie

Joined: Tue Mar 15, 2005 6:07 am
Posts: 9
Location: Kiev, Ukraine
I feel bad design when I forced to create no-argument constructor and getters/setters for my persistent classes by Hibernate. Anybody here who have ideas on how to avoid it?

The way I'm thinking on how to approach it is to use Memento pattern
http://home.earthlink.net/~huston2/dp/memento.html
Somebody who used it with Hibernate?

Many thanks.

_________________
Denis Krukovsky
http://dotuseful.sourceforge.net/


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 15, 2005 8:34 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
many options

constructor does not need to be public

access="field"

interceptor.instantiate()

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 15, 2005 8:53 am 
Newbie

Joined: Tue Mar 15, 2005 6:07 am
Posts: 9
Location: Kiev, Ukraine
Thanks Max. The point I'm moving from is
http://www.hibernate.org/hib_docs/v3/re ... onstructor
Quote:
We recommend having a constructor with at least package visibility for runtime proxy generation in Hibernate.

Package visibility is also unlikely option. Not sure what proxy generation is for but I would follow Hibernate documentation recommendations.

_________________
Denis Krukovsky
http://dotuseful.sourceforge.net/


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 15, 2005 9:02 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
proxying is for providing lazy loading, and if you constructor is less than package visible we cant invoke it to create the object.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 15, 2005 9:17 am 
Newbie

Joined: Tue Mar 15, 2005 6:07 am
Posts: 9
Location: Kiev, Ukraine
This is why I'm researching the possibility to apply Memento here. The model I'm thinking about is something like:
- Memento holds state of Entity object. Memento is written according to Hibernate rules (default constructor, getters and setters).
- Entity class have constructor with Memento parameter and is able to instantiate itself from Memento.
- DAO loads Memento from database using Hibernate, and then instantiates Entity using Memento.

Is it possible with Hibernate?

_________________
Denis Krukovsky
http://dotuseful.sourceforge.net/


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 15, 2005 9:32 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
so for each DomainObject you would have a DomainObjectMemento - basically duplicating your whole class hiearchy ?

sounds more like a anti pattern to me ,)

besides - this will work with hibernate, but you would loose alot of great functionality since one thing is loading...another is saving.

You are actually mimicing what is so bad about DTO's ..

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 15, 2005 9:50 am 
Newbie

Joined: Tue Mar 15, 2005 6:07 am
Posts: 9
Location: Kiev, Ukraine
Thanks Max. Memento vs no-args constructor is the subject for another discussion. What I am sure about is that I want to research all the possibilities with both sides.

What Hibernate functionality I'm losing doing this way? I'm especially concerned about business logic or application transactions.

_________________
Denis Krukovsky
http://dotuseful.sourceforge.net/


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 15, 2005 9:58 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
well basically you would need to copy all data from your entity back to the memento to let hibernate save it.

And that is non-trivial for object graphs etc.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 15, 2005 10:07 am 
Newbie

Joined: Tue Mar 15, 2005 6:07 am
Posts: 9
Location: Kiev, Ukraine
Quote:
well basically you would need to copy all data from your entity back to the memento to let hibernate save it.

This is how Memento is working

Quote:
And that is non-trivial for object graphs etc.

Yes - another concern. I'm thinking about - in my entity graph do not hold references to actual persistent Entities but to entity IDs.

_________________
Denis Krukovsky
http://dotuseful.sourceforge.net/


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 15, 2005 10:25 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
okey - so you think package protected default constructors are bad design, but still want to expose ids in your entities.

Well well ,)

I used a object model that only had ids as ref purely because I had to run on a system where the id could be different things at certain points and that I could not define in e.g. a ORM tool how to get it.....

why are you having ID's and not just refs to it ?

-max

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 15, 2005 10:49 am 
Newbie

Joined: Tue Mar 15, 2005 6:07 am
Posts: 9
Location: Kiev, Ukraine
Hey Max

Quote:
why are you having ID's and not just refs to it ?

We might be talking about the same thing actually. I see my Entity will hold reference to another Entity objects (which are identified by IDs they contain). While storing / retrieving from db, Memento could contain IDs of instances my Entity is referring to.

_________________
Denis Krukovsky
http://dotuseful.sourceforge.net/


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 15, 2005 11:04 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
and as such you are redoing what Session does....keeping track of which id that corresponds to a certain entity and if and entity is not yet loaded then get it....

you will be doing a lot of redundant internal bookkeeping...

_________________
Max
Don't forget to rate


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 12 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.