1. Upgrade from hibernate3.0.x/3.1.x to the latest Hibernate3.2, be sure to note that many of the Hibernate3.2 SQL functions such as COUNT (), the only return value for sum () has changed from integer to Long, If you do not upgrade your code, you will get a classcastexception. This change is primarily for JPA compatibility and can be found in the latest documentation for hibernate.org.
The Hibernate team also offers a solution that is compatible with the original:
Configuration classicCfg = new Configuration();
classicCfg.addSqlFunction( "count", new ClassicCountFunction());
classicCfg.addSqlFunction( "avg", new ClassicAvgFunction());
classicCfg.addSqlFunction( "sum", new ClassicSumFunction());
SessionFactory classicSf = classicCfg.buildSessionFactory();
Or
int count = ((Integer) Q.uniqueresult ()). Intvalue (), change to int count = ((number) Q.uniqueresult ()). Intvalue (); This allows two versions to be compatible at the same time.
2, Hibernate3.2 requirements ehcache1.2
3, Session.createsqlquery (SQL). Executeupdate (); This Hibernate3.0.5 is not supported, but Hibernate3.2 support, Session.createsqlquery (Fsql). Addscalar ( "Singlevalue", hibernate.double). Uniqueresult (); this doesn't need to be addscalar by 3.2.
4, Session.createsqlquery (SQL). Addentity (class Class); Hibernate3.0.5 does not support the Addentity method of a single parameter.
5. Hibernate3.2 can use Resulttransformer for native SQL queries. This returns entities that are not managed by hibernate.
sess.createSQLQuery("SELECT NAME, BIRTHDATE FROM CATS")
.setResultTransformer(Transformers.aliasToBean(CatDTO.class))
Or:
setResultTransformer(new AliasToBeanResultTransformer(CatDTO.class))
The above query will return a list of catdto that will be instantiated and inject the values of name and birthday into the corresponding properties or fields. However, it is important to note that each column must be addscalar ("column name")