本文整理汇总了Java中org.hibernate.Session.getTransaction方法的典型用法代码示例。如果您正苦于以下问题:Java Session.getTransaction方法的具体用法?Java Session.getTransaction怎么用?Java Session.getTransaction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.hibernate.Session
的用法示例。
在下文中一共展示了Session.getTransaction方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: beginTransaction
import org.hibernate.Session; //导入方法依赖的package包/类
/**
* Begin the transaction related to the session
*/
public Transaction beginTransaction(Session s) {
// already in a transaction, do not create a new one
if (s.getTransaction() != null && s.getTransaction().isActive()) return null;
return s.beginTransaction();
}
示例2: unassign
import org.hibernate.Session; //导入方法依赖的package包/类
public String unassign(String managerExternalId, Session hibSession) {
Transaction tx = null;
try {
if (hibSession.getTransaction()==null || !hibSession.getTransaction().isActive())
tx = hibSession.beginTransaction();
ExamAssignment oldAssignment = new ExamAssignment(this);
setAssignedPeriod(null);
if (getAssignedRooms()==null) setAssignedRooms(new HashSet());
getAssignedRooms().clear();
setAssignedPreference(null);
HashSet otherExams = new HashSet();
for (Iterator j=getConflicts().iterator();j.hasNext();) {
ExamConflict conf = (ExamConflict)j.next();
for (Iterator i=conf.getExams().iterator();i.hasNext();) {
Exam x = (Exam)i.next();
if (!x.equals(this)) {
x.getConflicts().remove(conf);
otherExams.add(x);
}
}
hibSession.delete(conf);
j.remove();
}
ExamEvent event = getEvent();
if (event!=null) hibSession.delete(event);
hibSession.update(this);
for (Iterator i=otherExams.iterator();i.hasNext();)
hibSession.update((Exam)i.next());
SubjectArea subject = null;
Department dept = null;
for (Iterator i=new TreeSet(getOwners()).iterator();i.hasNext();) {
ExamOwner owner = (ExamOwner)i.next();
subject = owner.getCourse().getSubjectArea();
dept = subject.getDepartment();
break;
}
ChangeLog.addChange(hibSession,
TimetableManager.findByExternalId(managerExternalId),
getSession(),
this,
getName()+" ("+
(oldAssignment.getPeriod()==null?"N/A":oldAssignment.getPeriodAbbreviation()+" "+oldAssignment.getRoomsName(", "))+
" → N/A)",
ChangeLog.Source.EXAM_INFO,
ChangeLog.Operation.UNASSIGN,
subject,
dept);
if (tx!=null) tx.commit();
return null;
} catch (Exception e) {
if (tx!=null) tx.rollback();
e.printStackTrace();
return "Unassignment of "+getName()+" failed, reason: "+e.getMessage();
}
}