How to specify packagesToScan in HibernateJpaAutoConfiguration? - spring

I'm using HibernateJpaAutoConfiguration directly in a Spring unit test. While Hibernate and EntityManager is configured, no entities are scanned.
Exception
10:29:36.377 [main] INFO o.s.b.f.a.AutowiredAnnotationBeanPostProcessor - JSR-330 javax.inject.Inject' annotation found and supported for autowiring
10:29:36.505 [main] TRACE o.s.b.b.PropertiesConfigurationFactory - Property Sources: org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor$FlatPropertySources#65f8f5ae
10:29:36.638 [main] TRACE o.s.b.b.PropertiesConfigurationFactory - Property Sources: org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor$FlatPropertySources#65f8f5ae
10:29:36.716 [main] TRACE o.s.b.b.PropertiesConfigurationFactory - Property Sources: org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor$FlatPropertySources#65f8f5ae
10:29:36.818 [main] INFO o.s.o.j.LocalContainerEntityManagerFactoryBean - Building JPA container EntityManagerFactory for persistence unit 'default'
10:29:36.842 [main] INFO o.h.jpa.internal.util.LogHelper - HHH000204: Processing PersistenceUnitInfo [
name: default
...]
10:29:36.979 [main] INFO org.hibernate.Version - HHH000412: Hibernate Core {4.3.6.Final}
10:29:36.980 [main] INFO org.hibernate.cfg.Environment - HHH000206: hibernate.properties not found
10:29:36.982 [main] INFO org.hibernate.cfg.Environment - HHH000021: Bytecode provider name : javassist
10:29:37.234 [main] INFO o.h.annotations.common.Version - HCANN000001: Hibernate Commons Annotations {4.0.4.Final}
10:29:37.599 [main] INFO org.hibernate.dialect.Dialect - HHH000400: Using dialect: org.hibernate.dialect.PostgreSQL9Dialect
10:29:37.608 [main] INFO o.h.e.j.internal.LobCreatorBuilder - HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
10:29:37.648 [main] INFO o.h.h.i.a.ASTQueryTranslatorFactory - HHH000397: Using ASTQueryTranslatorFactory
10:29:37.742 [main] INFO o.h.tool.hbm2ddl.SchemaUpdate - HHH000228: Running hbm2ddl schema update
10:29:37.742 [main] INFO o.h.tool.hbm2ddl.SchemaUpdate - HHH000102: Fetching database metadata
10:29:37.744 [main] INFO o.h.tool.hbm2ddl.SchemaUpdate - HHH000396: Updating schema
10:29:37.745 [main] INFO o.h.tool.hbm2ddl.SchemaUpdate - HHH000232: Schema update complete
My workaround is to create my own LocalContainerEntityManagerFactoryBean as follows:
final LocalContainerEntityManagerFactoryBean factoryBean = new LocalContainerEntityManagerFactoryBean();
factoryBean.setPersistenceUnitName("buzzPU"); // persistence.xml
factoryBean.setDataSource(dataSource);
factoryBean.setJpaVendorAdapter(jpaVendorAdapter);
factoryBean.setPersistenceXmlLocation("classpath*:META-INF/donotparsepersistence.xml");
factoryBean.setPackagesToScan("org.soluvas.buzz.core.jpa");
Note that I don't use META-INF/persistence.xml

From the Spring Boot reference...
62.4 Separate #Entity definitions from Spring configuration
Spring Boot tries to guess the location of your #Entity definitions, based on the #EnableAutoConfiguration it finds. To get more control, you can use the #EntityScan annotation, e.g.
#Configuration
#EnableAutoConfiguration
#EntityScan(basePackageClasses=City.class)
public class Application {
//...
}

Using the following also helps:
#EntityScan("org.soluvas.buzz.core.jpa")
It is an alias for 'basePackages' property that configures a list of packages to scan for annotated entities.
This annotation provides an alternative to manually setting
LocalContainerEntityManagerFactoryBean.setPackagesToScan(String...)
and is particularly useful if you want to configure entity scanning in
a type-safe way, or if your LocalContainerEntityManagerFactoryBean is
auto-configured.

Related

Clone of start.spring.io

