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.  [ 2 posts ] 
Author Message
 Post subject: Immutable entity mapping query
PostPosted: Wed Aug 13, 2008 8:47 am 
Newbie

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

The following is an example of a typical immutable entity type that we have in our business domain:

Code:
public class Entity
{
     public readonly int Id;
     public readonly string Name;

     public Entity(int id, string name)
     {
          this.Id = id;
          this.Name = name;
     }
}


Is there anyone out there that can confirm if we can map this type of entity directly in NHibernate without having to make any code changes to our domain entities? (e.g. like adding a default constructor)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 13, 2008 10:44 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
You definitely need a default constructor (which can be private). Hibernate can also access the fields if you use the appropriate access strategy (access="field"), but I'm not sure if it's possible to set read only fields through reflection.

So the answer to your question is no. You have to change your domain code. But you can change the code in a way that the visible part of the entities stays the same.

_________________
--Wolfgang


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