第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

我的junit4測(cè)試出錯(cuò) !

import java.util.Date;


import org.hibernate.Session;

import org.hibernate.SessionFactory;

import org.hibernate.Transaction;

import org.hibernate.boot.MetadataSources;

import org.hibernate.boot.registry.StandardServiceRegistry;

import org.hibernate.boot.registry.StandardServiceRegistryBuilder;

import org.junit.After;

import org.junit.Before;

import org.junit.Test;


public class StudentsTest {

private SessionFactory sessionFactory;

private Session session;

@Before

public void init(){

// A SessionFactory is set up once for an application!

StandardServiceRegistry registry = new StandardServiceRegistryBuilder()

.configure() // configures settings from hibernate.cfg.xml

.build();

try {

sessionFactory = new MetadataSources( registry ).buildMetadata().buildSessionFactory();

}

catch (Exception e) {

// The registry would be destroyed by the SessionFactory, but we had trouble building the SessionFactory

// so destroy it manually.

StandardServiceRegistryBuilder.destroy( registry );

System.out.println("sessionFactory");

}

? ?

? ?session=sessionFactory.openSession(); ? ?

? ?session.beginTransaction();

? ?

}

@After

public void destory(){

session.getTransaction().commit();

session.close();

sessionFactory.close();

}

@Test

public void testSaveStudents(){

Students students=new Students(2,"張三豐","男",new Date(),"武當(dāng)山");

session.save(students);

}


}


為什么我這個(gè)代碼老是提示空指針異常呢?

提示session找不著??!


<?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="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>

? ? ? ? <property name="hibernate.connection.password">123456</property>

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

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

? ? ? ? ?<property name="dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>?


? ? ? ??

? ? ? ? <property name="hibernate.show_sql">true</property>

? ? ? ? <property name="hibernate.format_sql">true</property>

? ? ? ? <property name="hibernate.hbm2ddl.auto">update</property>

? ? ? ? ??

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

? ? ? ??

? ? ? ? <mapping class="http://Students.hbm.xml"/>

? ? ?

? ? </session-factory>

</hibernate-configuration>


<?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-2-20 15:36:28 by Hibernate Tools 3.5.0.Final -->

<hibernate-mapping>

? ? <class name="Students" table="STUDENTS">

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


import java.util.Date;


import javax.persistence.Entity;

import javax.persistence.Table;



@Entity

@Table( name = "Students" )

public class Students {


? ? ? ?private int sid;

? ? ? ?private String sname;

? ? ? ?private String gender;

? private Date birthday;

? ? ? ?private String address;

public Students(){

}



public Students(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 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;

}



@Override

public String toString() {

return "Students [sid=" + sid + ", sname=" + sname + ", gender=" + gender + ", birthday=" + birthday

+ ", address=" + address + "]";

}

}


正在回答

2 回答

我的版本是5.2的,我在hibernate官網(wǎng)上看到的這個(gè)穿件session的方法,但是不知道為什么會(huì)出錯(cuò)?

0 回復(fù) 有任何疑惑可以回復(fù)我~

是不是因?yàn)閔ibernate版本高了,那個(gè)創(chuàng)建session語(yǔ)句不對(duì)

0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消

我的junit4測(cè)試出錯(cuò) !

我要回答 關(guān)注問(wèn)題
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)