I'm trying to build an instance of start.spring.io to use it in an air-gaped network. I have been working on it for three weeks and still I don't understand well what to do.
I have cloned start.spring.io from GitHub in a host connected to Internet.
There I can build the application without errors:
./mvnw clean install -DskipTests=true
Then if I true to run the application (../mwnw spring-boot:run from the start-site directory), I get the following error when the application starts, I mean is not an error trying to generate a project, and the application dies:
2022-12-19 17:53:21.170 INFO 2701 --- [ restartedMain] o.s.b.a.w.s.WelcomePageHandlerMapping : Adding welcome page: class path resource [static/index.html]
2022-12-19 17:53:21.264 WARN 2701 --- [ restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [io.spring.initializr.web.controller.ProjectGenerationController] from ClassLoader [jdk.internal.loader.ClassLoaders$AppClassLoader#5cb0d902]
2022-12-19 17:53:21.272 INFO 2701 --- [ restartedMain] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2022-12-19 17:53:21.311 INFO 2701 --- [ restartedMain] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-12-19 17:53:21.411 ERROR 2701 --- [ restartedMain] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [io.spring.initializr.web.controller.ProjectGenerationController] from ClassLoader [jdk.internal.loader.ClassLoaders$AppClassLoader#5cb0d902]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1804) ~[spring-beans-5.3.23.jar:5.3.23]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:620) ~[spring-beans-5.3.23.jar:5.3.23]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.23.jar:5.3.23]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$
...
So, I am not adding any special dependencies or initilializr dependencies other than those already included in the project. I use Java 17 from Bell Soft.
I am not about the Spring Boot version but I haven't modified anything in the project. The pom file in the top directory includes:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.5</version>
</parent>
About my dependencies I am using the initializer-bom:0.20.0-SNAPSHOT. I have also tried with other versions like 0.13.0 and 0.12.0 but the build fails in both cases for the start-site:
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /workspaces/start.spring.io.ori/start-site/src/main/java/io/spring/start/site/extension/dependency/springcloud/SpringCloudContractKotlinDslGradleBuildCustomizer.java:[44,22] cannot find symbol
symbol: method snippets()
location: variable build of type io.spring.initializr.generator.buildsystem.gradle.GradleBuild
[ERROR] /workspaces/start.spring.io.ori/start-site/src/main/java/io/spring/start/site/extension/dependency/graalvm/HibernatePluginGroovyDslGradleBuildCustomizer.java:[39,22] cannot find symbol
symbol: method snippets()
location: variable build of type io.spring.initializr.generator.buildsystem.gradle.GradleBuild
[ERROR] /workspaces/start.spring.io.ori/start-site/src/main/java/io/spring/start/site/extension/dependency/springcloud/SpringCloudContractGroovyDslGradleBuildCustomizer.java:[36,22] cannot find symbol
symbol: method snippets()
location: variable build of type io.spring.initializr.generator.buildsystem.gradle.GradleBuild
[INFO] 3 errors
I wonder if this effort makes sense. If I manage to build the application, will I be able of generating code or does the application connect to somewhere else to retrieve the data required to generate the code?
I would appreciate any hints. Thanks
I will write my (potential) answer here, even though I don't really think that is a real answer but too big to make it as a comment.
My setup:
Amazon Coretto JDK 17 https://docs.aws.amazon.com/corretto/latest/corretto-17-ug/downloads-list.html (it is not JDK 17 from Bell Soft)
Windows 11 Home
So I went to https://github.com/spring-io/start.spring.io and cloned it.
git clone https://github.com/spring-io/start.spring.io.git
Then I went in the root directoy of the cloned project and ran following command:
./mvnw clean install
Here I got some errors while running the tests, but this shouldn't be way too tragic - I think they failed for me, because it tries to run some gradlew commands but they do fail, because I don't have Gradle installed on my PC, as I am always using the Gradle Wrapper.
Then I started the Spring Boot Application.
cd start-site
../mvnw spring-boot:run
The Spring Boot Application started:
022-12-20T15:01:03.510+01:00 INFO 16592 --- [ restartedMain] io.spring.start.site.StartApplication : No active profile set, falling back to 1 default profile: "default"
2022-12-20T15:01:03.573+01:00 INFO 16592 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2022-12-20T15:01:03.573+01:00 INFO 16592 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2022-12-20T15:01:04.800+01:00 INFO 16592 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2022-12-20T15:01:04.809+01:00 INFO 16592 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2022-12-20T15:01:04.810+01:00 INFO 16592 --- [ restartedMain] o.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/10.1.1]
2022-12-20T15:01:04.872+01:00 INFO 16592 --- [ restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2022-12-20T15:01:04.873+01:00 INFO 16592 --- [ restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1298 ms
2022-12-20T15:01:05.371+01:00 INFO 16592 --- [ restartedMain] o.s.b.a.w.s.WelcomePageHandlerMapping : Adding welcome page: class path resource [static/index.html]
2022-12-20T15:01:05.823+01:00 INFO 16592 --- [ restartedMain] org.ehcache.core.EhcacheManager : Cache 'initializr.metadata' created in EhcacheManager.
2022-12-20T15:01:05.832+01:00 INFO 16592 --- [ restartedMain] org.ehcache.jsr107.Eh107CacheManager : Registering Ehcache MBean javax.cache:type=CacheConfiguration,CacheManager=urn.X-ehcache.jsr107-default-config,Cache=initializr.metadata
2022-12-20T15:01:05.832+01:00 INFO 16592 --- [ restartedMain] org.ehcache.jsr107.Eh107CacheManager : Registering Ehcache MBean javax.cache:type=CacheStatistics,CacheManager=urn.X-ehcache.jsr107-default-config,Cache=initializr.metadata
2022-12-20T15:01:05.835+01:00 INFO 16592 --- [ restartedMain] org.ehcache.core.EhcacheManager : Cache 'initializr.dependency-metadata' created in EhcacheManager.
2022-12-20T15:01:05.836+01:00 INFO 16592 --- [ restartedMain] org.ehcache.jsr107.Eh107CacheManager : Registering Ehcache MBean javax.cache:type=CacheConfiguration,CacheManager=urn.X-ehcache.jsr107-default-config,Cache=initializr.dependency-metadata
2022-12-20T15:01:05.836+01:00 INFO 16592 --- [ restartedMain] org.ehcache.jsr107.Eh107CacheManager : Registering Ehcache MBean javax.cache:type=CacheStatistics,CacheManager=urn.X-ehcache.jsr107-default-config,Cache=initializr.dependency-metadata
2022-12-20T15:01:05.839+01:00 INFO 16592 --- [ restartedMain] org.ehcache.core.EhcacheManager : Cache 'initializr.project-resources' created in EhcacheManager.
2022-12-20T15:01:05.841+01:00 INFO 16592 --- [ restartedMain] org.ehcache.jsr107.Eh107CacheManager : Registering Ehcache MBean javax.cache:type=CacheConfiguration,CacheManager=urn.X-ehcache.jsr107-default-config,Cache=initializr.project-resources
2022-12-20T15:01:05.841+01:00 INFO 16592 --- [ restartedMain] org.ehcache.jsr107.Eh107CacheManager : Registering Ehcache MBean javax.cache:type=CacheStatistics,CacheManager=urn.X-ehcache.jsr107-default-config,Cache=initializr.project-resources
2022-12-20T15:01:05.843+01:00 INFO 16592 --- [ restartedMain] org.ehcache.core.EhcacheManager : Cache 'initializr.templates' created in EhcacheManager.
2022-12-20T15:01:05.843+01:00 INFO 16592 --- [ restartedMain] org.ehcache.jsr107.Eh107CacheManager : Registering Ehcache MBean javax.cache:type=CacheConfiguration,CacheManager=urn.X-ehcache.jsr107-default-config,Cache=initializr.templates
2022-12-20T15:01:05.844+01:00 INFO 16592 --- [ restartedMain] org.ehcache.jsr107.Eh107CacheManager : Registering Ehcache MBean javax.cache:type=CacheStatistics,CacheManager=urn.X-ehcache.jsr107-default-config,Cache=initializr.templates
2022-12-20T15:01:06.026+01:00 INFO 16592 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
2022-12-20T15:01:06.031+01:00 INFO 16592 --- [ restartedMain] o.s.b.a.e.web.EndpointLinksResolver : Exposing 2 endpoint(s) beneath base path '/actuator'
2022-12-20T15:01:06.078+01:00 INFO 16592 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2022-12-20T15:01:06.089+01:00 INFO 16592 --- [ restartedMain] io.spring.start.site.StartApplication : Started StartApplication in 3.056 seconds (process running for 3.444)
2022-12-20T15:01:17.890+01:00 INFO 16592 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2022-12-20T15:01:17.891+01:00 INFO 16592 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2022-12-20T15:01:17.892+01:00 INFO 16592 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 1 ms
2022-12-20T15:01:18.122+01:00 INFO 16592 --- [io-8080-exec-10] .s.SaganInitializrMetadataUpdateStrategy : Fetching Spring Boot metadata from https://spring.io/project_metadata/spring-boot
If I now call http://localhost:8080/ - it works, I didn't do absolutely nothing.
Could it maybe be your JDK? I mean the JDKs are similar but not the same... And you also asked:
I wonder if this effort makes sense. If I manage to build the
application, will I be able of generating code or does the application
connect to somewhere else to retrieve the data required to generate
the code? I would appreciate any hints. Thanks
I personally think, it could make sense but - as soon as I generated a project on my own Spring Initializr, I watched the console of the Spring Boot Application and could see the following log:
Fetching Spring Boot metadata from https://spring.io/project_metadata/spring-boot
So it looks, like this thing actually fetches data from the internet, now I don't know what options you have but I have two in mind.
You could try to fork the GitHub Project and try to remove this network call (if this is really the only one) - I couldn't see anything more in the logs atleast... The actual response of the Call looks pretty simple though:
{"id":"spring-boot","name":"Spring Boot","projectReleases":[{"version":"3.0.1-SNAPSHOT","versionDisplayName":"3.0.1-SNAPSHOT","current":false,"releaseStatus":"SNAPSHOT","snapshot":true},{"version":"3.0.0","versionDisplayName":"3.0.0","current":true,"releaseStatus":"GENERAL_AVAILABILITY","snapshot":false},{"version":"2.7.7-SNAPSHOT","versionDisplayName":"2.7.7-SNAPSHOT","current":false,"releaseStatus":"SNAPSHOT","snapshot":true},{"version":"2.7.6","versionDisplayName":"2.7.6","current":false,"releaseStatus":"GENERAL_AVAILABILITY","snapshot":false},{"version":"2.6.14","versionDisplayName":"2.6.14","current":false,"releaseStatus":"GENERAL_AVAILABILITY","snapshot":false},{"version":"2.5.14","versionDisplayName":"2.5.14","current":false,"releaseStatus":"GENERAL_AVAILABILITY","snapshot":false},{"version":"2.4.13","versionDisplayName":"2.4.13","current":false,"releaseStatus":"GENERAL_AVAILABILITY","snapshot":false}]}
You allow explicitly the URL https://spring.io/project_metadata/spring-boot to fetch data inside of your Air Gap Network (I don't know if this is viable though)
I hope this helps a bit?
There are many dependencies that start from the initializer for spring-boot. If you try to build within an air-gapped network, you will not have access to maven's repository for the dependencies. Try building the package outside the network, and capture the libraries required. Look to your ~/.m2/ folder for the copies of the libraries needed. I would recommend setting up a Nexus repository, and it will capture the libraries as you need them from an open network which you can then use on the air-gapped network.
If this is a secured network, you'll have to have all those files vetted and scanned before you can get them into the air-gapped network. Plan for this.
As you add additional annotations or dependencies, you will have to get them from maven central again. It's not ideal, but you might find someone who setup a project to include all spring-boot dependencies for just this situation.
Also, use the STS dev environment, and build your spring-boot to run with included libraries.

Spring-Boot Server is not running, hangs after Initializing Spring FrameworkServlet 'dispatcherServlet

After running the spring-boot App, I'm getting the below logs:
Using below:
Kubernetes
Bit-Bucket Pipeline
MySQL and Oracle
Consul
Running Debug Mode
2019-07-17 10:33:03 [0] [main] INFO c.n.c.sources.URLConfigurationSource - To enable URLs as dynamic configuration sources, define System property archaius.configurationSource.additionalUrls or make config.properties available on classpath.
2019-07-17 10:33:11 [0] [http-nio-9080-exec-2] INFO o.a.c.c.C.[Tomcat].[localhost].[/] - Initializing Spring FrameworkServlet 'dispatcherServlet'

Spring boot Embedded Derby not working in the latest version.

I have used Embedded derby earlier in my spring boot projects. But now when i created the project through Spring Initializr with the derby dependency. I get the below error :
Schema 'SA' does not exist
followed by org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL via JDBC Statement
When i tried running the earlier project that i had created, the Derby is working just fine.
PFB the console for the earlier project :
2018-03-18 15:34:44.346 INFO 16560 --- [ restartedMain]
org.hibernate.cfg.Environment : HHH000021: Bytecode
provider name : javassist 2018-03-18 15:34:44.391 INFO 16560 --- [
restartedMain] o.hibernate.annotations.common.Version : HCANN000001:
Hibernate Commons Annotations {5.0.1.Final} 2018-03-18 15:34:44.490
**INFO 16560 --- [ restartedMain] org.hibernate.dialect.Dialect
: HHH000400: Using dialect: org.hibernate.dialect.DerbyDialect
2018-03-18 15:34:44.497 WARN 16560 --- [ restartedMain]
org.hibernate.dialect.DerbyDialect : HHH000430: The DerbyDialect
dialect has been deprecated; use one of the version-specific dialects
** instead 2018-03-18 15:34:45.094 INFO 16560 --- [ restartedMain]
org.hibernate.tool.hbm2ddl.SchemaExport : HHH000227: Running hbm2ddl
schema export 2018-03-18 15:34:45.099 ERROR 16560 --- [
restartedMain] org.hibernate.tool.hbm2ddl.SchemaExport : HHH000389:
Unsuccessful: drop table book 2018-03-18 15:34:45.099 ERROR 16560 ---
[ restartedMain] org.hibernate.tool.hbm2ddl.SchemaExport : Schema
'SA' does not exist 2018-03-18 15:34:45.129 WARN 16560 --- [
restartedMain] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Warning
Code: 10000, SQLState: 01J01 2018-03-18 15:34:45.129 WARN 16560 --- [
restartedMain] o.h.engine.jdbc.spi.SqlExceptionHelper : Database
'memory:testdb' not created, connection made to existing database
instead. 2018-03-18 15:34:45.129 INFO 16560 --- [ restartedMain]
org.hibernate.tool.hbm2ddl.SchemaExport : HHH000230: Schema export
complete 2018-03-18 15:34:45.152 INFO 16560 --- [ restartedMain]
j.LocalContainerEntityManagerFactoryBean : Initialized JPA
EntityManagerFactory for persistence unit 'default'
The Console Log for my current spring boot with embedded derby :
2018-03-18 15:42:23.234 INFO 11312 --- [ main]
com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2018-03-18 15:42:23.237 WARN 11312 --- [ main]
**com.zaxxer.hikari.util.DriverDataSource : Registered driver with
driverClassName=org.apache.derby.jdbc.EmbeddedDriver was not found,
trying direct instantiation. 2018-03-18 15:42:23.844 INFO 11312 --- [
** main] com.zaxxer.hikari.pool.PoolBase : HikariPool-1 - Driver
does not support get/set network timeout for connections. (Feature not
implemented: No details.) 2018-03-18 15:42:23.847 INFO 11312 --- [
main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start
completed. 2018-03-18 15:42:23.937 INFO 11312 --- [ main]
j.LocalContainerEntityManagerFactoryBean : Building JPA container
EntityManagerFactory for persistence unit 'default' 2018-03-18
15:42:23.969 INFO 11312 --- [ main]
o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing
PersistenceUnitInfo [ name: default ...] 2018-03-18 15:42:24.136
INFO 11312 --- [ main] org.hibernate.Version
: HHH000412: Hibernate Core {5.2.14.Final} 2018-03-18 15:42:24.138
INFO 11312 --- [ main] org.hibernate.cfg.Environment
: HHH000206: hibernate.properties not found 2018-03-18 15:42:24.199
INFO 11312 --- [ main]
o.hibernate.annotations.common.Version : HCANN000001: Hibernate
Commons Annotations {5.0.1.Final} 2018-03-18 15:42:24.380 INFO 11312
--- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.DerbyTenSevenDialect
2018-03-18 15:42:25.572 WARN 11312 --- [ main]
o.h.t.s.i.ExceptionHandlerLoggedImpl : GenerationTarget
encountered exception accepting command : Error executing DDL via JDBC
Statement
org.hibernate.tool.schema.spi.CommandAcceptanceException: Error
executing DDL via JDBC Statement at
org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:67)
~[hibernate-core-5.2.14.Final.jar:5.2.14.Final] at
org.hibernate.tool.schema.internal.SchemaDropperImpl.applySqlString(SchemaDropperImpl.java:375)
[hibernate-core-5.2.14.Final.jar:5.2.14.Final]
The difference i can find between the two is that in the current log(abv log) it says that the
com.zaxxer.hikari.util.DriverDataSource : Registered driver with
driverClassName=org.apache.derby.jdbc.EmbeddedDriver was not found,
trying direct instantiation.
Let me know if we need to configure something apart from the below dependency for enabling this derby. Note- I dint do anything apart from maven dependency in the previous project.
Maven dependency :
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<scope>runtime</scope>
</dependency>
Please configure you JPA Configuration as per your requirement. I've configured as below. You need to add below configuration in application.properties file.
# PROFILES
spring.profiles.active=dev
# JPA (JpaBaseConfiguration, HibernateJpaAutoConfiguration)
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=update
spring.jpa.database=default
spring.jpa.show-sql=true
# DATASOURCE (DataSourceAutoConfiguration & DataSourceProperties)
spring.datasource.continue-on-error=false
spring.datasource.generate-unique-name=false
add
spring.jpa.hibernate.ddl-auto=update
to your application.properties
it is by default create-drop.
The default driver used by derby is org.apache.derby.jdbc.AutoloadedDriver, but springboot and other framework choice org.apache.derby.jdbc.EmbeddedDriver.
It causes the driver to be unable to find the driver when using the datasource for the first time.
About Schema 'SA' does not exist.
I think that you use the other tool connect the derby, such as ij. And the jdbc url they use is the same. It looks like the same database connected, but it's not actually.
This is the key to the problem.
Added this in appplication.properties and worked
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=update
spring.jpa.database=default
spring.jpa.show-sql=true
I've added below property in application.properties, it worked!
spring.jpa.hibernate.ddl-auto=update

Configure container in spring-yarn

I'm using Spring Boot 1.3.5 and spring-yarn-boot 2.3.0 and are plying around with https://github.com/spring-guides/gs-yarn-basic.git The problem I have is configuring resourceManagerHost and resources for the YarnContainer. In the YarnClient and YarnAppMaster the default values are overridden as expected.
The container application have the following application.yml:
spring:
profiles: dev
hadoop:
fsUri: hdfs://dev
resourceManagerHost: rm.dev.com
resources:
- "file:///etc/hadoop/conf/core-site.xml"
- "file:///etc/hadoop/conf/hdfs-site.xml"
- "file:///etc/hadoop/conf/yarn-site.xml"
yarn:
appName: gs-yarn-basic
applicationDir: /app/gs-yarn-basic/
debug: true
The last line below shows that fs.defaultFS is overridden correctly but yarn.resourcemanager.address is set to 0.0.0.0:8032 and "Configuration:​" is set to the default xml configuration files.
[2016-06-09 16:47:14.397] boot - 35635 INFO [main] --- ContainerApplication: The following profiles are active: dev
[2016-06-09 16:47:14.397] boot - 35635 DEBUG [main] --- SpringApplication: Loading source class hello.container.ContainerApplication
[2016-06-09 16:47:14.450] boot - 35635 DEBUG [main] --- ConfigFileApplicationListener: Activated profiles dev
[2016-06-09 16:47:14.450] boot - 35635 DEBUG [main] --- ConfigFileApplicationListener: Skipped (empty) config file 'classpath:/application.yml'
[2016-06-09 16:47:14.450] boot - 35635 DEBUG [main] --- ConfigFileApplicationListener: Loaded config file 'classpath:/application.yml' for profile dev
[2016-06-09 16:47:14.455] boot - 35635 INFO [main] --- AnnotationConfigApplicationContext: Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext#b51cdbd: startup date [Thu Jun 09 16:47:14 CEST 2016]; root of context hierarchy
[2016-06-09 16:47:16.299] boot - 35635 INFO [main] --- ConfiguringBeanFactoryPostProcessor: No bean named 'taskScheduler' has been explicitly defined. Therefore, a default ThreadPoolTaskScheduler will be created.
[2016-06-09 16:47:16.303] boot - 35635 INFO [main] --- ConfiguringBeanFactoryPostProcessor: No bean named 'taskExecutor' has been explicitly defined. Therefore, a default SyncTaskExecutor will be created.
[2016-06-09 16:47:16.311] boot - 35635 INFO [main] --- AutowiredAnnotationBeanPostProcessor: JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
[2016-06-09 16:47:16.461] boot - 35635 INFO [main] --- PostProcessorRegistrationDelegate$BeanPostProcessorChecker: Bean 'org.springframework.data.hadoop.config.common.annotation.configuration.ObjectPostProcessorConfiguration' of type [class org.springframework.data.hadoop.config.common.annotation.configuration.ObjectPostProcessorConfiguration$$EnhancerBySpringCGLIB$$c2374003] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
[2016-06-09 16:47:16.474] boot - 35635 INFO [main] --- PostProcessorRegistrationDelegate$BeanPostProcessorChecker: Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [class org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$ca001d27] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
[2016-06-09 16:47:16.543] boot - 35635 INFO [main] --- PostProcessorRegistrationDelegate$BeanPostProcessorChecker: Bean 'yarnObjectPostProcessor' of type [class org.springframework.data.hadoop.config.common.annotation.configuration.AutowireBeanFactoryObjectPostProcessor] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
[2016-06-09 16:47:16.569] boot - 35635 INFO [main] --- PostProcessorRegistrationDelegate$BeanPostProcessorChecker: Bean 'org.springframework.yarn.boot.properties.SpringYarnEnvProperties' of type [class org.springframework.yarn.boot.properties.SpringYarnEnvProperties] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
[2016-06-09 16:47:16.584] boot - 35635 INFO [main] --- PostProcessorRegistrationDelegate$BeanPostProcessorChecker: Bean 'spring.yarn.CONFIGURATION_PROPERTIES' of type [class org.springframework.yarn.boot.properties.SpringYarnProperties] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
[2016-06-09 16:47:16.610] boot - 35635 INFO [main] --- PostProcessorRegistrationDelegate$BeanPostProcessorChecker: Bean 'spring.hadoop.CONFIGURATION_PROPERTIES' of type [class org.springframework.yarn.boot.properties.SpringHadoopProperties] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
[2016-06-09 16:47:16.619] boot - 35635 INFO [main] --- PostProcessorRegistrationDelegate$BeanPostProcessorChecker: Bean 'spring.yarn.container.CONFIGURATION_PROPERTIES' of type [class org.springframework.yarn.boot.properties.SpringYarnContainerProperties] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
[2016-06-09 16:47:16.663] boot - 35635 INFO [main] --- PostProcessorRegistrationDelegate$BeanPostProcessorChecker: Bean 'org.springframework.yarn.boot.YarnContainerAutoConfiguration$SpringYarnConfig' of type [class org.springframework.yarn.boot.YarnContainerAutoConfiguration$SpringYarnConfig$$EnhancerBySpringCGLIB$$2caddc60] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
[2016-06-09 16:47:16.675] boot - 35635 INFO [main] --- SpringYarnConfiguration: Enabling CONTAINER for Yarn
[2016-06-09 16:47:16.675] boot - 35635 INFO [main] --- PostProcessorRegistrationDelegate$BeanPostProcessorChecker: Bean 'org.springframework.yarn.config.annotation.configuration.SpringYarnContainerConfiguration' of type [class org.springframework.yarn.config.annotation.configuration.SpringYarnContainerConfiguration$$EnhancerBySpringCGLIB$$9f2964a0] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
[2016-06-09 16:47:16.723] boot - 35635 INFO [main] --- SpringYarnConfiguration: We couldn't figure out if we could use existing configuration
[2016-06-09 16:47:16.724] boot - 35635 INFO [main] --- SpringYarnConfiguration: Building configuration for bean 'yarnConfiguration'
[2016-06-09 16:47:16.738] boot - 35635 INFO [main] --- SpringYarnConfigBuilder: Existing yarnConfiguration: null
[2016-06-09 16:47:17.194] boot - 35635 INFO [main] --- ConfigurationFactoryBean: Overwriting fsUri=[file:///] with fsUri=[hdfs://dev]
[2016-06-09 16:47:17.323] boot - 35635 WARN [main] --- NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
[2016-06-09 16:47:17.442] boot - 35635 INFO [main] --- ConfigurationFactoryBean: Executing with tokens:
[2016-06-09 16:47:17.443] boot - 35635 INFO [main] --- ConfigurationFactoryBean: Kind: HDFS_DELEGATION_TOKEN, Service: ha-hdfs:dev, Ident: (HDFS_DELEGATION_TOKEN token 21603 for anonymous)
[2016-06-09 16:47:17.511] boot - 35635 INFO [main] --- ConfigurationFactoryBean: Kind: YARN_AM_RM_TOKEN, Service: 10.4.0.91:8030, Ident: (appAttemptId { application_id { id: 111 cluster_timestamp: 1465390563601 } attemptId: 1 } keyId: -144109947)
[2016-06-09 16:47:17.665] boot - 35635 INFO [main] --- SpringYarnConfigBuilder: Setting configuration for SpringYarnConfigs: fs.defaultFS=hdfs://dev yarn.resourcemanager.address=0.0.0.0:8032 Configuration: core-default.xml, core-site.xml, yarn-default.xml, yarn-site.xml, mapred-default.xml, mapred-site.xml
Any ideas on how to get the container application to pick up the configuration?

Very slow Spring Boot application startup

I have a simple Spring Boot application that connects to a PostgreSQL database and serves as a JSON service. Somehow the startup has become very slow, see timings 10:37:10 and 10:38:00:
2015-05-09 10:37:09.649 INFO 20880 --- [lication.main()] o.apache.catalina.core.StandardService : Starting service Tomcat
2015-05-09 10:37:09.651 INFO 20880 --- [lication.main()] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.0.20
2015-05-09 10:37:09.767 INFO 20880 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2015-05-09 10:37:09.767 INFO 20880 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 2970 ms
2015-05-09 10:37:09.979 INFO 20880 --- [ost-startStop-1] o.s.b.c.e.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2015-05-09 10:37:09.985 INFO 20880 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2015-05-09 10:37:10.105 INFO 20880 --- [lication.main()] o.s.j.d.DriverManagerDataSource : Loaded JDBC driver: org.postgresql.Driver
2015-05-09 10:37:10.214 INFO 20880 --- [lication.main()] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2015-05-09 10:37:10.233 INFO 20880 --- [lication.main()] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2015-05-09 10:37:10.585 INFO 20880 --- [lication.main()] org.hibernate.Version : HHH000412: Hibernate Core {4.3.8.Final}
2015-05-09 10:37:10.587 INFO 20880 --- [lication.main()] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2015-05-09 10:37:10.589 INFO 20880 --- [lication.main()] org.hibernate.cfg.Environment : HHH000021: Bytecode provider name : javassist
2015-05-09 10:37:10.968 INFO 20880 --- [lication.main()] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {4.0.5.Final}
2015-05-09 10:38:00.023 INFO 20880 --- [lication.main()] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.PostgreSQLDialect
2015-05-09 10:38:00.041 INFO 20880 --- [lication.main()] o.h.e.jdbc.internal.LobCreatorBuilder : HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
2015-05-09 10:38:00.274 INFO 20880 --- [lication.main()] o.h.h.i.ast.ASTQueryTranslatorFactory : HHH000397: Using ASTQueryTranslatorFactory
Any thoughts? Is there anything I can do to diagnose the problem?
For Spring Boot you can set this in your application.properties file:
spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false
I also found that I needed to set another property or I would get the error "org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set". To rectify that I set this property:
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
This reduced our startup time from about 100 seconds down to 12.
Problem solved using
properties.setProperty("hibernate.temp.use_jdbc_metadata_defaults", "false");
Thanks all.
Contributing application.yml version of property setting.
spring:
jpa:
properties:
hibernate:
temp:
use_jdbc_metadata_defaults: false
When I point to database in AWS RDS server it takes 78 seconds.
After given this configuration it takes 52 seconds.
spring:
jpa:
properties:
hibernate:
temp:
use_jdbc_metadata_defaults: false
And after given this configuration with the above configuration it takes only 10 seconds.
spring:
jpa:
hibernate:
ddl-auto: none
For dev environment, use the following property
spring.jpa.hibernate.ddl-auto=none
This would be a bit risky for staging and prod environment.
Are you running the tests on a local server? Perhaps there's some problem with the database server URL, such as a non-resolvable hostname or an IPv6 DNS entry, connecting with the same connection string from another application (e.g. http://squirrel-sql.sourceforge.net/) could confirm the problem.
The delay is definitely logged when creating the database connection for the first time (either while loading the driver or performing the connection).
I found the startup takes long time when the db server is far, in my case it won't take time when using the localhost db, and it take about 20 seconds in product enviroment with db is in us and server is in jp.
For springboot data JPA you need to add spring.data.jpa.repositories.bootstrap-mode=lazy in application.properties file this would also reduce bootup time.
spring.data.jpa.repositories.bootstrap-mode=lazy
spring.jpa.hibernate.ddl-auto=none
spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false
I used the following piece of code
spring:
jpa:
database-platform: org.hibernate.dialect.PostgreSQLDialect
show-sql: false
generate-ddl: true
**hibernate:
ddl-auto: none
properties:
hibernate.hbm2ddl.auto: none**

Resources