当前位置:首页 > 开发 > 开源软件 > 正文

Update your Hibernate 3 application to use Hibernate 4

发表于: 2012-10-23   作者:sunjing   来源:转载   浏览次数:
摘要: Changes for Hibernate 3.3 applications Hibernate "text" type now maps to JDBC LONGVARCHAR In pre-3.5 versions of Hibernate, text type were mapped to JDBC CLOB. A new Hibernate type, &qu

Changes for Hibernate 3.3 applications

  1. Hibernate "text" type now maps to JDBC LONGVARCHAR
    In pre-3.5 versions of Hibernate, text type were mapped to JDBC CLOB. A new Hibernate type, "materialized_clob", was added to map Java String properties to JDBC CLOB. If an application has properties configured as type="text" that are intended to be mapped to JDBC CLOB, they should be changed to type="materialized_clob" in hbm mapping files, or, if using annotations, @Type(type = "text") should be replaced by @Lob.
  2. Numeric aggregate Criteria projections now return the same value type as their HQL counterparts. As a result, the return type from the following projections in org.hibernate.criterion have changed:
    1. "count" and "count distinct" projections now return a Long value (due to changes in CountProjection, Projections.rowCount(), Projections.count( propertyName ), and Projections.countDistinct( propertyName )).
    2. "sum" projections return a value type that depends on the property type due to changes in Projections.sum( propertyName ). Failure to modify your application code may result in a java.lang.ClassCastException.
      1. for properties mapped as Long, Short, Integer, or primitive integer types, a Long value is returned;
      2. for properties mapped as Float, Double, or primitive floating point types, a Double value is returned.

Changes for Hibernate 3.5 applications

  1. AnnotationConfigration must be merged into Configuration
    Aside from the fact that AnnotationConfiguration is now deprecated, this usually is not of concern. However, if you are still using an hbm.xml file, you should be aware that AS7 now uses the org.hibernate.cfg.EJB3NamingStrategy in AnnotationConfigration instead of the older org.hibernate.cfg.DefaultNamingStrategy that was previously used in Configuration. This can result in naming mismatches. If you rely on the naming strategy to default the name of a association (many-to-many and collections of elements) table, you may see this issue. To resolve it, you can tell Hibernate to use the the legacy org.hibernate.cfg.DefaultNamingStrategy by calling Configuration#setNamingStrategy and passing it org.hibernate.cfg.DefaultNamingStrategy#INSTANCE
  2. The namespaces for the Hibernate DTD files have changed.
  3. If you are using Oracle, the global environment variable "hibernate.jdbc.use_streams_for_binary" must be set to true if you are using "materialized_clob" or "materialized_blob" properties.
  4. If you are using PostgreSQL, the global environment variable "hibernate.jdbc.use_streams_for_binary" must be set to false if you are using CLOB or BLOB properties.

General Changes when migrating to Hibernate 4

In Hibernate 4.0 there is a new IdentifierGenerator implementations.

Hibernate 4.0 supplies a property that is called hibernate.id.new_generator_mappings  and hibernate documentation states that it defaults to false for backward compatibility reasons - however in AS 7.1 this value defaults to true .

consider setting the value to false in persistence.xml in case you don't see the behaviour you had in your app in previous versions.

for more information - read about 5.1.2 Identifiers in general and about 5.1.2.2. Identifier generator more specifically* *here

Update your Hibernate 3 application to use Hibernate 4

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

编辑推荐
博客分类: JSR303 JSR303 Hibernate Validator 前言 <p style="padd
前言 效验这个概念,想必所有的开发者都知道其作用的重要性,那么笔者今天就要给各位讲解笔者在项目
前言 效验这个概念,想必所有的开发者都知道其作用的重要性,那么笔者今天就要给各位讲解笔者在项目
博客分类: JSR303 JSR303 Hibernate Validator 前言 <p style="padd
0. 前言 本文章所有代码已经上传,可以免费下载了解。 本项目启动的是会自动创建表结构,只需要看客
代码框架: 本工程的代码了。。jar包就不在这里展示了。 从官网上下载都可以! web.xml: <?xml v
首先用自动生成的那个页面,index.jsp: <%@ page language="java" contentType="text/html; cha
This is a blog post by iOS Tutorial Team member Adam Burkepile, a full-time Software Consulta
例:建表脚本 create table customers( id bigint not null, name varchar(15), primary key (id) )
早期的项目比较简单,多是用JSP 、Servlet + JDBC 直接搞定,后来使用 Struts1(Struts2)+Spring+Hib
版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号