Some of the problems after upgrading to Hibernate3.2

Source: Internet
Author: User

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")

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.