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: Mapping to entity with interface
PostPosted: Mon Jun 30, 2008 9:33 am 
Newbie

Joined: Mon Jun 30, 2008 9:12 am
Posts: 3
I have two assemblies: BLL and BLL.Interface
BLL.Interface contains interfaces of the bussiness entities. For example:
public interface IVartotojai
{
#region Public Properties
int Userid{get; set;}
string UserName{get; set;}
ISkyriai Skyriausid{get;set;}
}

BLL assembly has concrete implementation and mapping files. Mapping file looks like this:
using System;
using System.Collections;
using System.Collections.Generic;
using NmpkStatistika.BLL.Interface.Entities;

namespace NmpkStatistika.BLL.Entities
{

/// <summary>
/// Vartotojai object for NHibernate mapped table 'Vartotojai'.
/// </summary>
[Serializable]
public class Vartotojai : ICloneable,IVartotojai
{
#region Member Variables

protected int _userid;
protected string _username;
protected ISkyriai _skyriausid;

public virtual int Userid
{
get { return _userid; }
set { _bIsChanged |= (_userid != value); _userid = value; }

}

public virtual string UserName
{
get { return _username; }
set
{
if (value != null && value.Length > 50)
throw new ArgumentOutOfRangeException("UserName", "UserName value, cannot contain more than 50 characters");
_bIsChanged |= (_username != value);
_username = value;
}

}
public virtual ISkyriai Skyriausid
{
get { return _skyriausid; }
set { _bIsChanged |= (_skyriausid != value); _skyriausid = value; }

}
}

Mapping file like this:

<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="NmpkStatistika.BLL.Entities.Vartotojai,BLL" table="Vartotojai" lazy="true" proxy="NmpkStatistika.BLL.Interface.Entities.IVartotojai,BLL.Interface">
<id name="Userid" column="UserID" type="int">
<generator class="native" />
</id>
<property type="string" not-null="true" length="50" name="UserName" column="[UserName]" />
<many-to-one name="Skyriausid" cascade="none" column="SkyriausID" not-null="true" />
</class>
</hibernate-mapping>

I allways getting error that there is unmapped entity ISkyriai... If I comment out ISkyriai mapping part from Vartotojai.hbm.xml, I can query data that way:
session.CreateCriteria(typeof(IVartotojai)).List<IVartotojai>();
or
session.CreateCriteria(typeof(Vartotojai)).List<IVartotojai>();

So, I think nHibernate knows that IVartotojai = Vartotojai...

Tried create class section for interface with subclas section for concrete class, but nhibernate needs discriminator value, which I don't have...

How can I make this?

Skiv

P.S.: sorry for my poor english.


Top
 Profile  
 
 Post subject: Done
PostPosted: Tue Jul 01, 2008 6:33 am 
Newbie

Joined: Mon Jun 30, 2008 9:12 am
Posts: 3
Created two mapping files for each entity: for concrete class and for interface. When creating query criteria, used concrete class. That's all.


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.