-->
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.  [ 8 posts ] 
Author Message
 Post subject: Problem with sessions
PostPosted: Fri Oct 08, 2010 10:35 am 
Newbie

Joined: Fri Oct 08, 2010 10:32 am
Posts: 5
I am new on this and I didnt know where publish my question...

I have a problem trying to insert or update any table:

For Example: When I click on INSERT on my web page works fine, it inserts on the table and I can see those changes on the SGBD, but when I am navigating to see the changes, it keeps the old values of my table, I don`t know what is wrong with my connection or my session but I tried everything and it doesnt work... please can anybody help me?


Top
 Profile  
 
 Post subject: Re: Problem with sessions
PostPosted: Fri Oct 08, 2010 10:49 am 
Senior
Senior

Joined: Fri Oct 08, 2010 8:44 am
Posts: 130
Did you try "flush()" also? Do your application commit transaction after changes were done?


Top
 Profile  
 
 Post subject: Re: Problem with sessions
PostPosted: Fri Oct 08, 2010 11:07 am 
Newbie

Joined: Fri Oct 08, 2010 10:32 am
Posts: 5
yes, I have made it, and it works, it inserts on the table but when I try to show on my web page, it doesnt show me the results, I have to close my page and start again:
Here is the body of my HIBERNATE.cfg.xml:

<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/dbact</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">mypassword</property>
<property name="hibernate.current_session_context_class">thread</property>

<mapping class="dbgenerated.Table1" resource="dbgenerated/table1.hbm.xml"/>
<mapping class="dbgenerated.Table2" resource="dbgenerated/table2.hbm.xml"/>
...

and when I try to INSERT on a table, for example, I do this:

....
session = HibernateUtil.getSessionFactory().getCurrentSession();
Transaction Tx = session.beginTransaction();
try {
Tx.begin();
Table1 table1 = new Table1(parameter1, parameter2);
session.persist(table1);
session.flush();
Tx.commit();
} catch (HibernateException e) {
Tx.rollback();
}
.....

Can anybody figure out what is wrong???


Top
 Profile  
 
 Post subject: Re: Problem with sessions
PostPosted: Fri Oct 08, 2010 11:09 am 
Newbie

Joined: Fri Oct 08, 2010 10:32 am
Posts: 5
I dont know if this is the problem but the HIBERNATEUTIL is declared as Static:

public class HibernateUtil {
private static final SessionFactory sessionFactory;

static {
try {
sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
} catch (Throwable ex) {
throw new ExceptionInInitializerError(ex);
}
}

public static SessionFactory getSessionFactory() {
return sessionFactory;
}
}


Top
 Profile  
 
 Post subject: Re: Problem with sessions
PostPosted: Mon Oct 11, 2010 8:27 am 
Senior
Senior

Joined: Fri Oct 08, 2010 8:44 am
Posts: 130
Could you post some details on how you actually fetch the data from the database?


Top
 Profile  
 
 Post subject: Re: Problem with sessions
PostPosted: Mon Oct 11, 2010 3:06 pm 
Newbie

Joined: Fri Oct 08, 2010 10:32 am
Posts: 5
public List<Table1> GetFromTable1() {
session = HibernateUtil.getSessionFactory().getCurrentSession();
Transaction Tx = session.beginTransaction();
List<Table1> result = (List<Table1>) session.createQuery("from Table1").list();
return result;
}

thanks for trying to help!!!! you are great


Top
 Profile  
 
 Post subject: Re: Problem with sessions
PostPosted: Tue Oct 19, 2010 10:14 am 
Senior
Senior

Joined: Fri Oct 08, 2010 8:44 am
Posts: 130
jcortez wrote:
public List<Table1> GetFromTable1() {
session = HibernateUtil.getSessionFactory().getCurrentSession();
Transaction Tx = session.beginTransaction();
List<Table1> result = (List<Table1>) session.createQuery("from Table1").list();
return result;
}

thanks for trying to help!!!! you are great


Everything looks correct (you do not release transaction properly here, but it should not give such effects anyway). My guess would be that "GetFromTable1" method is not called for the second time. Do you get proper result if you restart your web-application after database update?


Top
 Profile  
 
 Post subject: Re: Problem with sessions
PostPosted: Thu Oct 21, 2010 2:44 pm 
Newbie

Joined: Fri Oct 08, 2010 10:32 am
Posts: 5
Quote:
Do you get proper result if you restart your web-application after database update?


Yes, when I restart my server services works fine, I mean I have to restart glassfish service to work again, but everytime I make a change, the changes are not shown, for example, I am navigating around my table with a button called "NEXT" on my app and when I make a change (Insert or update) it shows the previous values, but if I continue randomly shows the changes that I made, so I go to the db, and I realize that the changes are made...

Another problem that I have, I dont know if it is consequence of that but every 60 seconds my web app restart automatically, it restart to the login page and I have to enter my values again...

thanks for the help...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 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.