本文整理汇总了Java中org.hibernate.Session类的典型用法代码示例。如果您正苦于以下问题:Java Session类的具体用法?Java Session怎么用?Java Session使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Session类属于org.hibernate包,在下文中一共展示了Session类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getComposition
import org.hibernate.Session; //导入依赖的package包/类
@Override
public List<Integer> getComposition(int task_id) {
List<Integer> img_ids = new ArrayList<Integer>();
Session session = HibernateUtils.getSession();//生成Session实例
Transaction tx = session.beginTransaction();//生成事务实例
try {
img_ids = session.createQuery("SELECT img_id FROM Composition WHERE task_id = ?").setInteger(0, task_id).list();
tx.commit();//提交事务
} catch (Exception e) {
e.printStackTrace();
tx.rollback();
}finally {
HibernateUtils.closeSession();//关闭session实例
}
return img_ids;
}
示例2: deleteInterests
import org.hibernate.Session; //导入依赖的package包/类
@Override
public int deleteInterests(int user_id) {
Session session = HibernateUtils.getSession(); //生成session实例
Transaction tx = session.beginTransaction(); //创建transaction实例
int temp = 0;
try {
String hql = "delete from Interest where user_id = ?";
Query query = session.createQuery(hql);
query.setInteger(0, user_id);
temp = query.executeUpdate();
tx.commit(); //提交事务
} catch (Exception e) {
e.printStackTrace();
tx.rollback();
}finally {
HibernateUtils.closeSession(); //关闭Session实例
}
return temp;
}
示例3: createRoomUtilizationReportFor
import org.hibernate.Session; //导入依赖的package包/类
@Override
public void createRoomUtilizationReportFor(PointInTimeData pointInTimeData, Session hibSession) {
calculatePeriodsWithEnrollments(pointInTimeData, hibSession);
int minute = (startOnHalfHour ? 30 : 0);
for(Department department : depts) {
for(int dayOfWeek = 1 ; dayOfWeek < 8 ; dayOfWeek++) {
ArrayList<String> row = new ArrayList<String>();
row.add(department.getDeptCode());
row.add(department.getAbbreviation());
row.add(department.getName());
row.add(getDayOfWeekLabel(periodDayOfWeek(dayOfWeek)));
for(int hourOfDay = 0 ; hourOfDay < 24 ; hourOfDay++) {
String key = getPeriodTag(department.getUniqueId().toString(), dayOfWeek, hourOfDay, minute);
row.add(periodEnrollmentMap.get(key) == null ? "0": "" + periodEnrollmentMap.get(key).getWeeklyStudentEnrollment());
}
addDataRow(row);
}
}
}
示例4: main
import org.hibernate.Session; //导入依赖的package包/类
public static void main(String[] args) {
Configuration cfg=null;
SessionFactory factory=null;
Session ses=null;
Transaction tx=null;
cfg=new Configuration().configure("com/app/cfgs/hibernate.cfg.xml");
factory=cfg.buildSessionFactory();
ses=factory.openSession();
String hql="select item_name from bigbazarModel where bazarid=:id";
Query q=ses.createQuery(hql);
q.setParameter("id", 1001);
String s=(String) q.uniqueResult();
System.out.println("\t\t"+s);
factory.close();
}
开发者ID:pratikdimble,项目名称:Hibernate_HQL_UniqueResult_ExecuteUpdate_CopyData_Delete_Update,代码行数:19,代码来源:TestClass.java
示例5: findAllPitClassesWithContactHoursForDepartmentsAndSubjectAreas
import org.hibernate.Session; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private HashSet<PitClass> findAllPitClassesWithContactHoursForDepartmentsAndSubjectAreas(
PointInTimeData pointInTimeData, Session hibSession) {
HashSet<PitClass> pitClasses = new HashSet<PitClass>();
for(Long deptId : getDepartmentIds()) {
List<PitClass> pitClassesQueryResult = findAllPitClassesWithContactHoursForDepartment(pointInTimeData, deptId, hibSession);
for(PitClass pc : pitClassesQueryResult) {
if(pc.getPitSchedulingSubpart().getPitInstrOfferingConfig().getPitInstructionalOffering().getControllingPitCourseOffering().isIsControl().booleanValue()
&& getSubjectAreaIds().contains(pc.getPitSchedulingSubpart().getPitInstrOfferingConfig().getPitInstructionalOffering().getControllingPitCourseOffering().getSubjectArea().getUniqueId())) {
pitClasses.add(pc);
};
}
}
return(pitClasses);
}
示例6: enumerateAllIds
import org.hibernate.Session; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
@Transactional
public List<ID> enumerateAllIds()
{
return getHibernateTemplate().executeFind(new TLEHibernateCallback()
{
@Override
public Object doInHibernate(Session session) throws HibernateException
{
// NOTE: Don't order by name here - use NumberStringComparator
// on the returned list.
Query query = session.createQuery("select id from " + getPersistentClass().getName() //$NON-NLS-1$
+ " where institution = :institution"); //$NON-NLS-1$
query.setParameter("institution", CurrentInstitution.get()); //$NON-NLS-1$
query.setCacheable(true);
query.setReadOnly(true);
return query.list();
}
});
}
示例7: getCheckIns
import org.hibernate.Session; //导入依赖的package包/类
@Override
public List<CheckIn> getCheckIns(int user_id) {
List<CheckIn> checkIns=new ArrayList<CheckIn>();
Session session=HibernateUtils.getSession();//生成Session实例
Transaction tx=session.beginTransaction();//生成事务实例
try {
//select * from checkin where user_id=user_id order by checkin_time asc
checkIns= session.createCriteria(CheckIn.class).add(Restrictions.eq("user_id", user_id)).addOrder(Order.asc("checkin_time")).list();
tx.commit();//提交事务
} catch (Exception e) {
e.printStackTrace();
tx.rollback();
}finally {
HibernateUtils.closeSession();//关闭session实例
}
return checkIns;
}
示例8: delete
import org.hibernate.Session; //导入依赖的package包/类
@Override
public void delete (final FileScanner scanner)
{
getHibernateTemplate ().execute (new HibernateCallback<Void>()
{
@Override
public Void doInHibernate (Session session) throws HibernateException,
SQLException
{
String sql = "DELETE FROM FILE_SCANNER_PREFERENCES " +
"WHERE FILE_SCANNER_ID = ?";
SQLQuery query = session.createSQLQuery (sql);
query.setLong (0, scanner.getId ());
query.executeUpdate ();
return null;
}
});
super.delete (scanner);
}
示例9: findData
import org.hibernate.Session; //导入依赖的package包/类
@Override
public List<App> findData() {
Session session = null;
List<App> list = null;
try {
session = this.sessionFactory.openSession();
Query q = session.createQuery("from App app where app.hidden = false");
list = HibernateHelper.list(q);
// if (list != null) {
// logger.debug("in findData all .{} ", list.size());
// }
} catch (Exception e) {
logger.error("error:", e);
} finally {
session.close();
}
return list;
}
示例10: invoke
import org.hibernate.Session; //导入依赖的package包/类
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
SessionFactory sf = getSessionFactory();
if (!TransactionSynchronizationManager.hasResource(sf)) {
// New Session to be bound for the current method's scope...
Session session = openSession();
try {
TransactionSynchronizationManager.bindResource(sf, new SessionHolder(session));
return invocation.proceed();
}
finally {
SessionFactoryUtils.closeSession(session);
TransactionSynchronizationManager.unbindResource(sf);
}
}
else {
// Pre-bound Session found -> simply proceed.
return invocation.proceed();
}
}
示例11: moveToHistory
import org.hibernate.Session; //导入依赖的package包/类
public void moveToHistory(Step step, int actionId, Date finishDate, String status, String actor) throws WorkflowStoreException {
Session session = null;
try {
session = sessionFactory.openSession();
session.refresh(step);
super.markFinished(step, actionId, finishDate, status, actor);
update(session, step);
HibernateStep currentStep = (HibernateStep)step;
HibernateStep historyStep = new HibernateHistoryStep(currentStep);
HibernateProcessInstance entry = currentStep.getEntry();
entry.removeCurrentStep(currentStep);
entry.addHistoryStep(historyStep);
// Session transaction managed by the delete, save and update DAO methods
delete(session, currentStep);
save(session, historyStep);
update(session, entry);
if(logger.isDebugEnabled()) {
logger.debug(historyStep.toString());
logger.debug(entry.toString());
}
} catch(HibernateException hibernateException) {
throw new WorkflowStoreException(hibernateException);
} finally {
if (session != null)
session.close();
}
// Logging the results of this action
}
示例12: getMarkListByUserId
import org.hibernate.Session; //导入依赖的package包/类
@Override
public List<String> getMarkListByUserId(int user_id) {
List<String> accuracy = new ArrayList<String>();
Session session = HibernateUtils.getSession();//生成Session实例
Transaction tx = session.beginTransaction();//生成事务实例
try {
accuracy = session.createQuery("select mark_accuracy from Mark where user_id = ?").setInteger(0, user_id).list();
tx.commit();//提交事务
} catch (Exception e) {
e.printStackTrace();
tx.rollback();
}finally {
HibernateUtils.closeSession();//关闭session实例
}
return accuracy;
}
示例13: updateUserByAdmin
import org.hibernate.Session; //导入依赖的package包/类
@Override
public int updateUserByAdmin(User user){
Session session = HibernateUtils.getSession();
Transaction tx = session.beginTransaction();
int aa = 0;
try {
Query query = session.createQuery("update User u set u.username =?,u.sex = ?,u.integral=?,u.accuracy=? where u.user_id = ?");
query.setString(0, user.getUsername());
query.setString(1, user.getSex());
query.setInteger(2, user.getIntegral());
query.setString(3, user.getAccuracy());
query.setInteger(4, user.getUser_id());
aa = query.executeUpdate();
tx.commit();
} catch (Exception e) {
e.printStackTrace();
tx.rollback();
}finally {
HibernateUtils.closeSession();
}
return aa;
}
示例14: getAmountByCategoryId
import org.hibernate.Session; //导入依赖的package包/类
@Override
public int getAmountByCategoryId(int category_id) {
String sql = "SELECT COUNT(*) FROM image,image_category,category WHERE image.img_id = image_category.img_id AND category.category_id = image_category.category_id AND image.img_is_finish <>0 AND category.category_id = "+category_id;
Session session = HibernateUtils.getSession();//生成Session实例
Transaction tx = session.beginTransaction();//生成事务实例
int amount = 0;
try {
List arr = session.createSQLQuery(sql).list();
amount = Integer.parseInt(arr.get(0).toString());
tx.commit();//提交事务
} catch (Exception e) {
e.printStackTrace();
tx.rollback();
}finally {
HibernateUtils.closeSession();//关闭session实例
}
return amount;
}
示例15: execute
import org.hibernate.Session; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public Object execute(Context context) {
ProcessService processService=context.getProcessService();
ProcessInstanceQuery query=context.getProcessService().createProcessInstanceQuery();
query.processId(processDefinition.getId());
Session session=context.getSession();
for(ProcessInstance pi:query.list()){
processService.deleteProcessInstance(pi);
session.createQuery("delete "+Variable.class.getName()+" where processInstanceId=:processInstanceId").setLong("processInstanceId", pi.getId()).executeUpdate();
}
List<HistoryProcessInstance> hisInstances=session.createQuery("from "+HistoryProcessInstance.class.getName()+" where processId=:processId").setLong("processId", processDefinition.getId()).list();
for(HistoryProcessInstance instance:hisInstances){
session.createQuery("delete "+HistoryVariable.class.getName()+" where historyProcessInstanceId=:historyProcessInstanceId").setLong("historyProcessInstanceId", instance.getId()).executeUpdate();
}
session.createQuery("delete "+Blob.class.getName()+" where processId=:processId").setLong("processId", processDefinition.getId()).executeUpdate();
session.createQuery("delete "+HistoryProcessInstance.class.getName()+" where processId=:processId").setLong("processId", processDefinition.getId()).executeUpdate();
session.createQuery("delete "+HistoryTask.class.getName()+" where processId=:processId").setLong("processId", processDefinition.getId()).executeUpdate();
session.createQuery("delete "+HistoryActivity.class.getName()+" where processId=:processId").setLong("processId", processDefinition.getId()).executeUpdate();
session.delete(processDefinition);
return null;
}