No mapped documents in assembly

719 views
Skip to first unread message

Dave Harms

unread,
Jul 6, 2009, 3:19:46 PM7/6/09
to nhprof
Noob question here: I'm having trouble executing some unit tests in a
Sharp architected-web app. When I attempt to run my unit tests against
a PostgreSQL database NHProf reports a warning:

No mapped documents found in assembly.

That's only when I'm testing against PostgreSQL - I don't get any such
warning when I'm doing SQLite in-memory testing.

Following the SA convention I have my core classes in one assembly
(MvcDemo.Core) and my mapping classes in another (MvcDemo.Data). I've
followed the SA Northwind example, so I have a line in my App.config
appSettings section:

<add key="nhibernate.mapping.assembly" value="MvcDemo.Data" />

I don't get the same error with the SA Northwind live database tests.
I've compared my source code for the mapping classes with the
Northwind example (AutoPersistenceModelGenerator and the individual
entity maps), and I've even checked the IL code. I can't see any
reason why in my app the mapping classes wouldn't be found. At this
point the only material difference I'm aware of is that Northwind uses
MS SQL and my app uses PostgreSQL.

Any ideas where I should be looking? Or is this a bug in NHProf? Many
thanks.

Ayende Rahien

unread,
Jul 6, 2009, 3:33:45 PM7/6/09
to nhp...@googlegroups.com
It is likely that you are also including another assembly when you are using PostgreSQL
Can you post the code & config that you are using with it?

Dave Harms

unread,
Jul 6, 2009, 3:56:20 PM7/6/09
to nhprof
Sure - here you go.

Here's the entity class (abbreviated):

namespace MvcDemo.Core
{
public class User : Entity
{
protected User()
{
}
public User(String userName) : this() {
UserName = userName;
}
public User(String firstName,String lastName) : this() {
FirstName = firstName;
LastName = lastName;
}

[DomainSignature]
[NotNullNotEmpty]
public virtual String UserName { get; set; }

public virtual String FirstName { get; set; }
public virtual String LastName { get; set; }


}
}

Mapping class:

namespace MvcDemo.Data.NHibernateMappings
{
public class UserMap : IAutoMappingOverride<User>
{
public void Override(AutoMap<User> mapping) {
mapping.WithTable("user_");
mapping.SetAttribute("lazy", "false");
mapping.Id(x => x.Id, "UserId");
}
}
}

Automapper config:

namespace MvcDemo.Data.NHibernateMaps
{
public class AutoPersistenceModelGenerator :
IAutoPersistenceModelGenerator
{
public AutoPersistenceModel Generate() {
AutoPersistenceModel mappings = AutoPersistenceModel
.MapEntitiesFromAssemblyOf<User>()
.Where(GetAutoMappingFilter)
.WithConvention(GetConventions)
.UseOverridesFromAssemblyOf<AutoPersistenceModelGenerator>
();

return mappings;
}
/// <summary>
/// Provides a filter for only including types which inherit
from the IEntityWithTypedId interface.
/// This might be considered a little hackish having this
magic string in the comparison, but since
/// the interface is generic, it wouldn't be possible to
compare the type directly.
/// </summary>
private bool GetAutoMappingFilter(Type t) {
return t.GetInterfaces().Any(x =>
x.IsGenericType && x.GetGenericTypeDefinition() ==
typeof(IEntityWithTypedId<>));
}

private void GetConventions(Conventions c) {
c.GetPrimaryKeyNameFromType = type => type.Name + "ID";
c.FindIdentity = type => type.Name == "Id";
c.GetTableName = type => Inflector.Net.Inflector.Pluralize
(type.Name);
c.IsBaseType = IsBaseTypeConvention;
c.GetForeignKeyNameOfParent = type => type.Name + "ID";
}

private bool IsBaseTypeConvention(Type arg) {
bool derivesFromEntity = arg == typeof(Entity);
bool derivesFromEntityWithTypedId = arg.IsGenericType &&
(arg.GetGenericTypeDefinition() == typeof
(EntityWithTypedId<>));

return derivesFromEntity || derivesFromEntityWithTypedId;
}
}
}

The test app's App.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net"
type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
</configSections>

