-->
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.  [ 9 posts ] 
Author Message
 Post subject: Data is not refreshing
PostPosted: Wed Feb 16, 2005 2:19 am 
Newbie

Joined: Wed Feb 16, 2005 2:10 am
Posts: 3
I have a problem with data not being refreshed. Let us say there are 5 records in the table and when I do findAll(), it returns 5 records as expected but when the hibernate application is running, I go to the database and add one more record manually, the hibernate application is not picking up the sixth record, it still picks up the first 5 only. I had to stop and start my app to get the latest data. why it is happening ?

here is the sample code

cld.createChannelList(form);
ChannelList[] cl = cld.findAll();
System.out.println("*** # records = "+cl.length);

Thread.sleep(30000);

cl = cld.findAll();
System.out.println("*** # records = "+cl.length);




----------------


public java.util.List findAll () throws HibernateException {
Session s = null;
try {
s = getSession();
return findAll(s);
}
finally {
closeSession(s);
}
}


protected java.util.List findAll (Session s) throws HibernateException {
return findAll(s, getDefaultOrderProperty());
}




protected java.util.List findAll (Session s, String orderProperty) throws HibernateException {

Criteria crit = s.createCriteria(getReferenceClass());
if (null != orderProperty) crit.addOrder(Order.asc(orderProperty));
return crit.list();
}


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 16, 2005 5:20 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
i guess you are running within a transaction and either t1 cannot see t2 committed items (isolation level issue) or t2 havent committed yet.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: got the same problem
PostPosted: Wed Feb 16, 2005 7:16 am 
Newbie

Joined: Wed Feb 16, 2005 7:11 am
Posts: 3
Here is my source code...

Loading records:

public Object execute(DatabaseLoadAction action)
{
Object obj = new Object();

Session session = null;

try {
session = sf.openSession();
} catch (HibernateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

Transaction tx = null;

try {

tx = session.beginTransaction();
obj = session.createQuery(action.execute()).list();


} catch (Exception e) {
e.printStackTrace();
}

finally {
try {
session.clear();
session.flush();
session.close();

} catch (Exception e) {
e.printStackTrace();
}

}



return obj;
}

Saving records:

public boolean execute(DatabaseSaveAction action)
{
boolean ret=false;

Session session = null;

try {
session = sf.openSession();
} catch (HibernateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

Transaction tx = null;

try {

tx = session.beginTransaction();
ret = action.execute(session);

tx.commit();

} catch (Exception e) {
e.printStackTrace();
if (tx != null){
try {
tx.rollback();
System.out.println("Rollback Save Database Action ");
} catch (Exception exc) {
exc.printStackTrace();
}
}
}

finally {
try {
session.clear();
session.flush();
session.close();


} catch (Exception e) {
e.printStackTrace();
}

}
return ret;

}

But no refreshing :-(

can anybody help me???


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 16, 2005 7:20 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
eh no ...because you dont show where you have a "missing refresh" and you dont show how you add your objects...

you said something about performing inserts in a tool....did that tool commit ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 16, 2005 7:37 am 
Newbie

Joined: Wed Feb 16, 2005 2:10 am
Posts: 3
when you are updating the table from some other process (not hibernate), then my hibernate session is not reloading the data. I guess

I need to do this

Query setForceCacheRefresh(boolean forceCacheRefresh)
Should the query force a refresh of the specified query cache region? This is particularly useful in cases where underlying data may have been updated via a seperate process (i.e., not modified through Hibernate) and allows the application to selectively refresh the query cache regions based on its knowledge of those events.

how do I set this to true from config files ? not from the session code.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 16, 2005 8:29 am 
Newbie

Joined: Wed Feb 16, 2005 7:11 am
Posts: 3
I save the project this way:

Project project = new Project("test");
DatabaseController.getInstance().execute(new SaveProject(project));

I'll try to get it in the next line:

Collection projects = (Collection) db.execute(new GetProjectByID(id));

for (Iterator iter = projects.iterator(); iter.hasNext();)
{
Project element = (Project) iter.next();
logger.info(project.getName());
}


But the test-projet isn't there


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 16, 2005 8:35 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
if this is in two different sessions/transactions then they wont be able to see each other when

1: transaction isolation prevents it (basic jdbc db stuff)
2: transaction havent been flushed/commited yet and isolation level allows you to read committed.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 16, 2005 9:27 am 
Newbie

Joined: Wed Feb 16, 2005 7:11 am
Posts: 3
i enabled the isolation level and set it to TRANSACTION_SERIALIZABLE
(8) => the problem doesn't occur anymore

thx a lot


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 16, 2005 9:32 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
serializable is a *bad* mode for most things ,)

read_committed would be better.

_________________
Max
Don't forget to rate


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