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.  [ 4 posts ] 
Author Message
 Post subject: intercepting object creation
PostPosted: Wed Mar 05, 2008 10:58 am 
Beginner
Beginner

Joined: Wed Aug 29, 2007 8:23 am
Posts: 31
Hello.

If I'm not mistaken, all the entity classes need to have a default constructor so that they're initialized by NHibernate. I was wondering if there's anything I can do to intercept entity creation. I'm asking this because I have at least one entity which can't have a default constructor since it needs to receive a reference to another object in order to work correctly.

ok, I can make it have a default constructor and an internal property which could be used to pass that a reference; however, I'd prefer not to change my domain model and intercept object creation so that I'd return an "initialized" entity. is this possible?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 05, 2008 12:00 pm 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
You can use an Interceptor:

http://www.hibernate.org/hib_docs/nhibernate/1.2/reference/en/html/manipulatingdata.html#manipulatingdata-interceptors

There you can override the Instantiate method:

object Instantiate( Type clazz, object id )

and create the class yourself.

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 06, 2008 5:11 am 
Beginner
Beginner

Joined: Wed Aug 29, 2007 8:23 am
Posts: 31
Thanks again!

that's really what I needed :)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 06, 2008 11:23 am 
Beginner
Beginner

Joined: Wed Aug 29, 2007 8:23 am
Posts: 31
Hello again.

hum...it works though I still need to add a default constructor. Anyway, since I'm able to make it private, using the interceptor works really well!

thanks again.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.