Skip to content

Commit

Permalink
[jOOQ#5410] Update Hibernate dependency to 5.2.1 in jooq-meta-extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaseder committed Jul 12, 2016
1 parent a6ab96c commit 3acd115
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion jOOQ-meta-extensions/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.0.0.Final</version>
<version>5.2.1.Final</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@

import java.sql.Connection;
import java.sql.DriverManager;
import java.util.EnumSet;

import javax.persistence.Entity;

Expand All @@ -56,8 +57,8 @@

import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.boot.spi.MetadataImplementor;
import org.hibernate.tool.hbm2ddl.SchemaExport;
import org.hibernate.tool.schema.TargetType;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
import org.springframework.core.type.filter.AnnotationTypeFilter;
Expand Down Expand Up @@ -89,23 +90,26 @@ protected DSLContext create0() {
MetadataSources metadata = new MetadataSources(
new StandardServiceRegistryBuilder()
.applySetting("hibernate.dialect", "org.hibernate.dialect.H2Dialect")
.applySetting("javax.persistence.schema-generation-connection", connection)
.build()
);

ClassPathScanningCandidateComponentProvider scanner =
new ClassPathScanningCandidateComponentProvider(true);

scanner.addIncludeFilter(new AnnotationTypeFilter(Entity.class));
for (String pkg : packages.split(",")) {
for (BeanDefinition def : scanner.findCandidateComponents(defaultIfBlank(pkg, "").trim())) {
for (String pkg : packages.split(","))
for (BeanDefinition def : scanner.findCandidateComponents(defaultIfBlank(pkg, "").trim()))
metadata.addAnnotatedClass(Class.forName(def.getBeanClassName()));
}
}

// This seems to be the way to do this in idiomatic Hibernate 5.0 API
// See also: http://stackoverflow.com/q/32178041/521799
SchemaExport export = new SchemaExport((MetadataImplementor) metadata.buildMetadata(), connection);
export.create(true, true);
// SchemaExport export = new SchemaExport((MetadataImplementor) metadata.buildMetadata(), connection);
// export.create(true, true);

// Hibernate 5.2 broke 5.0 API again. Here's how to do this now:
SchemaExport export = new SchemaExport();
export.create(EnumSet.of(TargetType.DATABASE), metadata.buildMetadata());
}
catch (Exception e) {
throw new DataAccessException("Error while exporting schema", e);
Expand Down

0 comments on commit 3acd115

Please sign in to comment.