代码之家  ›  专栏  ›  技术社区  ›  DD.

MySQL NDB集群+Hibernate

  •  4
  • DD.  · 技术社区  · 14 年前

    5 回复  |  直到 14 年前
        1
  •  7
  •   Bill the Lizard    12 年前

    this blog post

    那么,我对 MySQL Cluster Overview 数据节点被视为一个整体(从文档中, 如果一个应用程序更新了一个员工的工资,那么所有其他查询此数据的MySQL服务器都可以立即看到此更改

    但是,如果希望Hibernate使用NDB引擎创建表,则需要一种特殊的方言(请参见 HHH-1496

    所以在理论上,一切似乎都好。实际上,

        2
  •  3
  •   gnomie    12 年前

    我们在Hibernate中使用MySQL NDB,它在Hibernate中没有任何适应性,也没有观察到一致性问题。然而,与InnoDB相比,NDB的行为确实有所不同,尤其是在大数据集上。索引必须适合内存,当涉及到长时间运行的事务时,这是相当明智的,并且可以锁定多少行是有限制的(您可以调整这些行,但仍然是无害的“delete from T where x<5“可能运行或失败,具体取决于需要锁定的行数)。因此,不是Hibernate而是Hibernate创建的SQL在NDB上可能无法像您预期的那样工作。

        3
  •  1
  •   sebi    12 年前

    public class CustomMySQL5Dialect extends MySQL5Dialect {
        public String getTableTypeString() {
            return " engine=ndb";
        }
    }
    
        5
  •  1
  •   t7tran    10 年前

    为了帮助下一位读者,我们在高性能应用程序(支持数千个并发用户)中使用NDBCluster和Hibernate已经超过4年了。注意,在版本7.3.1之前,MySQL NDB不支持外键约束( http://dev.mysql.com/doc/relnotes/mysql-cluster/7.3/en/mysql-cluster-news-5-6-10-ndb-7-3-1.html http://dev.mysql.com/tech-resources/articles/mysql-enforcing-foreign-keys.html ).

    public class MySQL5NDBDialect extends MySQLDialect
    {
        private static final String ENGINE_NDB = " ENGINE=NDB"; //$NON-NLS-1$
    
        @Override
        public boolean supportsCascadeDelete()
        {
            return false;
        }
    
        @Override
        public boolean dropConstraints()
        {
            return false;
        }
    
        @Override
        public String getTableTypeString()
        {
            return ENGINE_NDB;
        }
    
        @Override
        public String getAddForeignKeyConstraintString(final String constraintName, final String[] foreignKey,
            final String referencedTable, final String[] primaryKey, final boolean referencesPrimaryKey)
        {
            // our magic to inject triggers
        }
    }
    

    NDB 7.3.1及以上版本将更简单:

    public class MySQLNDB7Dialect extends MySQLDialect
    {
        private static final String ENGINE_NDB = " ENGINE=NDB"; //$NON-NLS-1$
    
        @Override
        public boolean supportsCascadeDelete()
        {
            return true;
        }
    
        @Override
        public boolean dropConstraints()
        {
            return true;
        }
    
        @Override
        public String getTableTypeString()
        {
            return ENGINE_NDB;
        }
    }