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--
|