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: Calling constructor that performs guard checks
PostPosted: Thu Oct 23, 2008 5:23 am 
Newbie

Joined: Wed Jun 25, 2008 10:24 am
Posts: 3
Location: Ireland
All,

We are using immutable types in our domain, that we want to map
directly to to database. The type takes the following format:

Code:
public class X
{
     private readonly int m_Prop1;
     private readonly int m_Prop2;

     private X() { }

     public X(int p1, int p2)
     {
         //Perform validation guard check against arguments

         this.m_Prop1 = p1;
         this.m_Prop2 = p2;
     }

     public int Prop1 { get { return this.m_Prop1; } }
     public int Prop2 { get { return this.m_Prop2; } }
}

The problem we have is that the private constructor is what NHibernate
instantiates (not the public constructor where guard checks are
performed), hence we can end up "getting" an instance of X from the
database that is invalid.

Is there any way to get NHibernate to call the constructor that
performs the guard checks?

Any help with this will be greatly appreciated.


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.