-->
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.  [ 1 post ] 
Author Message
 Post subject: PrePersist / PostLoad behaviour in Hibernate?
PostPosted: Fri Nov 06, 2009 7:12 am 
Newbie

Joined: Fri Nov 06, 2009 6:45 am
Posts: 2
I'm sorry if these tings have been dealt with before on this forum - I was however not able to find any relevant previous topic, nor any solution by googling.

Basically, I'm having two problems. My application is domain-driven, and thus my entities are part of a rich domain model were I want to restrict access to fields, data and behaviour as much as possible when motivated. One such case is the instantiation of the entities. In many cases, factories are responsible for assembling the objects and enforcing class invariants. This is only a problem in part with Hibernate, thanks to access="field" which is a godsend, since I don't have to expose setters and getters for all my methods. However, I still need to create a default constructor in order for Hibernate to create instances when restoring objects from the database. I'm not pleased with this, even though I may at least give the constructor default-access and disallow illegal instantiation outside of the package. I would like to delegate the restoration/re-assembly of different entities to static factory methods and actual factory instances.

Question: Is this at all possible?

This ties into another problem that I have. I have an aggregate in my domain model that keeps track of certain aspects of the state of things using a couple of value objects that contain far more information than I need, or even feel that I should, persist. I would like to be able to hook into the creation process (@PostLoad?) and reconstruct these value objects using a factory. The same goes, of course for @PrePersist and @PreUpdate, that I need to convert back from these rich value objects to the smaller data structure. It may sound like I just gave the solution to my problem myself, but I do not want to use Annotations.

Questions:
Can I define this behaviour in hbm.xml mappings?
Must the methods that handle these events be a part of the entity class itself?

I'm thankful for any input and/or discussions that follows...

Regards,
Sven


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

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.