猿问

hibernate运行报错

hibernate-release-5.2.9.Final

junit4.9

mysql使用5.1.29

这是cfg.xml文件

<?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.password">123456</property>

    <property name="connection.driver_name">com.mysql.jdbc.Driver</property>

    <property name="connection.url">jdbc:mysql://localhost:3306/webases</property>

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

     

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

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

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

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

    </session-factory>

</hibernate-configuration>

这是实体类

package hibernate;


import java.util.Date;


public class Student {

      private int sid;

      private String sname;

      private String gender;

      private Date birthday;

      private String address;

      

     

      public Student(int sid,String sname,String gender,Date birthday,String address){

     this.sid=sid;

     this.sname=sname;

     this.gender=gender;

     this.birthday=birthday;

     this.address=address;

     

      }

 public Student(){

     

     

      }

public int getSid() {

return sid;

}

public void setSid(int sid) {

this.sid = sid;

}

public String getSname() {

return sname;

}

public void setSname(String sname) {

this.sname = sname;

}

public String getGender() {

return gender;

}

public void setGender(String gender) {

this.gender = gender;

}

public Date getBirthday() {

return birthday;

}

public void setBirthday(Date birthday) {

this.birthday = birthday;

}

public String getAddress() {

return address;

}

public void setAddress(String address) {

this.address = address;

}

      

}

这是hbm.xml

<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"

"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<!-- Generated 2017-3-18 17:32:20 by Hibernate Tools 3.5.0.Final -->

<hibernate-mapping>

    <class name="hibernate.Student" table="STUDENT">

        <id name="sid" type="int">

            <column name="SID" />

            <generator class="assigned" />

        </id>

        <property name="sname" type="java.lang.String">

            <column name="SNAME" />

        </property>

        <property name="gender" type="java.lang.String">

            <column name="GENDER" />

        </property>

        <property name="birthday" type="java.util.Date">

            <column name="BIRTHDAY" />

        </property>

        <property name="address" type="java.lang.String">

            <column name="ADDRESS" />

        </property>

    </class>

</hibernate-mapping>

这是测试类

package hibernate;


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 =new StandardServiceRegistryBuilder().applySettings(config.getProperties()).build();

//创建会话工厂对象

sessionFactory=config.buildSessionFactory(serviceRegistry);

//会话对象

session=sessionFactory.openSession();

//开启事物

transaction=session.beginTransaction();

}

@After

public void destroy(){

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

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

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

}

@Test

public void testSaveStudent(){

Student s=new Student(1,"张三","男",new Date(),"丽水");

session.save(s);

}


}

控制台报错代码

三月 18, 2017 11:16:10 下午 org.hibernate.Version logVersion

INFO: HHH000412: Hibernate Core {5.2.9.Final}

三月 18, 2017 11:16:10 下午 org.hibernate.cfg.Environment <clinit>

INFO: HHH000206: hibernate.properties not found

三月 18, 2017 11:16:12 下午 org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>

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

三月 18, 2017 11:16:12 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure

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

三月 18, 2017 11:16:12 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator

INFO: HHH10001005: using driver [null] at URL [jdbc:mysql://localhost:3306/webases]

三月 18, 2017 11:16:12 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator

INFO: HHH10001001: Connection properties: {driver_name=com.mysql.jdbc.Driver, user=root, password=****}

三月 18, 2017 11:16:12 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator

INFO: HHH10001003: Autocommit mode: false

三月 18, 2017 11:16:12 下午 org.hibernate.engine.jdbc.connections.internal.PooledConnections <init>

INFO: HHH000115: Hibernate connection pool size: 20 (min=1)


好好认真学习
浏览 3237回答 2
2回答

浮生半夏1

WARN: HHH10001002: Using Hibernate built-in connection pool (not for production use!)这行是连接池报错,我这节课的代码没出现这个问题,但是在strut2和hibernate整合中出现了,请问您解决了吗

慕运维8547243

解决了吗?我也是这个问题,代码没错。。就是运行到这一步就不动了
随时随地看视频慕课网APP

相关分类

Java
我要回答