Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
* Configuration properties for Hibernate.
*
* @author Stephane Nicoll
* @author Artsiom Yudovin
* @since 2.1.0
* @see JpaProperties
*/
Expand All @@ -56,6 +57,13 @@ public class HibernateProperties {
*/
private Boolean useNewIdGeneratorMappings;

/**
* Archive Scanner. This is actually a shortcut for the "hibernate.archive.scanner"
* property. When not specified will default to
* "org.hibernate.boot.archive.scan.internal.DisabledScanner".
*/
private String archiveScanner = "org.hibernate.boot.archive.scan.internal.DisabledScanner";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update but that's not what I meant. There shouldn't be any property at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

property was removed


public String getDdlAuto() {
return this.ddlAuto;
}
Expand All @@ -72,6 +80,14 @@ public void setUseNewIdGeneratorMappings(Boolean useNewIdGeneratorMappings) {
this.useNewIdGeneratorMappings = useNewIdGeneratorMappings;
}

public String getArchiveScanner() {
return this.archiveScanner;
}

public void setArchiveScanner(String archiveScanner) {
this.archiveScanner = archiveScanner;
}

public Naming getNaming() {
return this.naming;
}
Expand All @@ -95,6 +111,7 @@ private Map<String, Object> getAdditionalProperties(Map<String, String> existing
HibernateSettings settings) {
Map<String, Object> result = new HashMap<>(existing);
applyNewIdGeneratorMappings(result);
applyArchiveScanner(result);
getNaming().applyNamingStrategies(result);
String ddlAuto = determineDdlAuto(existing, settings::getDdlAuto);
if (StringUtils.hasText(ddlAuto) && !"none".equals(ddlAuto)) {
Expand All @@ -121,6 +138,10 @@ else if (!result.containsKey(AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS)) {
}
}

private void applyArchiveScanner(Map<String, Object> result) {
result.put(AvailableSettings.SCANNER, this.archiveScanner);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not checking if a user has set the property

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added checking

}

private String determineDdlAuto(Map<String, String> existing,
Supplier<String> defaultDdlAuto) {
String ddlAuto = existing.get(AvailableSettings.HBM2DDL_AUTO);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
* Tests for {@link HibernateProperties}.
*
* @author Stephane Nicoll
* @author Artsiom Yudovin
*/
public class HibernatePropertiesTests {

Expand Down Expand Up @@ -123,6 +124,23 @@ public void useNewIdGeneratorMappingsFalse() {
"false")));
}

@Test
public void useArchiveScanner() {
this.contextRunner.withPropertyValues(
"spring.jpa.hibernate.archive-scanner:org.hibernate.boot.archive.scan.internal.StandardScanner")
.run(assertHibernateProperties((hibernateProperties) -> assertThat(
hibernateProperties).containsEntry(AvailableSettings.SCANNER,
"org.hibernate.boot.archive.scan.internal.StandardScanner")));
}

@Test
public void defaultArchiveScanner() {
this.contextRunner.run(assertHibernateProperties(
(hibernateProperties) -> assertThat(hibernateProperties).containsEntry(
AvailableSettings.SCANNER,
"org.hibernate.boot.archive.scan.internal.DisabledScanner")));
}

@Test
public void defaultDdlAutoIsNotInvokedIfPropertyIsSet() {
this.contextRunner.withPropertyValues("spring.jpa.hibernate.ddl-auto=validate")
Expand Down