Browsing All Posts filed under »Hibernate«

XStream and Hibernate lazy loading issues

May 9, 2011

0

If you are marshalling persistent objects being managed by Hibernate, you will have issues with Lazy loading. Say you have Order class with an property which is Product class type or List of OrderItem objects … instanceof match will fail (even if you have your own Custom Converter) … as the instance will be OrderItems_javaassist_xxx […]

Solr vs Hibernate Search

May 7, 2011

0

We are looking to implement indexing in our site and evaluated SolrJ (The java client library to access Lucene) and Hibernate Search (that also uses Lucene). Hibernate was very a tempting option given we already use Hibernate as the ORM. It just seems so elegant and simple. Also Hibenate takes care of updation to the […]

Projection and aggregate functions in Hibernate

April 18, 2011

1

I needed to aggregate columns (Sum, Count etc.) and display results in a JSP (thru Struts) … with the same convenience as regular attributes for a persistent class. String queryString = “select product.productName as productName, count(billQuantity) as countBillQuantity, sum(billAmount) as totalBillAmount from bill group by product.productName”; Query queryObject = getSession().createQuery(queryString); queryObject.setResultTransformer(Transformers.aliasToBean(QueryResultSummary.class)); QueryResultSummary is a class […]

Hibernate TransactionException: Transaction not successfully started

November 13, 2010

0

If you got this cryptic error … among other issues … this could because you had one transaction embedded inside another. MethodA(){ …. objectDAO.getSession().beginTransaction(); objectDAO.save(objectInstance); MethodB(); objectDAO.getSession().getTransaction().commit() …. } MethodB(){ …. anotherObjectDAO.getSession().beginTransaction();//<===Begining a transaction inside another transaction … REMOVE THIS anotherObjectDAO.save(anotherObjectInstance); anotherObjectDAO.getSession().getTransaction().commit()//<===Begining a transaction inside another transaction … REMOVE THIS …. } You may have […]

Hibernate mySQL connection lost overnight

September 19, 2010

0

Using tomcat + mySQL + Hibernate … Your application works fine … then you wake up in the morning and try to use it … it crashes. You restart Tomcat … it works fine again. There are a lot of posts on the internet about this 8 hour problem To fix it … 1. Change […]

Migrating Hibernate from 3.1 to 3.5.x (3.5.3 actually)

September 10, 2010

0

After changing the jar files (Hibernate3, all in \lib\required and any that you use from \lib\optional) Here’s the migration quide … #1. ┬áI got a java.lang.Long class cast exception. On further investigation┬áI found that any count(*) query returns Long (not sure what it was doing in 3.1) and I was casting it as Integer. Even […]

Hibernate Exception – Could not synchronize database with session

July 24, 2010

0

One fine saturday morning, trying to do a new release. A list all action that always worked started throwing up exceptions in Hibernate. Could not synchronize database with session Duplicate entry ‘1’ for key 2 I wasn’t even inserting or updating … and yet this suddenly broke. I figured out after a few frustrating hours […]