Reputation: 417
The Envers 5.1 documentation states that you should use the org.hibernate.envers.tools.hbm2ddl.EnversSchemaGenerator
to export a database schema programmatically.
But the class is not there anymore! Really ;-)
Maybe it was not adjusted to the schema management changes? How do I substitute the class with Hibernate 5.1?
Upvotes: 2
Views: 2342
Reputation: 21
If you want to export tables in a sql file in Hibernate 5.xx you can use the following code
StandardServiceRegistryBuilder registryBuilder = new StandardServiceRegistryBuilder().applySetting("hibernate.dialect", "org.hibernate.spatial.dialect.postgis.PostgisDialect"); // dialect
MetadataSources metadataSources = new MetadataSources(registryBuilder.build());
PathMatchingResourcePatternResolver resourceLoader = new PathMatchingResourcePatternResolver();
new LocalSessionFactoryBuilder(null, resourceLoader, metadataSources).scanPackages("com.xxx");
Metadata metadata = metadataSources.buildMetadata();
new SchemaExport().setFormat(true).setOutputFile("export.sql").createOnly(EnumSet.of(TargetType.STDOUT, TargetType.SCRIPT), metadata);
Upvotes: 2
Reputation: 53
In previous versions of Hibernate you had to generate the sql from the entities and those from Envers separatly.
But now it is not necessary anymore. Just generate them like mentioned and the envers will be generated along with them. (_AUTH tables)
Upvotes: 0
Reputation: 1967
To export schema programatically ,alternate way is
ServiceRegistry serviceRegistry =(StandardServiceRegistryImpl) new StandardServiceRegistryBuilder()
.configure("hibernate.cfg.xml")
.build();
MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(serviceRegistry).buildMetadata();
SchemaExport schemaExport = new SchemaExport(metadata);
schemaExport.setOutputFile("hbm2schema.sql");
schemaExport.create(true, true);
( (StandardServiceRegistryImpl) serviceRegistry ).destroy();
Upvotes: 0