0

I am working on project which uses jsf 1.X and hibernate, where am new. We are using below code to update_

        Shift4DAO dao = Shift4DAO.getInstance();
        Session session = dao.createNewSession();
        Transaction transaction = null;
        try {
            transaction = session.beginTransaction();
            session.saveOrUpdate(shift4B);
            transaction.commit();
        } catch (final HibernateException e) {
            e.printStackTrace();
            if (transaction != null) {
                transaction.rollback();
            } 

How session.saveOrUpdate(shift4B); it is working(Flow)? where Shift4DAO.java

public class Shift4DAO extends BaseShift4DAO {

public Shift4DAO () {}
}

And Shift4.java

public class Shift4 extends BaseShift4 {
private static final long serialVersionUID = 1L;


public Shift4 () {
    super();
}


public Shift4 (java.lang.Integer id) {
    super(id);
}


public Shift4 (
    java.lang.Integer id,
    org.azureworlds.dao.Employee createdBy,
    org.azureworlds.dao.Employee lastUpdatedBy,
    org.azureworlds.dao.Reservation reservation) {

    super (
        id,
        createdBy,
        lastUpdatedBy,
        reservation);
}

}

I fail to understand how i get connect to update for updating data. is anybody can simplify this, where i need to check or how connecting to HB? Thank u!!!!

2
  • the question is not really clear. You showed code which probably works and ask how to do it? what is the problem Commented Nov 13, 2012 at 20:53
  • i am studing this code , but i didnt understand how data flows into this code, and how it connects to other code? Commented Nov 19, 2012 at 9:03

1 Answer 1

1

dao.createNewSession(); creates a hibernate session which encapsulates a database connection and implements the "Unit of Work" pattern. session.saveOrUpdate(shift4B); tells the session that shift4B should be created(INSERT) or updated depending on the state of the entity (new or changed).

Sign up to request clarification or add additional context in comments.

3 Comments

but how he finds its corresponding javaBean class and go to HBconfi?
in the hbm mapping there is the class specified which the mapping belongs to. Hibernate uses shift4B.class.Fullname to get the corresponding mapping and all it needs is defined there
tnx, and why we used DAO which is nothing,just have blank constructor? means when i do saveOrUpdate(obj) then it go for obj's class through HBM file?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.