|
| 1 | += 5.0 Migration Guide |
| 2 | +:toc: |
| 3 | + |
| 4 | +This guide discusses migration from Hibernate ORM version 4.3 to version 5.0. For migration from |
| 5 | +earlier versions, see any other pertinent migration guides as well. |
| 6 | + |
| 7 | +== Re-purposing of Configuration |
| 8 | + |
| 9 | +Configuration, historically, allowed users to iteratively add settings and mappings in any order and to query the |
| 10 | +state of settings and mapping information in the middle of that process. Which meant that building the mapping |
| 11 | +information could not effectively rely on any settings being available. This lead to many limitations and problems. |
| 12 | + |
| 13 | +Quite a few methods have been removed from Configuration. Be sure to see the User Guide chapter on bootstrapping for |
| 14 | +details. For applications that integrate with Hibernate via one or more APIs, this change might effect your |
| 15 | +integrations as well. |
| 16 | + |
| 17 | + |
| 18 | +== Short-naming |
| 19 | + |
| 20 | +In an effort to insulate applications from refactoring efforts, Hibernate has begun to recognize "short name" values for |
| 21 | +certain configuration settings. These are discussed in detail in the User Guide in the pertinent sections. |
| 22 | + |
| 23 | +Where available, we highly recommend using the short name for a setting value. |
| 24 | + |
| 25 | + |
| 26 | +== Transactions |
| 27 | + |
| 28 | +The transaction SPI underwent a major redesign as part of 5.0 as well. From a user perspective this generally |
| 29 | +only comes into view in terms of configuration. Previously applications would work with the different backend |
| 30 | +transaction stratagies directly via the `org.hibernate.Transaction` API. In 5.0 a level of indirection has been |
| 31 | +added here. The API implementation of `org.hibernate.Transaction` is always the same now. On the backend, the |
| 32 | +`org.hibernate.Transaction` impl talks to a `org.hibernate.resource.transaction.TransactionCoordinator` which represents |
| 33 | +the "transactional context" for a given Session according to the backend transaction strategy. Users generally do not |
| 34 | +need to care about the distinction. |
| 35 | + |
| 36 | +The change is noted here because it might affect your bootstrap configuration. Whereas previously applications would |
| 37 | +specify `hibernate.transaction.factory_class` and refer to a `org.hibernate.engine.transaction.spi.TransactionFactory` FQN, |
| 38 | +with 5.0 the new contract is `org.hibernate.resource.transaction.TransactionCoordinatorBuilder` and is specified using the |
| 39 | +`hibernate.transaction.coordinator_class` setting. See `org.hibernate.cfg.AvailableSettings.TRANSACTION_COORDINATOR_STRATEGY` |
| 40 | +JavaDocs for additional details. |
| 41 | + |
| 42 | +The following short-names are recognized: |
| 43 | +`jdbc`::(the default) says to use JDBC-based transactions (`org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl`) |
| 44 | +`jta`::says to use JTA-based transactions (`org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorImpl`) |
| 45 | + |
| 46 | +See the User Guide for additional details. |
| 47 | + |
| 48 | + |
| 49 | +== Type handling |
| 50 | + |
| 51 | +* Migrated `org.hibernate.metamodel.spi.TypeContributor` and `org.hibernate.metamodel.spi.TypeContributions` |
| 52 | + to `org.hibernate.boot.model.TypeContributor` and `org.hibernate.boot.model.TypeContributions` |
| 53 | +* Built-in `org.hibernate.type.descriptor.sql.SqlTypeDescriptor` implementations no longer auto-register themselves |
| 54 | + with `org.hibernate.type.descriptor.sql.SqlTypeDescriptorRegistry`. Applications using custom SqlTypeDescriptor |
| 55 | + implementations extending the built-in ones and relying on that behavior should be updated to call |
| 56 | + `SqlTypeDescriptorRegistry#addDescriptor` themselves. |
| 57 | +* The JDBC type for "big_integer" (org.hibernate.type.BigIntegerType) properties has changed from |
| 58 | + java.sql.Types,NUMERIC to java.sql.Types.BIGINT. |
| 59 | +* For ids defined as UUID with generation, for some databases it is required to explicitly set the `@Column( length=16 )` |
| 60 | + in order to generate BINARY(16) so that comparisons properly work. |
| 61 | +* For EnumType mappings defined in hbm.xml where the user wants name-mapping (`javax.persistence.EnumType#STRING`) |
| 62 | + the configuration must explicitly state that using either the `useNamed` (true) setting or by specifying the `type` |
| 63 | + setting set to the value 12 (VARCHAR JDBC type code). |
| 64 | + |
| 65 | + |
| 66 | +== Naming strategies |
| 67 | + |
| 68 | +Historically Hibernate provided just a singular contract for applying a "naming strategy". Starting in 5.0 this has |
| 69 | +been split into 2 distinct contracts: |
| 70 | +* `ImplicitNamingStrategy` - is used whenever a table or column is not explicitly named to determine the name to use. |
| 71 | +* `PhysicalNamingStrategy` - is used to convert a "logical name" (either implicit or explicit) name of a table or column |
| 72 | +into a physical name (e.g. following corporate naming guidelines) |
| 73 | + |
| 74 | + |
| 75 | +== Changed setting defaults |
| 76 | + |
| 77 | +* Default value for `hibernate.id.new_generator_mappings` setting changed to true for 5.0. See |
| 78 | + `org.hibernate.cfg.AvailableSettings#USE_NEW_ID_GENERATOR_MAPPINGS` javadocs. |
| 79 | +* The default ImplicitNamingStrategy (`hibernate.implicit_naming_strategy`) has changed to the JPA-compliant one. See |
| 80 | + `org.hibernate.cfg.AvailableSettings.IMPLICIT_NAMING_STRATEGY` javadocs for details. If you experience problems |
| 81 | + migrating dues to implicit table or column names you may want to specify the legacy strategy |
| 82 | + (`legacy-hbm` \ `org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyHbmImpl`). |
| 83 | +* `hibernate.jdbc.batch_versioned_data` default value is now true; Oracle dialects set this property to false, |
| 84 | +except for Oracle12cDialect |
| 85 | + |
| 86 | + |
| 87 | +== Misc |
| 88 | + |
| 89 | +* `cfg.xml` files are again fully parsed and integrated (events, security, etc) |
| 90 | +* properties loaded from `cfg.xml` through EntityManagerFactory did not previously prefix names with "hibernate." this is now made consistent. |
| 91 | +* `Configuration` is no longer `Serializable` |
| 92 | +* `org.hibernate.dialect.Dialect.getQuerySequencesString` expected to retrieve catalog, schema, and increment values as well |
| 93 | +* removed AuditConfiguration in preference for new `org.hibernate.envers.boot.internal.EnversService` |
| 94 | +* changed AuditStrategy method parameters from (removed) AuditConfiguration to (new) EnversService |
| 95 | +* Moving `org.hibernate.hql.spi.MultiTableBulkIdStrategy` and friends to new `org.hibernate.hql.spi.id` package |
| 96 | + and sub-packages |
| 97 | +* Complete redesign of "property access" contracts |
| 98 | +* Valid `hibernate.cache.default_cache_concurrency_strategy` setting values are now defined via |
| 99 | + `org.hibernate.cache.spi.access.AccessType#getExternalName` rather than the `org.hibernate.cache.spi.access.AccessType` |
| 100 | + enum names; this is more consistent with other Hibernate settings |
| 101 | + |
| 102 | + |
| 103 | +== Deprecations |
| 104 | + |
| 105 | +* Removed the deprecated `org.hibernate.cfg.AnnotationConfiguration` |
| 106 | +* Removed deprecated `org.hibernate.id.TableGenerator` id-generator |
| 107 | +* Removed deprecated `org.hibernate.id.TableHiLoGenerator` (hilo) id-generator |
| 108 | +* Deprecated `org.hibernate.id.SequenceGenerator` and its subclasses |
| 109 | +* Added a new dedicated "deprecation logger" to consolidate logging for deprecated uses. |
| 110 | + |
| 111 | +== Changed/Moved contracts |
| 112 | + |
| 113 | +* `org.hibernate.integrator.spi.Integrator` contract changed to account for bootstrap redesign |
| 114 | +* Extracted `org.hibernate.engine.jdbc.env.spi.JdbcEnvironment` from `JdbcServices`; |
| 115 | + created `org.hibernate.engine.jdbc.env` package and moved a few contracts there. |
| 116 | +* Introduction of `org.hibernate.boot.model.relational.ExportableProducer` which will effect any |
| 117 | + `org.hibernate.id.PersistentIdentifierGenerator` implementations |
| 118 | +* Changed to signature of `org.hibernate.id.Configurable` to accept `ServiceRegistry` rather than just `Dialect` |
0 commit comments