-->
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.  [ 1 post ] 
Author Message
 Post subject: Maybe it's a flush problem
PostPosted: Wed Dec 19, 2012 8:00 pm 
Newbie

Joined: Wed Dec 19, 2012 5:46 pm
Posts: 1
Location: FRENCH POLYNESIA
Hello Everyone,

First of all I would like to thank the community to help me understand my problem. Also, Excuse me for my bad English, it's not my main language.

Problem
I am using org.hibernate.Criteria to read records from database. Sometimes (in 1% of time), my method does not return all the records.

When the problem occurred, there is no Exception.

Code:
@SuppressWarnings("unchecked")
public List<InvoiceLine> getInvoiceLines(final Session aSession, final InvoiceId aId) {
   long iStart = System.currentTimeMillis();

   Criteria iCriteria = aSession.createCriteria(InvoiceLine.class);
   iCriteria.add(Restrictions.eq("id.invoiceNumber", aId.getInvoiceNumber()));
   iCriteria.add(Restrictions.eq("id.invoiceType", aId.getInvoiceType()));
   iCriteria.add(Restrictions.eq("id.sellingType", aId.getSellingType()));
   iCriteria.add(Restrictions.eq("id.proforma", aId.isProforma()));
   List<InvoiceLine> iResults = iCriteria.list();

   logger.debug(String.format("aSession<%s> InvoiceId<%s> iResults<%d> time: %d", aSession, aId, iResults.size(), System.currentTimeMillis() - iStart));
   return iResults;
}


Process
Here the process where I use this method:
Code:
public InvoiceLine addInvoiceLine(final Invoice aInvoice, final InvoiceLine aInvoiceLine) throws Exception {
   long iStart = System.currentTimeMillis();

   try {
      // Save invoice_line
      this.saveInvoiceLine(aInvoice, aInvoiceLine);

      // Update Invoice's amount
      List<InvoiceLine> iInvoiceLines = this.getInvoiceLines(aInvoice.getId());
      this.updateInvoiceAmount(aInvoice, iInvoiceLines);
      this.save(aInvoice);

      logger.debug(String.format("Invoice<%s> InvoiceLine<%s> time: %d", aInvoice.getId(), aInvoiceLine.getId(), System.currentTimeMillis() - iStart));
      return aInvoiceLine;
   } catch (Exception aException) {
      logger.error(String.format("Invoice<%s> InvoiceLine<%s> time: %d", aInvoice.getId(), aInvoiceLine.getId(), System.currentTimeMillis() - iStart), aException);
      throw aException;
   }
}


Explanation
First, I execute this.saveInvoiceLine(aInvoice, aInvoiceLine) that insert/update the invoice_line in database. To perform the insert/update, I use getSessionFactory().openSession() to create my org.hibernate.Session and execute my insert/update in a transaction. The transaction is then committed and the org.hibernate.Session is closed.

And, I execute this.getInvoiceLines(aInvoice.getId()) to read all invoice_line associated with my invoice. The just added invoice_line is not returned.

Theory
Our Team believe that we have a flush problem sometimes. We believe that Hibernate have some sort of "cache" and when the this.getInvoiceLines() is executed, the cache simply does not have the added invoice_line.

Thank you for your help.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.