org.hibernate.classic.Session.beginTransaction()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(4.7k)|赞(0)|评价(0)|浏览(214)

本文整理了Java中org.hibernate.classic.Session.beginTransaction()方法的一些代码示例,展示了Session.beginTransaction()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Session.beginTransaction()方法的具体详情如下:
包路径:org.hibernate.classic.Session
类名称:Session
方法名:beginTransaction

Session.beginTransaction介绍

暂无

代码示例

代码示例来源:origin: org.jasig.portlet.utils/portlet-mvc-util

public static void main(String[] args) throws Exception
{
  String dir = args[0];
  String importExportContext = args[1];
  String sessionFactoryBeanName = args[2];
  String modelClassName = args[3];
  String serviceBeanName = args[4];
  String serviceBeanMethodName = args[5];
  ApplicationContext context = PortletApplicationContextLocator.getApplicationContext(importExportContext);
  SessionFactory sessionFactory = context.getBean(sessionFactoryBeanName, SessionFactory.class);
  Class<?> modelClass = Class.forName(modelClassName);
  Object service = context.getBean(serviceBeanName);
  JAXBContext jc = JAXBContext.newInstance(modelClass);
  File folder = new File(dir);
  File[] files = folder.listFiles(new ImportFileFilter());
  for(File f : files) {
    StreamSource xml = new StreamSource(f.getAbsoluteFile());
    Unmarshaller unmarshaller = jc.createUnmarshaller();
    JAXBElement je1 = unmarshaller.unmarshal(xml, modelClass);
    Object object = je1.getValue();
    Session session = sessionFactory.getCurrentSession();
    Transaction transaction = session.beginTransaction();
    Method method = service.getClass().getMethod(serviceBeanMethodName,modelClass);
    method.invoke(service,object);
    transaction.commit();
  }
}

代码示例来源:origin: org.jasig.portlet.utils/portlet-mvc-util

Transaction transaction = session.beginTransaction();

代码示例来源:origin: com.lohika.alp/alp-reporter

/**
 * Create TestClass by classname.
 *
 * @param className the class name
 * @return the test class
 */
protected TestClass getTestClass(String className) {
  Session session = factory.openSession();
  Transaction tx = null;
  try {
    tx = session.beginTransaction();
    
    List<TestClass> list = session.createCriteria(TestClass.class)
        .add(Expression.eq("name", className)).list();
    tx.commit();
    if (list.size() == 0)
      return null;
    else
      return list.get(0);
  } finally {
    session.close();
  }
}

代码示例来源:origin: com.lohika.alp/alp-reporter

/**
 * Update Hibernate persistent object.
 *
 * @param object to update
 */
protected void updateObject(Object obj) {
  Session session = factory.openSession();
  Transaction tx = null;
  try {
    tx = session.beginTransaction();
    session.update(obj);
    tx.commit();
  } catch (Exception e) {
    if (tx != null)
      tx.rollback();
  } finally {
    session.close();
  }
}

代码示例来源:origin: com.lohika.alp/alp-reporter

/**
 * Save Hibernate persistent object.
 *
 * @param object to save
 */
protected void saveObject(Object obj) {
  Session session = factory.openSession();
  Transaction tx = null;
  try {
    tx = session.beginTransaction();
    session.save(obj);
    tx.commit();
  } catch (Exception e) {
    if (tx != null)
      tx.rollback();
  } finally {
    session.close();
  }
}

代码示例来源:origin: net.sourceforge.wicketwebbeans.databinder/wicketwebbeans-databinder

public void delete(AjaxRequestTarget target, Form form, Object bean)
{
  // confirm message shown by wwb. If we get here we do a delete
  Session session = DataStaticService.getHibernateSession();
  session.beginTransaction();
  session.delete(bean);
  session.getTransaction().commit();
  if (target != null) // ajax request
    target.addComponent(panel);
}

代码示例来源:origin: caelum/caelum-stella

private static void save(Modelo modelo) {
    Session session = HibernateUtil.getSessionFactory().openSession();
    session.beginTransaction();
    ModeloDAO dao = new ModeloDAO(session);
    try {
      dao.save(modelo);
      System.out.println("Modelo válido: " + modelo);
      session.getTransaction().commit();
    } catch (ConstraintViolationException e) {
      System.out.println("Modelo inválido: " + modelo);
      System.out
          .println("Listagem das mensagens de validação (obtidas do arquivo ValidatorMessages.properties):");
      for (ConstraintViolation<?> violation : e.getConstraintViolations()) {
        System.out.println("\t" + violation.getMessage());
      }
      session.getTransaction().rollback();
    } finally {
      session.close();
    }
  }
}

代码示例来源:origin: com.lohika.alp/alp-reporter

/**
 * Save log.
 *
 * @param methodResult the method result
 * @param testMethod the test method
 */
private void saveLog(ITestResult methodResult, TestMethod testMethod) {
  // TODO Use saveLog with client of results web services
  File logFile = LogFileAttribute.getLogFile(methodResult);
  List<File> attachments = LogFileAttachmentAttribute
      .getAttachmentFiles(methodResult);
  if (logFile != null) {
    Session session = factory.openSession();
    session.beginTransaction();
    try {
      long id = testMethod.getId();
      logUploader.upload(id, logFile);
      // Upload attachments
      if (attachments != null) {
        for (File attachment : attachments) {
          logUploader.upload(id, attachment);
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      session.close();
    }
  }
}

代码示例来源:origin: net.sourceforge.wicketwebbeans.databinder/wicketwebbeans-databinder

DataStaticService.getHibernateSession().beginTransaction();
metaData = new BeanMetaData(beanClass, null, this, null, true);
Label label = new Label("label", new Model(metaData.getParameter("label")));

相关文章