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.  [ 5 posts ] 
Author Message
 Post subject: Implementing Interface
PostPosted: Thu Oct 05, 2006 8:50 pm 
Newbie

Joined: Thu Sep 14, 2006 8:52 pm
Posts: 12
We are designing a layered application - ui, domain, persistence,...
We also primarily work with interfaces. ie we pass interfaces around and variables to hold object reference are of type "Interface".

I have a "Client" which implements "IClient". I would like to restrict the reference to the Client implementation just to this - IClient aClient = new Client() in the domain layer. Also, We would like to keep all the NHibernate code in the persistence layer and we would like it to only know about the Interfaces.

In my mapping file (<>.hbm.xml) if I use the class name as "IClient" then Session.Save(aClient) chokes because it expects an object of type IClient while aClient is of type "Client".

To avoid this, if in my mapping file I use the class name as "Client" then the object constructed and returned by Session.Get<IClient>(ClientId) chokes because it only knows how to construct "Client".

So my question is this - in the nhibernate way of the world, is it possible to have a class implement an Interface and that Class/Interface is implemented as a single table in the db?

Other way to ask the question would be, is there any way I can convey the information to nhibernate that Client implements the interface IClient so it is appropriate interchange Client for IClient and vice-versa.


Top
 Profile  
 
 Post subject: Re: Implementing Interface
PostPosted: Fri Oct 06, 2006 2:46 am 
Expert
Expert

Joined: Thu Jan 19, 2006 4:29 pm
Posts: 348
softlogger wrote:
In my mapping file (<>.hbm.xml) if I use the class name as "IClient" then Session.Save(aClient) chokes because it expects an object of type IClient while aClient is of type "Client".

To avoid this, if in my mapping file I use the class name as "Client" then the object constructed and returned by Session.Get<IClient>(ClientId) chokes because it only knows how to construct "Client".

So my question is this - in the nhibernate way of the world, is it possible to have a class implement an Interface and that Class/Interface is implemented as a single table in the db?


Ist should be popssible to implemet this with sub-class mapping.
I.e. You map IClient as class and Client as subclass.

Gert

_________________
If a reply helps You, rate it!


Top
 Profile  
 
 Post subject: Re: Gert's response
PostPosted: Fri Oct 06, 2006 1:54 pm 
Newbie

Joined: Thu Sep 14, 2006 8:52 pm
Posts: 12
I keep running into this Exception.

TestLayer.ClientTest.RetrieveAndUpdateClient : System.TypeInitializationException : The type initializer for 'Persistency.DbMgr' threw an exception.
----> NHibernate.MappingException : discriminator mapping required for polymorphic persistence

I tried different combination of values for the the discriminator value without luck. Can you please see what's wrong with the mapping as show here -
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0"
namespace="Model.Interfaces"
assembly="Model.Interfaces">
<class name="IClient" table="cus" discriminator-value="Model.Client.Client">
<id name="Id" column="cusky">
<generator class="guid" />
</id>
<property name="FirstName" column="cus01frnm" />
<property name="LastName" column="cus01lanm" />
<property name="Status" column="cusstat" />
<property name="Change" column="`change`" />
<property name="Create" column="`create`" />
<subclass name="Model.Client.Client, Model.Client" extends="Model.Interfaces.IClient" discriminator-value="Model.Client.Client">

</subclass>
</class>

</hibernate-mapping>


Top
 Profile  
 
 Post subject: one more thing....
PostPosted: Fri Oct 06, 2006 1:56 pm 
Newbie

Joined: Thu Sep 14, 2006 8:52 pm
Posts: 12
This is a single class implementing an Interface and mapping to a single table so I do not really have a discriminating column as shown in most examples.


Top
 Profile  
 
 Post subject: Re: one more thing....
PostPosted: Sat Oct 07, 2006 5:31 am 
Expert
Expert

Joined: Thu Jan 19, 2006 4:29 pm
Posts: 348
softlogger wrote:
This is a single class implementing an Interface and mapping to a single table so I do not really have a discriminating column as shown in most examples.


I have no idea if it possible to have subclass mapping without discriminator column. I would think that not.

Gert

_________________
If a reply helps You, rate it!


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