日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

java hibernate 多对多_java - hibernate多对多问题

發(fā)布時(shí)間:2024/9/27 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java hibernate 多对多_java - hibernate多对多问题 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

映射文件如下:

sequence_stuid

sequence_teaid

@Test

public void testSave2() {

Configuration cfg = null;

ServiceRegistry sr = null;

SessionFactory sf = null;

Session session = null;

Transaction tx = null;

try {

cfg = new Configuration().configure("hibernate.cfg.xml");

sr = new StandardServiceRegistryBuilder().applySettings(cfg.getProperties()).build();

sf = cfg.buildSessionFactory(sr);

System.out.println("SessionFactory --> " + sf);

session = sf.openSession();

System.out.println("SESSION --> " + session);

tx = session.beginTransaction();

// 創(chuàng)建對象

Teacher t1 = new Teacher("韓老師");

Teacher t2 = new Teacher("王老師");

Student s1 = new Student("小明");

Student s2 = new Student("小藍(lán)");

// 建立關(guān)聯(lián)關(guān)系

t1.getStudentSet().add(s1);

t1.getStudentSet().add(s2);

t2.getStudentSet().add(s2);

s1.getTeacherSet().add(t1);

s2.getTeacherSet().add(t1);

s2.getTeacherSet().add(t2);

// 由主動方維護(hù)關(guān)聯(lián)關(guān)系 inverse="false"

session.save(s1);

session.save(s2);

tx.commit();

System.out.println("transaction commit.");

} catch (Exception e) {

tx.rollback();

System.out.println("transaction rollback.");

} finally {

if (session != null) session.close();

System.out.println("session closed.");

}

}

執(zhí)行以上方法時(shí)事務(wù)為什么不會提交?

下面是控制臺打印的信息

八月 22, 2015 6:49:48 下午 org.hibernate.annotations.common.reflection.java.JavaReflectionManager

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

八月 22, 2015 6:49:48 下午 org.hibernate.Version logVersion

INFO: HHH000412: Hibernate Core {4.3.10.Final}

八月 22, 2015 6:49:48 下午 org.hibernate.cfg.Environment

INFO: HHH000206: hibernate.properties not found

八月 22, 2015 6:49:48 下午 org.hibernate.cfg.Environment buildBytecodeProvider

INFO: HHH000021: Bytecode provider name : javassist

八月 22, 2015 6:49:48 下午 org.hibernate.cfg.Configuration configure

INFO: HHH000043: Configuring from resource: hibernate.cfg.xml

八月 22, 2015 6:49:48 下午 org.hibernate.cfg.Configuration getConfigurationInputStream

INFO: HHH000040: Configuration resource: hibernate.cfg.xml

八月 22, 2015 6:49:48 下午 org.hibernate.cfg.Configuration addResource

INFO: HHH000221: Reading mappings from resource: com/bdqn/entity/Student.hbm.xml

八月 22, 2015 6:49:48 下午 org.hibernate.cfg.Configuration addResource

INFO: HHH000221: Reading mappings from resource: com/bdqn/entity/Teacher.hbm.xml

八月 22, 2015 6:49:48 下午 org.hibernate.cfg.Configuration doConfigure

INFO: HHH000041: Configured SessionFactory: null

八月 22, 2015 6:49:48 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure

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

八月 22, 2015 6:49:48 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator

INFO: HHH000401: using driver [oracle.jdbc.OracleDriver] at URL [jdbc:oracle:thin:@localhost:1521:orcl]

八月 22, 2015 6:49:48 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator

INFO: HHH000046: Connection properties: {user=rolland, password=**}

八月 22, 2015 6:49:48 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator

INFO: HHH000006: Autocommit mode: false

八月 22, 2015 6:49:48 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure

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

八月 22, 2015 6:49:49 下午 org.hibernate.dialect.Dialect

INFO: HHH000400: Using dialect: org.hibernate.dialect.Oracle10gDialect

八月 22, 2015 6:49:49 下午 org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService

INFO: HHH000399: Using default transaction strategy (direct JDBC transactions)

八月 22, 2015 6:49:49 下午 org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory

INFO: HHH000397: Using ASTQueryTranslatorFactory

SessionFactory --> org.hibernate.internal.SessionFactoryImpl@52815fa3

SESSION --> SessionImpl(PersistenceContext[entityKeys=[],collectionKeys=[]];ActionQueue[insertions=org.hibernate.engine.spi.ExecutableList@5e403b4a updates=org.hibernate.engine.spi.ExecutableList@5117dd67 deletions=org.hibernate.engine.spi.ExecutableList@5be49b60 orphanRemovals=org.hibernate.engine.spi.ExecutableList@2931522b collectionCreations=org.hibernate.engine.spi.ExecutableList@7674b62c collectionRemovals=org.hibernate.engine.spi.ExecutableList@19e7a160 collectionUpdates=org.hibernate.engine.spi.ExecutableList@662706a7 collectionQueuedOps=org.hibernate.engine.spi.ExecutableList@45a4b042 unresolvedInsertDependencies=UnresolvedEntityInsertActions[]])

transaction rollback.

session closed.

總結(jié)

以上是生活随笔為你收集整理的java hibernate 多对多_java - hibernate多对多问题的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。