-->
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: Running SchemaExport from another app
PostPosted: Fri Apr 21, 2006 5:45 pm 
Newbie

Joined: Fri Apr 21, 2006 5:33 pm
Posts: 12
Hi,

I'm trying to write an app that can generate HBM files and DDL files for any given assembly.

The code below looks like it should work, but it doesn't. I've highlighted the line that fails, and the exception is:
"System.TypeLoadException: Could not load type 'Northwind.Address, NHibernate, Version=1.0.2.0, Culture=neutral, PublicKeyToken=154fdcb44c4484fc', check that type and assembly names are correct"

Can anyone explain why it doesn't work, and what I can do to get around the problem?

Code:
''' <summary>
''' Generates the database schema to support the mappings
''' </summary>
''' <remarks></remarks>
Friend Sub generateSchema(ByVal assemblyFilePath As String, ByVal hbmDirectory As String, ByVal schemaOutputDirectory As String)
    Dim _assembly As Reflection.Assembly = Reflection.Assembly.LoadFrom(assemblyFilePath)

    ' Certain NH properties need to be configured before the mappings can be loaded:
    Dim _properties As New Hashtable
    _properties.Add("hibernate.dialect", "NHibernate.Dialect.MsSql2000Dialect")
    _properties.Add("hibernate.connection.driver_class", "NHibernate.Driver.SqlClientDriver")
    _properties.Add("hibernate.connection.provider", "NHibernate.Connection.DriverConnectionProvider")

    Dim _nhConfig As New NHibernate.Cfg.Configuration
    _nhConfig.AddProperties(_properties)

    ' Load the Configuration with the mapping files:
    Dim _hbmFiles() As String = IO.Directory.GetFiles(hbmDirectory, "*.hbm.xml")
    For Each _hbmFile As String In _hbmFiles
        _nhConfig.AddFile(_hbmFile)     '<---- BANG!!
    Next

    ' Perform the export:
    Dim _exporter As New NHibernate.Tool.hbm2ddl.SchemaExport(_nhConfig)
    Dim _outputFile As String = IO.Path.Combine(schemaOutputDirectory, _assembly.GetName.Name & ".sql")
    _exporter.SetOutputFile(_outputFile)
    _exporter.Execute(True, False, False, True)
End Sub


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 24, 2006 2:44 am 
Newbie

Joined: Mon Apr 03, 2006 10:47 pm
Posts: 4
It can't work!

It need create a new domain.


Top
 Profile  
 
 Post subject: Re: Running SchemaExport from another app
PostPosted: Mon Apr 24, 2006 10:02 am 
Contributor
Contributor

Joined: Thu May 12, 2005 8:45 am
Posts: 226
Vij wrote:
"System.TypeLoadException: Could not load type 'Northwind.Address, NHibernate, Version=1.0.2.0, Culture=neutral, PublicKeyToken=154fdcb44c4484fc', check that type and assembly names are correct"


It's likely a mapping error. You have a class "Northwind.Address" but you didn't specify the assembly to load that type from. It should be "Northwind.Address, <insert_assembly_name_here>".


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.