1

how to setup nhibernate configuration (fluent configuration) for MySql and force the default engine to be InnoDB so Im able to use Transactions

thanks

2 Answers 2

2

Or you may want to use this custom dialect

public class MySQL5InnoDBDialect
        : MySQL5Dialect
    {

        public MySQL5InnoDBDialect()
        {
            RegisterColumnType(DbType.Guid, "CHAR(36)"); //You don't "really" need this one for what you asked
        }

        public override string TableTypeString
        {
            get { return " ENGINE=InnoDB"; }
        }

        public override bool HasSelfReferentialForeignKeyBug
        {
            get { return true; }
        }

        public override bool SupportsCascadeDelete
        {
            get { return true; }
        }
    }

(update your .config file accordingly)

<property name="dialect">
Org.Zighinetto.MySQL5InnoDBDialect, Org.Zighinetto
</property>

The dialect trick works fine when you don't own MySQL installation (ie. you use shared hosting) and default is the usual MyISAM

Sign up to request clarification or add additional context in comments.

Comments

0

Generally there is nothing specific that you would have to do with your mappings to work with mysql and innodb.

Switching to innodb engine is something you will have to do from inside of mysql yourself, it is not related to nHibernate. http://dev.mysql.com/doc/refman/5.1/en/storage-engine-setting.html

Here is a sample configuration that I use for mysql (innodb) and nHibernate:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
    <session-factory>
    <property name="connection.connection_string">Data Source=localhost;Database=test;UID=root;pwd=;</property>
    <property name="dialect">NHibernate.Dialect.MySQL5Dialect</property>
    <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
    <property name="connection.driver_class">NHibernate.Driver.MySqlDataDriver</property>
        <property name="show_sql">false</property>
        <property name="connection.release_mode">auto</property>
        <property name="adonet.batch_size">500</property>
        <property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
    <property name="hbm2ddl.keywords">none</property>
    </session-factory>
</hibernate-configuration>

5 Comments

what if I use nhibernate SchemaExport to create the database for me?
It would still be the same config. I use SchemaExport myself.
what if i would like to have a table/column use InnoDB engine and the other one use MyISAM?
It's a per table configuration and it doesn't matter for nHibernate which one you use. Also, changing engine for a column doesn't make sense.
right per table configuration, how do we go about that? for example for a domain object i want nhibernate to use innodb engine when creating db table and for another one myisam. thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.