<appSettings>
<!-- Accepts a comma delimited list of assembly names containing
mapping artifacts; the ".dll" is optional -->
<add key="nhibernate.mapping.assembly" value="MvcDemo.Data" />
</appSettings>

<log4net>
<appender name="LogToFile" type="log4net.Appender.FileAppender">
<file value="../../logs/Northwind.Tests.log"/>
<appendToFile value="false"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%d [%t] %-5l - %m%n%n"/>
</layout>
</appender>
<appender name="ConsoleAppender"
type="log4net.Appender.ConsoleAppender">
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%d [%t] %-5l - %m%n%n"/>
</layout>
</appender>
<root>
<!-- Value of priority may be ALL, DEBUG, INFO, WARN, ERROR, FATAL,
OFF -->
<priority value="DEBUG"/>
<appender-ref ref="ConsoleAppender"/>
</root>
</log4net>

<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="nunit.framework"
publicKeyToken="96d09a1eb7f44a77" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535"
newVersion="2.4.8.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="NHibernate"
publicKeyToken="aa95f207798dfdb4" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535"
newVersion="2.0.1.4000"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Iesi.Collections"
publicKeyToken="AA95F207798DFDB4" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535"
newVersion="1.0.1.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>


Hibernate.cfg.xml

<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" >
<session-factory>
<property
name="connection.connection_string">Server=127.0.0.1;Port=5432;Database=MvcDemo;User
Id=********;Password=********;</property>
<property name="dialect">NHibernate.Dialect.PostgreSQLDialect</
property>
<property
name="connection.provider">NHibernate.Connection.DriverConnectionProvider</
property>
<property
name="connection.driver_class">NHibernate.Driver.NpgsqlDriver</
property>
<property name="connection.release_mode">on_close</property>
<property name="show_sql">true</property>
</session-factory>
</hibernate-configuration>

I'm initializing NHProf in the unit test like this since it's a single
test at the moment. I suppose I should move this to a singleton:

[TestFixtureSetUp]
public void Setup()
{

HibernatingRhinos.NHibernate.Profiler.Appender.NHibernateProfiler.Initialize
();
}

Thanks, and let me know if you need anything else.

Dave

On Jul 6, 2:33 pm, Ayende Rahien <aye...@ayende.com> wrote:
> It is likely that you are also including another assembly when you are using
> PostgreSQLCan you post the code & config that you are using with it?

Ayende Rahien

unread,
Jul 6, 2009, 3:59:46 PM7/6/09
to nhp...@googlegroups.com
I _think_ that the problem is here:


.MapEntitiesFromAssemblyOf<User>()

I am not sure how FN is dealing with that, but it may translate into a call to AddAssembly, and since you aren't using hbm files, you won't have any mapped entities there.

Dave Harms

unread,
Jul 6, 2009, 4:16:28 PM7/6/09
to nhprof
I *think* that line is okay - as I understand it that's simply telling
FNH where to find the entities it's mapping. The SA NW example does
the same thing.

What's maddening about all this is that the SA NW example works just
fine. I've got to be doing something really dumb somewhere and I just
haven't found it yet. But I have a working example, so I'll hack at
that until I find out where I went wrong.

Dave

On Jul 6, 2:59 pm, Ayende Rahien <aye...@ayende.com> wrote:
> I _think_ that the problem is here:
>
> .MapEntitiesFromAssemblyOf<User>()
>
> I am not sure how FN is dealing with that, but it may translate into a call
> to AddAssembly, and since you aren't using hbm files, you won't have any
> mapped entities there.
>

Dave Harms

unread,
Jul 6, 2009, 6:14:22 PM7/6/09
to nhprof
It appears to be a non-issue. After playing some more with the NW
example and my own code I've concluded that while NHProf issues a
warning about no mapping files being found, in fact the mappings are
in effect. Perhaps FNH applies the mappings at some point after that
warning.

Dave
> ...
>
> read more »

Dave Harms

unread,
Jul 6, 2009, 6:15:47 PM7/6/09
to nhprof
Oh, and the warning message *is* there in the NW example as well, at
least in my most recent tests. Not sure how I came to believe it
wasn't. Perhaps I was running the wrong test suite.

Dave

On Jul 6, 3:16 pm, Dave Harms <dgha...@gmail.com> wrote:
> ...
>
> read more »
Reply all
Reply to author
Forward
0 new messages