hibernate学习笔记

javax.naming.NoInitialContextException:Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial

org.hibernate.dialect.MySQLDialect是MySQL 4.x之前的版本. TYPE=MYISAM是MySQL 4.0方言构建的,但在5.5版本已经废除了。

  • 如果用的是 MariaDB,则用以下其中之一代替
    Given that you use MariaDB, you need to use (depending on the version of MariaDB and - maybe - the version of Hibernate) one of:
    org.hibernate.dialect.MariaDBDialect
    org.hibernate.dialect.MariaDB53Dialect
  • 如果你用的是mysql(或在MariaDB中上面不行),则用以下其中之一代替
    org.hibernate.dialect.MySQL5Dialect
    org.hibernate.dialect.MySQL55Dialect
    org.hibernate.dialect.MySQL57Dialect
    参考链接

    Could not unbind factory from JNDI

    或提示下列错误
    javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
    这个错误是因为我们在配置hibernate.cfg.xml时给sessionFactory设了name属性。该name属性的作用是“/jndi/name绑定到JNDI的SessionFactory实例”,而若配置了JNDI则需要添加对应的属性。但在hibernate容器初始化时找不到JNDI服务提供商的默认属性和JNDI服务器没有被显式的配置时发生,所以出错。所以在xxx.cfg.xml将sessionFactory的name属性去掉即可。
    参考链接
    如果是在tomcat下调试出现这个错误的,看这里