we created new application with JPA configuration. It is new application, so there are no entities yet and application failing during build with this error:
io.micronaut.context.exceptions.ConfigurationException: Entities not found for JPA configuration: 'default' within packages io.example.foo
This error is not error because there really no entity exists. When I created dummy entity to test, build pass. Can you tell me how to fix it?
This is my jpa configuration:
jpa:
default:
properties:
hibernate:
hbm2ddl:
auto: none
dialect: org.hibernate.dialect.PostgreSQL10Dialect
physical_naming_strategy: "io.micronaut.data.hibernate.naming.DefaultPhysicalNamingStrategy"
bytecode:
provider: none
Related
I am trying to build my service as GraalVM native image using Spring and buildpacks. My application is Spring Data REST app talking to PostgreSQL database. There is nothing unusual in the code. The image builds with no issues and runs outside of Docker container, but when I am trying to run the generated GraalVM container I am getting an error:
Description:
Native reflection configuration for org.hibernate.dialect.PostgreSQLDialect is missing.
The exception is
Caused by: java.lang.ClassNotFoundException: org.hibernate.dialect.PostgreSQLDialect
at com.oracle.svm.core.hub.ClassForNameSupport.forName(ClassForNameSupport.java:71) ~[na:na]
at java.lang.Class.forName(DynamicHub.java:1319) ~[.....:na]
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:130) ~[na:na]
My application.yml:
---
spring:
config:
activate:
on_profile: local
datasource:
url: jdbc:postgresql://localhost:5432/test
username: postgres
password: 1234
driver-class-name: org.postgresql.Driver
jpa:
hibernate:
use-new-id-generator-mappings: false
ddl-auto: none
show-sql: true
properties:
hibernate:
dialect: org.hibernate.dialect.PostgreSQLDialect
javax:
persistence:
validation:
mode: none
I know that Spring native image support still has issues, I am just wondering if the problem is on my side.
There now is a way to solve this for postgres with the current version of Spring Native using version spring native hints.
Native Hints
This turns out to be simple to implement using an annotation. See example below...
package com.margic.serverless.data;
import org.hibernate.dialect.PostgreSQL95Dialect;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.nativex.hint.TypeHint;
#SpringBootApplication
#TypeHint(types = PostgreSQL95Dialect.class, typeNames = "org.hibernate.dialect.PostgreSQLDialect")
public class DataApplication {
public static void main(String[] args) {
SpringApplication.run(DataApplication.class, args);
}
}
The reason is Spring native support issues: The following dependencies are not known to work with Spring Native: ..., Rest Repositories, ...
We have a working Spring Boot (2.1.3) application. For local development we use
jpa:
hibernate:
ddl-auto: create-drop
Now we need to generate a ddl file for our db-guys (preferable during build). I'll tried by setting these additional properties:
javax:
persistence:
schema-generation:
create-source: metadata
action: create
create-target: create.sql
With these settings in place (ddl-auto changed to none) i started up my application. While it started fine there is not "create.ddl" to found.
Because i want the ddl file to be generated during build i added a test:
#RunWith(SpringRunner.class)
#DataJpaTest
#TestPropertySource(locations = "classpath:/testproperties/ddlgenerate.yml")
#AutoConfigureTestDatabase(replace = Replace.NONE)
public class GenerateDDL {
#Autowired
private EntityManager em;
#Test
public void generateDDL(){
em.close();
em.getEntityManagerFactory().close();
}
}
I read somewhere that the ddl should be generated during instantiation of EntityManager?!
The referenced classpath:/testproperties/ddlgenerate.yml only contains
spring:
jpa:
properties:
javax:
persistence:
schema-generation:
create-source: metadata
action: create
create-target: create.sql
Log indicates that the properties are loaded. The test is green but still no ddl file.
So how to get a ddl file generated (preferable during build)?
The problem is that #TestPropertySource does not support yaml files as source. All is working as soon as yaml is converted to properties file.
I'm running into following issue while trying to configure solver with BRUTE_FORCE for multiple entity classes:
Caused by:
com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$DuplicateFieldException: Duplicate field entitySelectorConfig
Following is the configuration:
<solver>
...
<exhaustiveSearch>
<exhaustiveSearchType>BRUTE_FORCE</exhaustiveSearchType>
<entitySelector>
<entityClass>PlanningEntity_ClassA</entityClass>
</entitySelector>
<entitySelector>
<entityClass>PlanningEntity_ClassB</entityClass>
</entitySelector>
</exhaustiveSearch>
</solver>
This configuration works fine if single entity is specified.
If no entity is specified, following is the exception:
The phaseConfig (ExhaustiveSearchPhaseConfig) has no entitySelector configured and because there are multiple in the entityClassSet ...
I am trying to connect to two postgresql databases from a single Grails 3.1.5 application, my application.yml looks like this:
hibernate:
cache:
queries: false
use_second_level_cache: true
use_query_cache: false
region.factory_class: org.hibernate.cache.ehcache.EhCacheRegionFactory
dataSources:
dataSource:
pooled: true
jmxExport: true
driverClassName: org.postgresql.Driver
username: username
password: password
dialect: net.kaleidos.hibernate.PostgresqlExtensionsDialect
dataSource_two:
pooled: true
jmxExport: true
driverClassName: org.postgresql.Driver
username: username
password: password
dialect: net.kaleidos.hibernate.PostgresqlExtensionsDialect
environments:
development:
dataSources:
dataSource:
dbCreate: update
url: jdbc:postgresql://localhost:5432/dbone
dataSource_two:
dbCreate: update
url: jdbc:postgresql://localhost:5432/dbtwo
test:
dataSource:
dbCreate: update
url: jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
production:
dataSource:
dbCreate: update
url: jdbc:h2:./prodDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
I am getting this error and cannot start the application
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'transactionManager_dataSource_two' while setting constructor argument with key [1]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager_dataSource_two': Cannot resolve reference to bean 'sessionFactory_dataSource_two' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory_dataSource_two': Invocation of init method failed; nested exception is org.hibernate.cache.NoCacheRegionFactoryAvailableException: Second-level cache is used in the application, but property hibernate.cache.region.factory_class is not given; please either disable second level cache or set correct region factory using the hibernate.cache.region.factory_class setting and make sure the second level cache provider (hibernate-infinispan, e.g.) is available on the classpath.
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:359)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveManagedList(BeanDefinitionValueResolver.java:382)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:157)
at org.springframework.beans.factory.support.ConstructorResolver.resolveConstructorArguments(ConstructorResolver.java:634)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:140)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1143)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1046)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
at org.grails.transaction.TransactionManagerPostProcessor.initialize(TransactionManagerPostProcessor.java:75)
at org.grails.transaction.TransactionManagerPostProcessor.setBeanFactory(TransactionManagerPostProcessor.java:53)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeAwareMethods(AbstractAutowireCapableBeanFactory.java:1597)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1565)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)
... 20 common frames omitted
Looks like grails cannot find hibernate.cache.region.factory_class but as you can see I have that property in application.yml. I also checked if the class exists in classpath and it does. Any ideas why I am getting this error ?
the hibernate settings are datasource-specific, too.
so try adding a hibernate_two block with the hibernate settings for your dataSource_two
I updated the grails version to 3.1.9 and used the same exact configuration and it worked. The only thing I changed is was 'org.hibernate.cache.ehcache.EhCacheRegionFactory' to 'org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory'.
there are a lot of examples of camel and spring dealing with JPA, but I would prefer spring boot autoconfigured data source instead of XML or configuration classes.
However even with
spring:
datasource:
url: jdbc:postgresql://postgres/fooBarBaz
username: fooBarBaz
password: fooBarBaz
jpa:
hibernate:
ddl-auto: update
naming-strategy: org.hibernate.cfg.ImprovedNamingStrategy
set up
The data source is not picked up:
No qualifying bean of type [javax.sql.DataSource] found for dependency: expected at least 1 bean which qualifies as auto wire candidate for this dependency.