-->
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: Unable to load the most recently saved object
PostPosted: Tue Nov 09, 2004 1:00 pm 
Newbie

Joined: Tue Nov 09, 2004 12:29 pm
Posts: 1
Hibernate version:
3.0alpha

Mapping files:

<hibernate-configuration>
<session-factory name="Test">
<property name="show_sql">true</property>
<property name="max_fetch_depth">0</property>
<property name="jdbc.batch_versioned_data">true</property>
<property name="jdbc.use_streams_for_binary">true</property>
<property name="proxool.pool_alias">pool1</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://192.168.0.151/c2iedm_adam</property>
<property name="connection.username">root</property>
<property name="connection.pool_size">1</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.cache.use_query_cache">false</property>
<mapping resource="com/acs/crom/OrgActionAssociation.hbm.xml"/>
<mapping resource="com/acs/crom/Action.hbm.xml"/>
<mapping resource="com/acs/crom/ActionTask.hbm.xml"/>
<mapping resource="com/acs/bml/Event.hbm.xml"/>
<mapping resource="com/acs/bml/Activity.hbm.xml"/>
<mapping resource="com/acs/bml/ExecutionPhase.hbm.xml"/>
<mapping resource="com/acs/bml/Execution.hbm.xml"/>
<mapping resource="com/acs/bml/Location.hbm.xml"/>
<mapping resource="com/acs/bml/Point.hbm.xml"/>
<mapping resource="com/acs/bml/AbsolutePoint.hbm.xml"/>
<mapping resource="com/acs/bml/LinePoint.hbm.xml"/>
<mapping resource="com/acs/bml/Line.hbm.xml"/>
<mapping resource="com/acs/crom/ObjectItemLocation.hbm.xml"/>
<mapping resource="com/acs/crom/ActionReference.hbm.xml"/>
<mapping resource="com/acs/bml/Reference.hbm.xml"/>
<mapping resource="com/acs/bml/Document.hbm.xml"/>
<mapping resource="com/acs/bml/OpOrder.hbm.xml"/>
<mapping resource="com/acs/bml/VerticalDistance.hbm.xml"/>
<mapping resource="com/acs/bml/Where.hbm.xml"/>
<mapping resource="com/acs/bml/WhereFeature.hbm.xml"/>
<mapping resource="com/acs/bml/Who.hbm.xml"/>
<mapping resource="com/acs/bml/Why.hbm.xml"/>
<mapping resource="com/acs/crom/Capability.hbm.xml"/>
<mapping resource="com/acs/crom/MissionCapability.hbm.xml"/>
<mapping resource="com/acs/crom/Context.hbm.xml"/>
<mapping resource="com/acs/bml/Overlay.hbm.xml"/>
<mapping resource="com/acs/crom/ObjectType.hbm.xml"/>
<mapping resource="com/acs/crom/FeatureType.hbm.xml"/>
<mapping resource="com/acs/crom/ControlFeatureType.hbm.xml"/>
<mapping resource="com/acs/crom/OrganizationType.hbm.xml"/>
<mapping resource="com/acs/crom/GovernmentOrganizationType.hbm.xml"/>
<mapping resource="com/acs/crom/MilitaryOrganizationType.hbm.xml"/>
<mapping resource="com/acs/crom/UnitType.hbm.xml"/>
<mapping resource="com/acs/crom/ObjectItemType.hbm.xml"/>
<mapping resource="com/acs/crom/ObjectStatus.hbm.xml"/>
<mapping resource="com/acs/crom/UnitStatus.hbm.xml"/>
<mapping resource="com/acs/crom/ObjectItem.hbm.xml"/>
<mapping resource="com/acs/crom/Feature.hbm.xml"/>
<mapping resource="com/acs/crom/ControlFeature.hbm.xml"/>
<mapping resource="com/acs/crom/Organization.hbm.xml"/>
<mapping resource="com/acs/crom/Unit.hbm.xml"/>
<mapping resource="com/acs/bml/UnitAssociation.hbm.xml"/>
<mapping resource="com/acs/bml/TaskOrganization.hbm.xml"/>
</session-factory>
</hibernate-configuration>

Code between sessionFactory.openSession() and session.close():

Code to save my object

public void addOpOrder(OpOrder newOpOrder) {

try {
log.write("Successfully received OpOrder", true);
}
catch (Exception ex) {
}

Session session = SessionManager.currentSession();
Transaction tx = session.beginTransaction();

try {
session.saveOrUpdate(newOpOrder);
tx.commit();
session.evict(newOpOrder);
}
catch (Exception ex1) {
ex1.printStackTrace(new java.io.PrintStream(log));
tx.rollback();
}
finally {
System.out.println("finally executed");
SessionManager.closeSession();
}
}

Code to load my object:

public OpOrder getOpOrder(String id) {
try {
log.write("Retrieving OpOrder with id = " + id, true);
}
catch (Exception ex) {
}
try {
OpOrder retrievedOrder = null;
Session session = SessionManager.currentSession();
Query query = session.createQuery(
"from OpOrder as opOrder where opOrder.id = ?");
query.setParameter(0, id);
query.setForceCacheRefresh(true);
List opOrders = query.list();
retrievedOrder = (OpOrder) opOrders.get(0);
return retrievedOrder;
}
catch (Exception ex) {
ex.printStackTrace();
}
finally {
//SessionManager.closeSession();
}
return null;
}

SessionManager code:

public class SessionManager {

private static SessionFactory sessionFactory;

private static Log log = LogFactory.getLog(SessionManager.class);

public static final ThreadLocal session = new ThreadLocal();

static {
try {
sessionFactory = new Configuration().configure().buildSessionFactory();
} catch (Throwable ex) {
log.error("Initial SessionManager creation failed.", ex);
throw new ExceptionInInitializerError(ex);
}
}

public static Session currentSession() throws HibernateException {
Session s = (Session) session.get();
// Open a new Session, if this Thread has none yet
if(s == null) {
s = sessionFactory.openSession();
session.set(s);
}
return s;
}

public static void closeSession() throws HibernateException {
Session s = (Session) session.get();
session.set(null);
if (s != null) s.close();
}

}

Name and version of the database you are using:
MySQL 4.0.18-nt

I have a web service which runs and receives calls to either save or retrieve an OpOrder object. I am able to successfully save the object and I have verified that the entries exist in the database. However, when I try to load the object I just saved I get no results from my query. However, if I save a new object, I am now able to load that previously stored object.

Here is the normal sequence of calls and the results they produce
call addOpOrder (new OpOrder added with id x)
call getOpOrder(x) no results from query
call addOpOrder (new OpOrder added with id x+1)
call getOpOrder(x), OpOrder id=x is found and loaded this time

If I restart my web service (i.e. shutdown and restart tomcat), I am able to load the object without having to do an additional save. Does anyone know what I can do to fix this? If you need additional information I will be happy to provide it.

-Adam Ritchie


Top
 Profile  
 
 Post subject: Same problem
PostPosted: Tue Dec 28, 2004 5:28 pm 
Newbie

Joined: Mon Jul 26, 2004 2:52 pm
Posts: 11
I have noticed similar problem. Looks like there is some latency in finding the object that is saved. Could this be a MySQL problem?

Thanks,


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.