Update your Hibernate 3 application to use Hibernate 4

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

你可能感兴趣的:(Hibernate4)