Example usage for org.hibernate Session save

List of usage examples for org.hibernate Session save

Introduction

In this page you can find the example usage for org.hibernate Session save.

Prototype

Serializable save(Object object);

Source Link

Document

Persist the given transient instance, first assigning a generated identifier.

Usage

From source file:au.org.theark.study.model.dao.StudyDao.java

License:Open Source License

public void updateSubject(SubjectVO subjectVO) throws ArkUniqueException {
    Session session = getSession();

    Person person = subjectVO.getLinkSubjectStudy().getPerson();
    String currentLastNameFromDB = getCurrentLastnameFromDB(person);// may need to test this effect of a reget

    session.update(person);// Update Person and associated Phones

    PersonLastnameHistory personLastNameHistory = null;

    if (currentLastNameFromDB != null && !currentLastNameFromDB.isEmpty()
            && !currentLastNameFromDB.equalsIgnoreCase(person.getLastName())) {
        if (person.getLastName() != null) {
            personLastNameHistory = new PersonLastnameHistory();
            personLastNameHistory.setPerson(person);
            personLastNameHistory.setLastName(currentLastNameFromDB);
            session.save(personLastNameHistory);
        }//from ww w  .j  a va2s .c  o m
    }

    // Update subjectPreviousLastname
    if (personLastNameHistory != null) {
        subjectVO.setSubjectPreviousLastname(getPreviousLastname(person));
    }

    LinkSubjectStudy linkSubjectStudy = subjectVO.getLinkSubjectStudy();
    session.merge(linkSubjectStudy);
}

From source file:au.org.theark.study.model.dao.StudyDao.java

License:Open Source License

public void create(Address address) throws ArkSystemException {
    Session session = getSession();
    session.save(address);
}

From source file:au.org.theark.study.model.dao.StudyDao.java

License:Open Source License

public void create(OtherID otherID) throws ArkSystemException {
    Session session = getSession();
    session.save(otherID);
}

From source file:au.org.theark.study.model.dao.StudyDao.java

License:Open Source License

public void create(Consent consent) throws ArkSystemException {
    try {//w ww  .ja  v a2  s  .co  m
        Session session = getSession();
        session.save(consent);

    } catch (HibernateException hibException) {
        log.error("An exception occured while creating a consent " + hibException.getStackTrace());
        throw new ArkSystemException("Could not create the consent.");
    }
}

From source file:au.org.theark.study.model.dao.StudyDao.java

License:Open Source License

/**
 * This is a lean version of CreateSubject. Here we basically copy the details of the existing subject and link it to the new study. The person
 * object will still remain same and is not duplicated.There is no generation of SubjectUID as it is inherited from the existing subject details of
 * the main study./*from ww w  .j  a  va  2  s. c  om*/
 */
public void cloneSubjectForSubStudy(LinkSubjectStudy linkSubjectStudy) {
    // Add Business Validations here as well apart from UI validation
    if (!linkSubjectStudyExists(linkSubjectStudy)) {
        Session session = getSession();
        session.save(linkSubjectStudy);
        autoConsentLinkSubjectStudy(linkSubjectStudy);
    }
}

From source file:au.org.theark.study.model.dao.StudyDao.java

License:Open Source License

@Override
public void processFieldsBatch(List<? extends ICustomFieldData> fieldsToUpdate, Study study,
        List<? extends ICustomFieldData> fieldsToInsert) {
    Session session = getSession();
    int count = 0;
    for (ICustomFieldData dataToUpdate : fieldsToUpdate) {
        session.update(dataToUpdate);/* w ww.j  a va2 s . c o  m*/
        count++;
        // based on recommended hibernate practice of <prop key="hibernate.jdbc.batch_size">50</prop>
        if (count % 50 == 0) {
            log.info("\n\n\n\n\n\n\n\n\nflush!!!!!!!!!!!!!!"); // TODO Evaluate why batch not working. hints: may be identity/id generation related.
                                                               // Will revisit after all batch work done
            session.flush();
            session.clear();
        }
    }
    count = 0;
    for (ICustomFieldData dataToInsert : fieldsToInsert) {
        session.save(dataToInsert);
        count++;
        // based on recommended hibernate practice of <prop key="hibernate.jdbc.batch_size">50</prop>
        if (count % 50 == 0) {
            log.info("\n\n\n\n\n\n\n\n\nflush!!!!!!!!!!!!!!");
            session.flush();
            session.clear();
        }
    }
    session.flush();
    session.clear();
}

From source file:autoancillarieslimited.hiberate.dao.AbstractDao.java

@Override
public boolean insert(T object) {
    Session session = null;
    Transaction beginTransaction = null;
    try {//from w w w .jav  a2s . c  o m
        session = HibernateUtil.getSessionFactory().openSession();
        beginTransaction = session.beginTransaction();
        session.save(object);
        beginTransaction.commit();
    } catch (HibernateException ex) {
        ex.printStackTrace();
        if (beginTransaction != null) {
            beginTransaction.rollback();
        }
    } finally {
        if (session != null) {
            session.close();
        }
    }
    return true;
}

From source file:backend.api.FinanceManagement.java

public boolean addUser(Users user) // ok
{
    Session s = sf.openSession();
    try {/*w  ww . j a v a2 s  .  c o m*/
        Transaction tx = s.beginTransaction();

        try {
            s.save(user);

            tx.commit();
            return true;
        } catch (Exception e) {
            tx.rollback();
            return false;
        }
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    } finally {
        s.close();

    }
}

From source file:backend.api.FinanceManagement.java

public boolean addFinanceRegisterRecord(FinanceRegister fr) //ok
{
    Session s = SessionFactoryManager.INSTANCE.getSessionFactory().openSession();
    try {//from  w w w  . ja  va2s .  com
        Transaction tx = s.beginTransaction();

        try {
            s.save(fr);

            tx.commit();
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            tx.rollback();
            return false;
        }

    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }

    finally {
        s.close();
    }
}

From source file:backend.api.Statistics.java

public boolean addFinanceRegisterRecord(FinanceRegister fr) // ok
{
    Session s = sf.openSession();
    try {/*w ww. ja  v  a 2 s. c  om*/
        Transaction tx = s.beginTransaction();

        try {
            s.save(fr);

            tx.commit();
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            tx.rollback();
            return false;
        }
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    } finally {
        s.close();
    }
}