我是靠谱客的博主 秀丽巨人,最近开发中收集的这篇文章主要介绍hibernate入门会遇到的错误 Unable to create requested service,觉得挺不错的,现在分享给大家,希望可以做个参考。
概述
连接不上数据库 (不一定是出错在连接数据库上)
Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
Access to DialectResolutionInfo cannot be null when ‘hibernate.dialect’ not set
这liang两个错可能同时出现
错误图示
可能出现的问题是在
检查这个文件(连接数据库相关代码)里的代码有没有出错
图片代码 (*看代码有没有出错)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- 1. 数据库相关 -->
<property name="connection.username">root</property>
<property name="connection.password">123</property>
<property name="connection.url">jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- 配置本地事务(No CurrentSessionContext configured!) -->
<property name="hibernate.current_session_context_class">thread</property>
<!-- 2. 调试相关 -->
<property name="show_sql">true</property>
<property name="format_sql">true</property>
<!-- 3. 添加实体映射文件 -->
<mapping resource="com/zking/entity/user.hbm.xml"/>
</session-factory>
</hibernate-configuration>
还可能出错的地方是
hibernate入门测试代码
package com.zking.test;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import com.zking.entity.User;
public class Test {
public static void main(String[] args) {
Configuration cnf = new Configuration().configure("/hibernate.cfg.xml");
SessionFactory sessionFactory = cnf.buildSessionFactory();
Session session =sessionFactory.openSession();
Transaction transaction = session.beginTransaction();
User user = new User();
//新增
// user.setUserName("zhuzhzu");
// user.setUserPwd("123");
// session.save(user);
//修改
// user.setId(2);
// user.setUserName("23dddf");
// user.setUserPwd("123ew");
// session.update(user);
//删除
// user.setId(3);
// session.delete(user);
//查询
user.setId(3);
User user2 = session.get(User.class, 2);
System.out.println(user2);
transaction.commit();
session.close();
}
}
最后
以上就是秀丽巨人为你收集整理的hibernate入门会遇到的错误 Unable to create requested service的全部内容,希望文章能够帮你解决hibernate入门会遇到的错误 Unable to create requested service所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复