These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: update issue
PostPosted: Sat Apr 14, 2007 3:01 pm 
Newbie

Joined: Sun Jan 01, 2006 7:57 am
Posts: 8
Hibernate version:
3.1

Hello, I have a problem with getting the most recent data from database...


So the problem:

I load the jsf page, I get the list of my persons...
Now I add an employee. And when I come back to see the changes of my list, I have there and indicator that the person is an employee,
and this indicator(bool) is right after the saving proces is true but is I refresh the list againn the indicator is then false,
and it is changing like Im refreshing the list from true to false but in the database is always true...
I was debuging and this
return crit.list();
just returned wrong list, like it would be return the old list...
So the problem is why it is not returning the update list???



this is my method for getting persons ...

public Collection<T> findByExample(T exampleInstance, String order ,Boolean asc) {
Criteria crit = getSession().createCriteria(getPersistentClass()).add(
Example.create(exampleInstance));
if(asc) {
crit.addOrder(Order.asc(order));
}else {
crit.addOrder(Order.desc(order));
}
return crit.list();
}

this method is called everytime from facade object when I refresh(by ajax) the page:

public ArrayList<Osoba> getAllPersonByCharacters(Short what) {
ArrayList<Osoba> temp = new ArrayList<Osoba>();
Osoba person = new Osoba();

if(what == null) {
return temp;
}

if(what == MainFacade.CLIENTS ) {
person.setJeKlient(true);
}
if(what == MainFacade.MEMBERS) {
person.setJeClen(true);
}
if(what == MainFacade.EMPLOYEES) {
person.setJeZamestnanec(true);
}
if(what == MainFacade.VOLUNTEERS) {
person.setJeDobrovolnik(true);
}
if(what == MainFacade.NOT_CLIENTS) {
person.setJeKlient(false);
}
if(what == MainFacade.NOT_MEMBERS) {
person.setJeClen(false);
}
if(what == MainFacade.NOT_EMPLOYEES) {
person.setJeZamestnanec(false);
}
if(what == MainFacade.NOT_VOLUNTEERS) {
person.setJeZamestnanec(true);
person.setJeDobrovolnik(false);
}

temp.addAll(getDAOFactory().getPersonFactory().getOsobaDAO().findByExample(person,"priezvisko",true));
return temp;
}

here is the method for the collection of my table tag from my jsf page...

public ArrayList<Osoba> getPersons() {
return getFacadeFactory().getPersonFacade().getAllPersonByCharacters(getOperation_id());
}


and finaly the saving process:

public String save(){
try {
Osoba person = (Osoba)getHTTPSession().getAttribute("_session_current_person");
getFacadeFactory().getEmployeeFacade().save(this,person);
getHTTPSession().setAttribute("_saved","employee_l");
getHTTPSession().setAttribute("_clear","employee");
return "employee_saved";
} catch (BusinessException e) {
return "employee_not_saved";
}
}

public void save(EmployeeBean eb, Osoba person) {
try {
beginTransaction();
Zamestnanec employee = new Zamestnanec();
ObjectHelper.setAttributesFromGetterToSetter(employee,eb,new String[] {"kvalifikacia","skolenieExt"});

employee.setOddeleniaId(getDAOFactory().getEmployeeFactory().getCOddelenieDAO().getById(eb.getJobDepartmentValue()));
employee.setNastupyId(getDAOFactory().getEmployeeFactory().getCNastupDAO().getById(eb.getJobGettingInValue()));
employee.setPracVztahyId(getDAOFactory().getEmployeeFactory().getCPracVztahDAO().getById(eb.getWorkingRelationsValue()));
employee.setPozicieId(getDAOFactory().getEmployeeFactory().getCPoziciaDAO().getById(eb.getJobPositionValue()));
employee.setFunkcieZamId(getDAOFactory().getEmployeeFactory().getCFunkciaZamDAO().getById(eb.getJobFunctionValue()));
employee.setCSkolenieIntMany(setJobInternTraining(eb.getJobInternTrainingValues()));
employee.setVystupyId(getDAOFactory().getEmployeeFactory().getCVystupDAO().getById(eb.getJobGettingOutValue()));
employee.setVzdelanieZamId(getDAOFactory().getClientMemberFactory().getCVzdelanieDAO().getById(eb.getEducationTypesValue()));
employee.setdVzdelanieZamId(getDAOFactory().getClientMemberFactory().getCDruhVzdelanieDAO().getById(eb.getSortOfEducationTypesValue()));
employee.setZamestnanecId(person);
employee.setDobrovolnik(false);

person.setZamestnanecId(employee);
person.setJeZamestnanec(true);

saveToDB(employee);

commitTransaction();
closeSession();

} catch (Exception e) {
rollbackTransaction();
throw new BusinessException();
}
}


And the methods fro hibernate are:
public class MainFacade extends MainControlClass {

public static final short CLIENTS = 1;
public static final short MEMBERS = 2;
public static final short EMPLOYEES = 3;
public static final short VOLUNTEERS = 4;

public static final short NOT_CLIENTS = 5;
public static final short NOT_MEMBERS = 6;
public static final short NOT_EMPLOYEES = 7;
public static final short NOT_VOLUNTEERS = 8;

public static final short NOT_PERSON = 20;

public Session getSession () {
return HibernateUtil.getSession();
}
public static void closeSession (){
HibernateUtil.closeSession();
}
public static void beginTransaction () {
HibernateUtil.beginTransaction();
}
public static void commitTransaction () {
HibernateUtil.commitTransaction();
}
public static void rollbackTransaction () {
HibernateUtil.rollbackTransaction();
}

public Object saveToDB(Object entity) {
getSession().save(entity);
return entity;
}

public Object updateInDB(Object entity) {
getSession().saveOrUpdate(entity);
return entity;
}

public void deleteFromDB(Object entity) {
getSession().delete(entity);
}

public void flushDB() {
getSession().flush();
}


public static void clearBeanInfo(String bean) {
FacesContext facesContext = FacesContext.getCurrentInstance();
ValueBinding valueBinding = facesContext.getApplication().createValueBinding("#{"+bean+"}");
valueBinding.setValue(facesContext,null);
}

public static Object getBean(String bean) {
FacesContext facesContext = FacesContext.getCurrentInstance();
ValueBinding valueBinding = facesContext.getApplication().createValueBinding("#{"+bean+"}");
return valueBinding.getValue(facesContext);
}
}

_________________
--johnypt--


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 14, 2007 9:29 pm 
Senior
Senior

Joined: Tue Mar 09, 2004 2:38 pm
Posts: 141
Location: Lowell, MA USA
Have you tested your Hibernate code outside of your Servlet to see you get the same problems? If not, you should try that before anything else so that way you can rule out if its a Hibernate issue or something else. Since you seem to be holding data in the HTTP Session, I suspect your issues doesn't lie in HIbernate, but something in your session management code.

If you're looking to gain better performance by storing data in the HTTP Session, you may want to consider Hibernates L2 cache. It's easier to configure and less error prone as HTTP session caching. It's also much less overhead as the cache can be shared across multiple client sessions.

Ryan-

_________________
Ryan J. McDonough
http://damnhandy.com

Please remember to rate!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.