1.在hibernate配置文件中方言配置“org.hibernate.dialect.MySQLDialect”中的MYSQL那个y要小写。
如果数据库是本地,hibernate配置文件中的地址这样配置:jdbc:mysql://localhost/hibernate
2.java.lang.NoSuchMethodError: org.hibernate.internal.CoreMessageLogger.debugf(Ljava/lang/String;I)V
3.java.lang.AbstractMethodError: Method com/mysql/jdbc/PreparedStatement.setBinaryStream(ILjava/io/InputStream;J)V is abstract
出现以上错误,自行下载mysql-connector-java-bin5.1.7版本进行替换,可解决问题。
4.在创建会话
Session session = sessionFactory.getCurrentSession();
如果报错org.hibernate.HibernateException: No CurrentSessionContext configured!
那就在hibernate.cfg.xml
加<property name="current_session_context_class">thread</property>设置session会话
或者不在hibernate内设置,把Session session = sessionFactory.getCurrentSession();
换成Session session = sessionFactory.openSession();