为了账号安全,请及时绑定邮箱和手机立即绑定

使用的是Java1.8环境;报错说有两个,但没有提示;下面是控制台信息:想要问一下具体出现什么错误?

//控制台信息

十月 22, 2017 1:07:00 下午 org.hibernate.Version logVersion

INFO: HHH000412: Hibernate Core {5.0.1.Final}

十月 22, 2017 1:07:00 下午 org.hibernate.cfg.Environment <clinit>

INFO: HHH000206: hibernate.properties not found

十月 22, 2017 1:07:00 下午 org.hibernate.cfg.Environment buildBytecodeProvider

INFO: HHH000021: Bytecode provider name : javassist

十月 22, 2017 1:07:01 下午 org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>

INFO: HCANN000001: Hibernate Commons Annotations {5.0.0.Final}

十月 22, 2017 1:07:01 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure

WARN: HHH000402: Using Hibernate built-in connection pool (not for production use!)

//测试类代码

import java.util.Date;


import org.hibernate.Session;

import org.hibernate.SessionFactory;

import org.hibernate.Transaction;

import org.hibernate.boot.registry.StandardServiceRegistryBuilder;

import org.hibernate.cfg.Configuration;

import org.hibernate.service.ServiceRegistry;

import org.junit.After;

import org.junit.Before;

import org.junit.Test;


//测试类

public class StudentsTest {


private SessionFactory sessionFactory;

private Session session;

private Transaction transaction;

@Before

public void init() {

Configuration config=new Configuration().configure();

//创建配置对象

ServiceRegistry serviceRegistry=(ServiceRegistry) new StandardServiceRegistryBuilder().applySettings(config.getProperties()).build();

//创建服务注册对象

sessionFactory =config.buildSessionFactory(serviceRegistry);

//创建会话工厂对象

session = sessionFactory.openSession();

//打开会话

transaction = session.beginTransaction();

//打开事务

}

@After

public void destory() {

transaction.commit();//提交事务

session.close();//关闭会话

sessionFactory.close();//关闭会话工厂

}

@Test

public void toSaveStudents() {

Students s = new Students(1, "张三丰", "男", new Date(), "武当山");

session.save(s);//保存进数据库

}

}

//配置类信息

<?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>

    <property name="connection.username">root</property>

    <property name="connection.passsword">root</property>

    <property name="connection.driver_class">com.mysql.jdbc.driver</property>

    <property name="connection.url">jdbc:mysql:///hibernate?useUnicode=true&amp;characterEncoding=UTF-8</property>

    <property name="dialect">org.hibernate.dialect.MySQLDialect</property>

    

    <property name="show_sql">true</property>

    <property name="format_sql">true</property>

    <property name="hbm2ddl.auto">create</property>

    

    <mapping resource="Students.hbm.xml"/>

    </session-factory>

</hibernate-configuration>


正在回答

1 回答

看junit有报错信息,如果你的数据库是5.x,那么方言就不对,要换成org.hibernate.dialect.MySQL5Dialect

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

使用的是Java1.8环境;报错说有两个,但没有提示;下面是控制台信息:想要问一下具体出现什么错误?

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信