This issue can't be edited
Because it belongs to an archived project. Jira admins can restore projects from the archive.
Honor "hbm2ddl" setting to initialize and drop the schema
Description
Environment
Activity

Gunnar Morling February 9, 2016 at 2:40 PMEdited
This finally will be doable as of ORM 5.1 with the required changes implemented as part of HHH-10458.
What we'll have to do:
Implement an OGM-specific
SchemaManagementTool
and its delegatesDrop properties "hibernate.ogm.datastore.create_database" (replaced by "hbm2ddl.auto") and likely "hibernate.ogm.datastore.database" (I suppose "hibernate.default_schema" can be used instead)
Add support for dropping tables etc. -> add
List<T> getDropCommands()
toSchemaDefiner
where<T>
is a store-specific type of DDL commands (mostly String, but it may be some object representation e.g. for MongoDB which does not have a DDL)The schema management mechanism supports different types of "targets": DATABASE, SCRIPT and STDOUT; In a first step OGM would only support the former; Naturally, the other two require DDL commands to have a String-assignable representation, so they may not be doable for some backends
Further steps will include
Support for reading import scripts (
SourceType.SCRIPT
etc.); Again the String-requirement may make it not supportable for some storesSupport for the other hbm2ddl modes (validation, migration)
I've pushed a very rough first attempt to my fork at https://github.com/gunnarmorling/hibernate-ogm/tree/OGM-571; This is far from being complete, just a validation to make sure the work on the OGM side suits our purposes
Davide D'Alto January 6, 2015 at 11:26 AMEdited
The problem is in SessionFactoryImpl, the creation of a new SchemaExport is done in the constructor of SessioFactoryImpl when the hbm2ddl property is set. The schema export fails because it runs org.hibernate.cfg.Configuration.generateSchemaCreationScript(...) and it cannot recognize some types. This is the error:
javax.persistence.PersistenceException: [PersistenceUnit: jpajtastandalone] Unable to build Hibernate SessionFactoryCaused by: org.hibernate.MappingException: No Dialect mapping for JDBC type: -2
I've tried to override the methods in OgmConfiguration but I still have the error if Persistence.createEntityManagerFactory(...) is used.
Emmanuel Bernard January 5, 2015 at 1:13 PM
This turned out not to be trivial to do and will require changes in Hibernate ORM.
Basically hbm2ddl does trigger the SessionFactory to call SchemaUpdate (or something like that). Davide tried to fool this mechanism but we could not find a way,
So we need to take a step back and modify ORM first.

Gunnar Morling January 2, 2015 at 9:33 AM
Bummer, so you guys decided against doing this for the Final :-/ ? Would have been very useful IMO as we now have an option which we'll remove for sure in 4.2.

Gunnar Morling October 30, 2014 at 9:32 AM
, do you think you could take a look at this one? It'd be nice to get this done for the Final. Note that support for Persistence#generateSchema()
can be done separately IMO.
Currently, the
SchemaDefiner
contract is implicitly invoked during bootstrap. Instead, we should consider the setting given for the "hbm2ddl" option and initialize/drop the schema accordingly.In addition, JPA 2.1's
Persistence#generateSchema()
operation should be supported.This will require to add a
dropSchema()
method toSchemaDefiner
.Also the property
OgmProperties#CREATE_DATABASE
seems obsolete once we support hbm2ddl.