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

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

為什么我使用session.openSession()得出來(lái)的連接對(duì)象的hashcode是相同的?我用的是hibernate5

package?junit;

import?java.sql.Connection;
import?java.sql.SQLException;
import?java.util.Date;

import?org.hibernate.Session;
import?org.hibernate.SessionFactory;
import?org.hibernate.Transaction;
import?org.hibernate.cfg.Configuration;
import?org.hibernate.jdbc.Work;
import?org.junit.Test;

import?com.model.Student;

public?class?SessionTest?{

	@Test
	public?void?test1(){
		Configuration?configure?=?new?Configuration().configure();
		SessionFactory?sessionFactory?=configure.buildSessionFactory();
		Session?session?=?sessionFactory.openSession();
		
		//System.out.println(session==session2);
		Transaction?trans=session.beginTransaction();
		session.doWork(new?Work()?{
			
			@Override
			public?void?execute(Connection?arg0)?throws?SQLException?{
				//?TODO?Auto-generated?method?stub
				System.out.println(arg0.hashCode());
			}
		});
		Student?s?=?new?Student(7,?"kkk",?new?Date(),?"上海");
		session.save(s);		
		trans.commit();		
		Session?session2?=?sessionFactory.openSession();
		trans=session2.beginTransaction();		
		session2.doWork(new?Work()?{
			@Override
			public?void?execute(Connection?arg0)?throws?SQLException?{
				//?TODO?Auto-generated?method?stub
				System.out.println(arg0.hashCode());
			}
		});
		s?=?new?Student(6,?"111",?new?Date(),?"上海");
		session2.save(s);		
		trans.commit();
		session.close();
		session2.close();
	}
}


正在回答

6 回答

你看看判斷狀態(tài),改變狀態(tài)的地方是不是有什么問(wèn)題嘞。

vvqigfidkgsjkhugwbbdxbidzphyjrrzrcmrtguhoevcd

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

理解是兩個(gè)不同對(duì)象就好,估計(jì)你也使用的Java 8

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

hashCode方法是Object的方法 ?你是可以在任何子類(lèi)里面復(fù)寫(xiě)的(java所有類(lèi)均繼承Object),如果手動(dòng)設(shè)置 ?return “1"那就會(huì)相同

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

我也使用的hibernate5也是這樣子,剛剛查了下Java中兩個(gè)不同對(duì)象的hashcode可能相同

connection hashcode:1968552224

Hibernate:?

? ? insert?

? ? into

? ? ? ? student

? ? ? ? (sname, gender, birthday, address, sid)?

? ? values

? ? ? ? (?, ?, ?, ?, ?)

connection hashcode:1968552224

false

Hibernate:?

? ? insert?

? ? into

? ? ? ? student

? ? ? ? (sname, gender, birthday, address, sid)?

? ? values

? ? ? ? (?, ?, ?, ?, ?)


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

因?yàn)槟泔@示的關(guān)閉了session會(huì)話(huà),如果你注釋掉,hashcode值就會(huì)不一樣了,這也就是老師一直在證明opensesion()為什么不會(huì)自動(dòng)關(guān)閉session會(huì)話(huà),getCurrentSession()能自動(dòng)關(guān)閉session會(huì)話(huà)了。我在評(píng)論區(qū)有具體說(shuō)明。你可以去看下

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

不小心按了一個(gè)截圖按鈕。

console輸出是這個(gè):

Hibernate:?

? ? drop table if exists STUDENT

Hibernate:?

? ? create table STUDENT (

? ? ? ? SID integer not null,

? ? ? ? SNAME varchar(255),

? ? ? ? BIRTHDAY datetime,

? ? ? ? ADDRESS varchar(255),

? ? ? ? primary key (SID)

? ? )

Jun 30, 2016 10:04:40 PM org.hibernate.tool.schema.internal.SchemaCreatorImpl applyImportSources

INFO: HHH000476: Executing import script 'org.hibernate.tool.schema.internal.exec.ScriptSourceInputNonExistentImpl@a7e2d9d'

1215029765

Hibernate:?

? ? insert?

? ? into

? ? ? ? STUDENT

? ? ? ? (SNAME, BIRTHDAY, ADDRESS, SID)?

? ? values

? ? ? ? (?, ?, ?, ?)

1215029765

Hibernate:?

? ? insert?

? ? into

? ? ? ? STUDENT

? ? ? ? (SNAME, BIRTHDAY, ADDRESS, SID)?

? ? values

? ? ? ? (?, ?, ?, ?)


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

舉報(bào)

0/150
提交
取消

為什么我使用session.openSession()得出來(lái)的連接對(duì)象的hashcode是相同的?我用的是hibernate5

我要回答 關(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)