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

為了賬號安全,請及時綁定郵箱和手機立即綁定

是不是導入的包錯了??

源碼:

import java.util.Date;

//import javax.transaction.Transaction;

import org.hibernate.Session;

import org.hibernate.SessionFactory;

import org.hibernate.Transaction;

import org.hibernate.cfg.Configuration;

import org.hibernate.service.ServiceRegistry;

import org.hibernate.service.ServiceRegistryBuilder;


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(){

//創(chuàng)建配置對象

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

? //創(chuàng)建服務注冊對象

//serviceRegistry serviceRegistry =new ServiceRegistryBuilder().applySettings(config.getProperty());

//這里有錯誤,轉(zhuǎn)換不了,用了強制轉(zhuǎn)換

ServiceRegistry serviceRegistry =new ServiceRegistryBuilder().applySettings(config.getProperties()).buildServiceRegistry();

? //創(chuàng)建會話工廠對象

sessionFactory =config.buildSessionFactory(serviceRegistry);

//會話對象

session = sessionFactory.openSession();

//開啟事務

? ? ? transaction = session.beginTransaction();

}

@After

public void destory(){

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

session.close(); ? ? //關閉會話

sessionFactory.close();//關閉會話工廠

}

@Test

public void testSaveStudents(){

? ?//生成學生對象

Students s = new Students(1,"張三豐","男",new Date(),"武當山");

session.save(s);//保存對象進入數(shù)據(jù)庫

}

}

報錯:


java.lang.Error: Unresolved compilation problems:?

Cannot instantiate the type Configuration

Syntax error, insert ";" to complete BlockStatements

SerceRegistry cannot be resolved to a type

The method getproperties() is undefined for the type Configuration

Syntax error, insert ":: IdentifierOrNew" to complete ReferenceExpression

Syntax error, insert ";" to complete Statement

b cannot be resolved or is not a field

Type mismatch: cannot convert from org.hibernate.Transaction to javax.transaction.Transaction


at StudentsTest.init(StudentsTest.java:23)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)

at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)

at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)

at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)

at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)

at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)

at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)

at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)

at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)

at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)

at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)

at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)

at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)

at org.junit.runners.ParentRunner.run(ParentRunner.java:300)

at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)

at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)


正在回答

1 回答

Transaction重新寫一下

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

舉報

0/150
提交
取消

是不是導入的包錯了??

我要回答 關注問題
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號