-->
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.  [ 3 posts ] 
Author Message
 Post subject: Problem using interfaces
PostPosted: Fri Apr 06, 2007 5:47 pm 
Newbie

Joined: Fri Apr 06, 2007 5:37 pm
Posts: 1
Hi,
I created interfaces for my database objects which are declared as internal in the data-access dll. In the mapping files I map the concrete classes to the tables.

The mapping is correct - I can save, delete and load objects from the db.

My problem is as follows:
in a factory class I added a generic Load<T>(object id) function, which simply routes to the session's Load()-function. because outside the dll only the interfaces are visible, I pass the interface as the generic parameter to this function.

This doesn't work, I get the exception
"Unknown entity class: ICustomer"

I understand the reason for this: there's no mapping for the interface. Is there any way in the mapping file to specify that a class is implementing an interface and that this class is instantiated if you query for that interface? or any other workaround?


Here's an example:

public interface ICustomer
{
...
}

internal class CustomerImpl : ICustomer
{
...
}

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="CodeFactory.CfFaktura.Data" namespace="CodeFactory.CfFaktura.Data.Entities">
<class name="CustomerImpl" table="customer" lazy="false">
...
</class>
</hibernate-mapping>


mfg Steven


Top
 Profile  
 
 Post subject: Me Too
PostPosted: Tue Apr 17, 2007 5:13 pm 
Newbie

Joined: Tue Apr 17, 2007 4:55 pm
Posts: 1
I'm trying to do this exact thing. Is there any way to give NH a "hint" as to which concrete implementation to use? I'd really like to talk in interface terms all the way down to my repository.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 19, 2007 2:41 am 
Senior
Senior

Joined: Mon Aug 21, 2006 9:18 am
Posts: 179
I've wondered about this...
It seems like you should be able to modify the code to use something like Castle's IoC container to be map to the implemented type. This would decouple the persistence from the implementation details more too.
Somewhere in the AbstractEntityLoader...within the Load method do the lookup?
Not sure how well this would work with collections/objectgraphs but I am assuming that if at the last possible moment the lookup happened it seems feasible. Performance would seem to suffer tho.
Mike

_________________
If this helped...please remember to rate it!


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