Hi all,
first, sorry for my english, is not my native language, I will try to explain my problem.
my problem is that the data structure of Hibernate does not update correctly
I have a HibernateUtil class with this code.
Code:
public class HibernateUtil {
private static final SessionFactory sessionFactory = buildSessionFactory();
private static SessionFactory buildSessionFactory(){
try {
return new Configuration().configure(new File("hibernate.cfg.xml")).buildSessionFactory();
}catch(Exception ex){
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
}
with this class I use the sessionFactory global variable in all code
then I have a loop to do inserts on the DB, but the insertion is conditional.
I have an array with this structure [[year,value],.....] and this data
[
['2011','value1'],
['2010','value1'],
['2011','value1'],
.
.
.
.
.
]
then I try to insert these values on my DB, but before to insert I check if there is the year on my DB
Code:
//first verify if there is data on my DB
public Data ObtenerDatosDeData(String sYear){
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
Data objData = (Data)session.createQuery("select dt from datas as dt where dt.year=:dtrequestyear")
.setParameter("dtrequestyear", sYear)
.uniqueResult();
session.getTransaction().commit();
return objData;
}
this function always return an empty list for year 2011
why this happend??
how can I solve the problem??
thanks in advance for your help.
Quote:
added
I noticed something else.
if I insert data from another application (phpMyAdmin, other java app, ....)
the same problem occurs, it seems to me that get data from memory and not from the DB