4

I'm learning Nhibernate and am making a test project. I want to generate tables based on the entities. In the test project, I am using sqlite and can see the output: "drop table if exists Player" but it's not creating the table Player afterwards. I have confirmed by copying the Player.hbm.xml file into another folder that the mapping is being found.

Test class in the test project:

    [Test]
    public void TestCanGenerateSchema()
    {
        var cfg = new Configuration();
        cfg.Configure(); //tell NH to configure itself based on the config
        cfg.AddAssembly(typeof(Player).Assembly); //find mapping info in this assembly

        new SchemaExport(cfg).Execute(true, true, true);
    }

My Hubernate.cfg.xml in the test project:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
    <session-factory>
        <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
        <property name="dialect">NHibernate.Dialect.SQLiteDialect</property>
        <property name="connection.driver_class">NHibernate.Driver.SQLite20Driver</property>
        <property name="connection.connection_string">Data Source=:memory:;Version=3;New=True;</property>
        <property name="connection.release_mode">auto</property>
        <property name="show_sql">true</property>
        <property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
        <!-- mapping files -->
    </session-factory>
</hibernate-configuration>

My mapping file in Chess.Web project (Build Action = Embedded Resource):

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                   assembly="Chess.Web"
                   namespace="Chess.Web.Domain">
    <class name="Player">
        <id name="Id"/>
        <property name="Name" />
        <property name="Password" />
    </class>
</hibernate-mapping>

Any ideas?

Ben
  • 1,853
  • 19
  • 20
  • I don't know much about Hibernate, but I will try to help you in this comment, as I am a chess fan myself. We can state that your commands are generated, but is there any evidence that your commands are really executed? I'm looking forward for your nice chess product and I wish you the best of luck with it. – Lajos Arpad Mar 11 '13 at 18:57

1 Answers1

8
new SchemaExport(cfg).Execute(true, true, true);

Third parameter should probably be false if you want to create tables:

justDrop
true if only the ddl to drop the Database objects should be executed.
Dmitry
  • 17,078
  • 2
  • 44
  • 70
  • 1
    Wow, was a simple solution. Teaches me to be more careful and read the parameters. Thanks! – Ben Mar 12 '13 at 01:11