Axon : While Enabling JPA repository giving errorTokenEntry is not mapped - java

In order to use multiple database in Springboot application having Axon framework.
I used #EnableJpaRepositories after which I started getting following error
java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: TokenEntry is not mapped [SELECT te.segment FROM TokenEntry te WHERE te.processorName = :processorName ORDER BY te.segment ASC]
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:138)
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:181)
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:188)
at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:725)
at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:816)
at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:23)
at sun.reflect.GeneratedMethodAccessor107.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:366)
at com.sun.proxy.$Proxy150.createQuery(Unknown Source)
at sun.reflect.GeneratedMethodAccessor107.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:314)
at com.sun.proxy.$Proxy150.createQuery(Unknown Source)
at org.axonframework.eventhandling.tokenstore.jpa.JpaTokenStore.fetchSegments(JpaTokenStore.java:194)
at org.axonframework.eventhandling.TrackingEventProcessor$WorkerLauncher.run(TrackingEventProcessor.java:1195)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: TokenEntry is not mapped [SELECT te.segment FROM TokenEntry te WHERE te.processorName = :processorName ORDER BY te.segment ASC]
at org.hibernate.hql.internal.ast.QuerySyntaxException.generateQueryException(QuerySyntaxException.java:79)
at org.hibernate.QueryException.wrapWithQueryString(QueryException.java:103)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:220)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:144)
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:113)
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:73)
at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:162)
at org.hibernate.internal.AbstractSharedSessionContract.getQueryPlan(AbstractSharedSessionContract.java:604)
at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:716)
... 15 common frames omitted
Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: TokenEntry is not mapped
at org.hibernate.hql.internal.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:169)
at org.hibernate.hql.internal.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:91)
at org.hibernate.hql.internal.ast.tree.FromClause.addFromElement(FromClause.java:79)
... 21 common frames omitted
Following is the way I enabled JPA repositories
#Data
#Configuration
#EnableScheduling
#ConfigurationProperties(prefix = "spring.datasource")
#EnableJpaRepositories(
basePackages = {"com.mypackage","org.axonframework.eventhandling.tokenstore.jpa"},
entityManagerFactoryRef = "postgresEntityManager",
transactionManagerRef = "postgresTransactionManager")}
)
public class PostgresConfiguration {

Interesting, I'd assume this to work out of the box really.
Are you using Spring Boot by any chance #tijo? To be honest I am assuming not, but it does give me a suggestion.
Axon Framework uses the #RegisterDefaultEntities annotation to register the required entities automatically for you when you're using the axon-springboot-starter. You can see this being done on the JpaAutoConfiguration class.
What's being done there is the following:
#RegisterDefaultEntities(packages = {
"org.axonframework.eventhandling.tokenstore",
"org.axonframework.modelling.saga.repository.jpa"
})
public class JpaAutoConfiguration { ... }
Would you mind checking whether that works? Main difference I see in your config is that you're only using the "org.axonframework.eventhandling.tokenstorejpa" base package.
Let us know whether this does the trick!

Related

Spring Boot: Change the attribute for #Table in Entity class

I have on spring boot app having one entity class which is linked to my database table also I used sequence on that table.
So I use Table annotation as well as SequenceGenerator annotation on my Entity class with hard-coded value, like this:
#Entity
#Primary
#Table(name = "tbl_name", schema = "public")
//#Table(name = "tbl_name_dev", schema = "public")
public class PoJoClass implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#SequenceGenerator(name = "tbl_name_id_seq", sequenceName = "tbl_name_id_seq", allocationSize = 1)
#GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "tbl_name_id_seq")
// PoJo attributes
// Setter/Getter
}
Which I wanted to implement in way where I can set both the table and sequence as parameter for each profile like dev and prod. As for testing we have table name different then prod in some cases.
Also, I used the same table name in my repository class with #Query annotation, which look like this:
#Query(value = "SELECT * FROM tbl_name WHERE col1 <> ?1", nativeQuery = true)
PoJoClass getLatestRecordForCompositeKey(String col1);
Finding out same way to set both as parameter on each profile base.
Update:
Alex, route me to follow this link. And I checked and tried implementing the same in my code but I might not understand that logic due to that it is failing or nothing which I did not get properly. Cloud anyone please help on this.
I wanted to use property: from my application property file and i added the same there.
As that link suggested added the Configuration class.
#Configuration
public class TableNameConfig {
#Value("${config.table.name}")
private String configTableName;
#Value("${visits.table.name}")
private String visitsTableName;
#Bean
public PhysicalNamingStrategyStandardImpl physicalNamingStrategyStandard(){
return new PhysicalNamingImpl();
}
class PhysicalNamingImpl extends PhysicalNamingStrategyStandardImpl {
#Override
public Identifier toPhysicalTableName(Identifier name, JdbcEnvironment context) {
switch (name.getText()) {
case "PoJoClass":
return new Identifier(configTableName, name.isQuoted());
case "Visits":
return new Identifier(visitsTableName, name.isQuoted());
case "Result":
default:
return super.toPhysicalTableName(name, context);
}
}
}
}
So that I can later use the property like this:
#Table(name = "${config.table.name}", schema = "public")
But I am getting this error, I think I am not able to resolve that property, not understood where to change and what:
2019-12-07 15:57:46.649 INFO 21840 --- [ restartedMain]
org.hibernate.type.BasicTypeRegistry : HHH000270: Type
registration [java.util.UUID] overrides previous :
org.hibernate.type.UUIDBinaryType#233cf9c7 Hibernate: create table
public.${config.table.name} (id serial not null, active_flag
varchar(255), updated_datetime TIMESTAMP WITHOUT TIME ZONE, primary
key (id))
2019-12-07 15:57:50.561 WARN 21840 --- [ restartedMain]
o.h.t.s.i.ExceptionHandlerLoggedImpl : GenerationTarget
encountered exception accepting command : Error executing DDL "create
table public.${config.table.name} (id serial not null, active_flag
varchar(255), updated_datetime TIMESTAMP WITHOUT TIME ZONE, primary
key (id))" via JDBC Statement
org.hibernate.tool.schema.spi.CommandAcceptanceException: Error
executing DDL "create table public.${config.table.name} (id serial not
null, active_flag varchar(255), updated_datetime TIMESTAMP WITHOUT
TIME ZONE, primary key (id))" via JDBC Statement at
org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:67)
~[hibernate-core-5.3.10.Final.jar:5.3.10.Final] at
org.hibernate.tool.schema.internal.AbstractSchemaMigrator.applySqlString(AbstractSchemaMigrator.java:559)
[hibernate-core-5.3.10.Final.jar:5.3.10.Final] at
org.hibernate.tool.schema.internal.AbstractSchemaMigrator.applySqlStrings(AbstractSchemaMigrator.java:504)
[hibernate-core-5.3.10.Final.jar:5.3.10.Final] at
org.hibernate.tool.schema.internal.AbstractSchemaMigrator.createTable(AbstractSchemaMigrator.java:277)
[hibernate-core-5.3.10.Final.jar:5.3.10.Final] at
org.hibernate.tool.schema.internal.GroupedSchemaMigratorImpl.performTablesMigration(GroupedSchemaMigratorImpl.java:71)
[hibernate-core-5.3.10.Final.jar:5.3.10.Final] at
org.hibernate.tool.schema.internal.AbstractSchemaMigrator.performMigration(AbstractSchemaMigrator.java:207)
[hibernate-core-5.3.10.Final.jar:5.3.10.Final] at
org.hibernate.tool.schema.internal.AbstractSchemaMigrator.doMigration(AbstractSchemaMigrator.java:114)
[hibernate-core-5.3.10.Final.jar:5.3.10.Final] at
org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.java:183)
[hibernate-core-5.3.10.Final.jar:5.3.10.Final] at
org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaManagementToolCoordinator.java:72)
[hibernate-core-5.3.10.Final.jar:5.3.10.Final] at
org.hibernate.internal.SessionFactoryImpl.(SessionFactoryImpl.java:310)
[hibernate-core-5.3.10.Final.jar:5.3.10.Final] at
org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:467)
[hibernate-core-5.3.10.Final.jar:5.3.10.Final] at
org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:939)
[hibernate-core-5.3.10.Final.jar:5.3.10.Final] at
org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:57)
[spring-orm-5.1.9.RELEASE.jar:5.1.9.RELEASE] at
org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365)
[spring-orm-5.1.9.RELEASE.jar:5.1.9.RELEASE] at
org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:390)
[spring-orm-5.1.9.RELEASE.jar:5.1.9.RELEASE] at
org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:377)
[spring-orm-5.1.9.RELEASE.jar:5.1.9.RELEASE] at
org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:341)
[spring-orm-5.1.9.RELEASE.jar:5.1.9.RELEASE] at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1837)
[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE] at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1774)
[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE] at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:593)
[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE] at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515)
[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE] at
org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320)
[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE] at
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE] at
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318)
[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE] at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE] at
org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1105)
~[spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE] at
org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867)
~[spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE] at
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549)
~[spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE] at
org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141)
~[spring-boot-2.1.7.RELEASE.jar:2.1.7.RELEASE] at
org.springframework.boot.SpringApplication.refresh(SpringApplication.java:743)
~[spring-boot-2.1.7.RELEASE.jar:2.1.7.RELEASE] at
org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:390)
~[spring-boot-2.1.7.RELEASE.jar:2.1.7.RELEASE] at
org.springframework.boot.SpringApplication.run(SpringApplication.java:312)
~[spring-boot-2.1.7.RELEASE.jar:2.1.7.RELEASE] at
org.springframework.boot.SpringApplication.run(SpringApplication.java:1214)
~[spring-boot-2.1.7.RELEASE.jar:2.1.7.RELEASE] at
org.springframework.boot.SpringApplication.run(SpringApplication.java:1203)
~[spring-boot-2.1.7.RELEASE.jar:2.1.7.RELEASE] at
com.slb.dataplatform.configurationapi.ConfigurationApiApplication.main(ConfigurationApiApplication.java:12)
~[classes/:na] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
Method) ~[na:1.8.0_201] at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
~[na:1.8.0_201] at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
~[na:1.8.0_201] at java.lang.reflect.Method.invoke(Method.java:498)
~[na:1.8.0_201] at
org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
~[spring-boot-devtools-2.1.7.RELEASE.jar:2.1.7.RELEASE] Caused by:
org.postgresql.util.PSQLException: ERROR: syntax error at or near "$"
Position: 21 at
org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2476)
~[postgresql-42.1.1.jar:42.1.1] at
org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2189)
~[postgresql-42.1.1.jar:42.1.1] at
org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:300)
~[postgresql-42.1.1.jar:42.1.1] at
org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:428)
~[postgresql-42.1.1.jar:42.1.1] at
org.postgresql.jdbc.PgStatement.execute(PgStatement.java:354)
~[postgresql-42.1.1.jar:42.1.1] at
org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:301)
~[postgresql-42.1.1.jar:42.1.1] at
org.postgresql.jdbc.PgStatement.executeCachedSql(PgStatement.java:287)
~[postgresql-42.1.1.jar:42.1.1] at
org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:264)
~[postgresql-42.1.1.jar:42.1.1] at
org.postgresql.jdbc.PgStatement.execute(PgStatement.java:260)
~[postgresql-42.1.1.jar:42.1.1] at
com.zaxxer.hikari.pool.ProxyStatement.execute(ProxyStatement.java:95)
~[HikariCP-3.2.0.jar:na] at
com.zaxxer.hikari.pool.HikariProxyStatement.execute(HikariProxyStatement.java)
~[HikariCP-3.2.0.jar:na] at
org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:54)
~[hibernate-core-5.3.10.Final.jar:5.3.10.Final] ... 39 common frames
omitted
I think I am not able to override method toPhysicalTableName properly, please let me know what is wrong I did.
Help is highly appreciated. thanks in advance.

replace real data source with embedded database for tests

I have two data sources in my spring boot application. both declared like:
#Lazy
#Configuration
#EnableJpaRepositories(
basePackages = "com.nws.signer.db.dao",
entityManagerFactoryRef = "signerEntityManager",
transactionManagerRef = "signerTransactionManager"
)
#EnableTransactionManagement
public class SignerJPAConfig {
private Map<String, String> sig_db_props;
private String sig_url;
#Autowired
private VedProfiledPropsSource p;
#PostConstruct
public void init() {
sig_db_props = new HashMap<>();
sig_url =
String.format("jdbc:postgresql://%s:%s/%s", p.getSigDbHost(), p.getSigDbPort(), p.getSigDbName());
sig_db_props.put("hibernate.dialect", "org.hibernate.dialect.PostgreSQL92Dialect");
sig_db_props.put("javax.persistence.jdbc.url", sig_url);
sig_db_props.put("javax.persistence.jdbc.user", p.getSigDbUser());
sig_db_props.put("javax.persistence.jdbc.password", p.getSigDbPassword());
sig_db_props.put("hibernate.connection.autocommit", "true");
sig_db_props.put("hibernate.cache.use_second_level_cache", "false");
sig_db_props.put("hibernate.hbm2ddl.auto", "update");
}
...
}
so I am using VedProfiledPropsSource which is #ConfigurationProperties with properties for specific profile used. after initializing jpaPropertyMap in postConstruct I am setting it to LocalContainerEntityManagerFactoryBean which is declared as a bean alongside with DataSource and PlatformTransactionManager. same for the other data source.
Now I want to use embedded-database-spring-test dependency:
<dependency>
<groupId>io.zonky.test</groupId>
<artifactId>embedded-database-spring-test</artifactId>
<version>1.5.1</version>
<scope>test</scope>
</dependency>
to bootstrap the embedded database for tests and connect my data sources to this database. the build machine doesn't have a database so I want to use this within the test scope.
my e2e test class starts with:
#TestInstance(TestInstance.Lifecycle.PER_CLASS)
#ExtendWith(SpringExtension.class)
#Transactional
#SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = {VedicaConfig.class})
#AutoConfigureMockMvc
#ActiveProfiles("mvntest")
#FlywayTest
#TestMethodOrder(MethodOrderer.OrderAnnotation.class)
#AutoConfigureEmbeddedDatabase(beanName = "signerJPAConfig")
public class RESTTest {
...
}
so I was thinking it will bootstrap the in-memory postgresql db and replace (by magic) the named data source anf flyway will apply migration scripts.
now I am missing/misunderstanding something as this is not happening and my data source configuration bean is still trying to connect to the database with credentials correctly red from profiled property file. and it fails with:
2019-10-07 00:05:53.785 ERROR 40358 --- [ prefetching-3] org.postgresql.Driver : Connection error:
org.postgresql.util.PSQLException: Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:245) ~[postgresql-42.2.2.jar:42.2.2]
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49) ~[postgresql-42.2.2.jar:42.2.2]
at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:195) ~[postgresql-42.2.2.jar:42.2.2]
at org.postgresql.Driver.makeConnection(Driver.java:452) ~[postgresql-42.2.2.jar:42.2.2]
at org.postgresql.Driver.connect(Driver.java:254) ~[postgresql-42.2.2.jar:42.2.2]
at java.sql.DriverManager.getConnection(DriverManager.java:664) [na:1.8.0_66]
at java.sql.DriverManager.getConnection(DriverManager.java:208) [na:1.8.0_66]
at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriverManager(DriverManagerDataSource.java:154) [spring-jdbc-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriver(DriverManagerDataSource.java:145) [spring-jdbc-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnectionFromDriver(AbstractDriverBasedDataSource.java:205) [spring-jdbc-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnection(AbstractDriverBasedDataSource.java:169) [spring-jdbc-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at org.flywaydb.core.internal.jdbc.JdbcUtils.openConnection(JdbcUtils.java:56) [flyway-core-5.2.4.jar:na]
at org.flywaydb.core.internal.database.DatabaseFactory.createDatabase(DatabaseFactory.java:72) [flyway-core-5.2.4.jar:na]
at org.flywaydb.core.Flyway.execute(Flyway.java:1670) [flyway-core-5.2.4.jar:na]
at org.flywaydb.core.Flyway.migrate(Flyway.java:1356) [flyway-core-5.2.4.jar:na]
at io.zonky.test.db.flyway.DefaultFlywayDataSourceContext$FlywayDatabasePreparer.prepare(DefaultFlywayDataSourceContext.java:173) [embedded-database-spring-test-1.5.1.jar:na]
at io.zonky.test.db.provider.impl.ZonkyPostgresDatabaseProvider$DatabaseInstance$DatabaseTemplate.<init>(ZonkyPostgresDatabaseProvider.java:147) [embedded-database-spring-test-1.5.1.jar:na]
at io.zonky.test.db.provider.impl.ZonkyPostgresDatabaseProvider$DatabaseInstance$DatabaseTemplate.<init>(ZonkyPostgresDatabaseProvider.java:136) [embedded-database-spring-test-1.5.1.jar:na]
at io.zonky.test.db.provider.impl.ZonkyPostgresDatabaseProvider$DatabaseInstance$1.load(ZonkyPostgresDatabaseProvider.java:120) [embedded-database-spring-test-1.5.1.jar:na]
at io.zonky.test.db.provider.impl.ZonkyPostgresDatabaseProvider$DatabaseInstance$1.load(ZonkyPostgresDatabaseProvider.java:118) [embedded-database-spring-test-1.5.1.jar:na]
at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3542) [signer-1.0-SNAPSHOT.jar:na]
at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2323) [signer-1.0-SNAPSHOT.jar:na]
at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2286) [signer-1.0-SNAPSHOT.jar:na]
at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2201) [signer-1.0-SNAPSHOT.jar:na]
at com.google.common.cache.LocalCache.get(LocalCache.java:3953) [signer-1.0-SNAPSHOT.jar:na]
at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:3957) [signer-1.0-SNAPSHOT.jar:na]
at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4875) [signer-1.0-SNAPSHOT.jar:na]
at com.google.common.cache.LocalCache$LocalLoadingCache.getUnchecked(LocalCache.java:4881) [signer-1.0-SNAPSHOT.jar:na]
at io.zonky.test.db.provider.impl.ZonkyPostgresDatabaseProvider$DatabaseInstance.getTemplate(ZonkyPostgresDatabaseProvider.java:133) [embedded-database-spring-test-1.5.1.jar:na]
at io.zonky.test.db.provider.impl.ZonkyPostgresDatabaseProvider.getDatabase(ZonkyPostgresDatabaseProvider.java:94) [embedded-database-spring-test-1.5.1.jar:na]
at io.zonky.test.db.provider.impl.PrefetchingDatabaseProvider$PrefetchingTask.lambda$new$0(PrefetchingDatabaseProvider.java:252) [embedded-database-spring-test-1.5.1.jar:na]
at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266) ~[na:1.8.0_66]
at java.util.concurrent.FutureTask.run(FutureTask.java) ~[na:1.8.0_66]
at io.zonky.test.db.provider.impl.PrefetchingDatabaseProvider$PrefetchingTask.run(PrefetchingDatabaseProvider.java:259) [embedded-database-spring-test-1.5.1.jar:na]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) ~[na:1.8.0_66]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) ~[na:1.8.0_66]
at java.lang.Thread.run(Thread.java:745) ~[na:1.8.0_66]
Caused by: java.net.ConnectException: Connection refused
please advice me what should I do in order to replace my real data source with embedded one?
Thanks
For me, this worked. If you have a Spring boot project with JPA (Entities and Repositories), you can create the following test:
#ExtendWith(SpringExtension.class)
#DataJpaTest(excludeAutoConfiguration = { LiquibaseAutoConfiguration.class })
#AutoConfigureEmbeddedDatabase
#ActiveProfiles("junit")
public class JpaTest {
#Autowired
private MyRepository repo;
#Test
public void create(){
...
}
Be sure to set the following properties:
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=create
spring.jpa.database=POSTGRESQL

Error during Apache Ignite cache creation

I'm trying to create cache (in fact almost copy-pasting from the example code to understand how it works) and simply write/read some data. I'm able to start Ignite nodes but when but getting an error with following stack trace during attempt to create the cache:
Exception in thread "main" class org.apache.ignite.IgniteException: Failed to instantiate Spring XML application context (make sure all classes used in Spring configuration are present at CLASSPATH) [springUrl=file:/C:/temp/apache-ignite-fabric-1.7.0-bin/examples/config/example-ignite.xml]
at org.apache.ignite.internal.util.IgniteUtils.convertException(IgniteUtils.java:881)
at org.apache.ignite.Ignition.start(Ignition.java:349)
at ignite.HelloWorld.CacheApiExample.main(CacheApiExample.java:18)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Caused by: class org.apache.ignite.IgniteCheckedException: Failed to instantiate Spring XML application context (make sure all classes used in Spring configuration are present at CLASSPATH) [springUrl=file:/C:/temp/apache-ignite-fabric-1.7.0-bin/examples/config/example-ignite.xml]
at org.apache.ignite.internal.util.spring.IgniteSpringHelperImpl.applicationContext(IgniteSpringHelperImpl.java:370)
at org.apache.ignite.internal.util.spring.IgniteSpringHelperImpl.loadConfigurations(IgniteSpringHelperImpl.java:87)
at org.apache.ignite.internal.util.spring.IgniteSpringHelperImpl.loadConfigurations(IgniteSpringHelperImpl.java:81)
at org.apache.ignite.internal.IgnitionEx.loadConfigurations(IgnitionEx.java:596)
at org.apache.ignite.internal.IgnitionEx.start(IgnitionEx.java:774)
at org.apache.ignite.internal.IgnitionEx.start(IgnitionEx.java:705)
at org.apache.ignite.internal.IgnitionEx.start(IgnitionEx.java:576)
at org.apache.ignite.internal.IgnitionEx.start(IgnitionEx.java:546)
at org.apache.ignite.Ignition.start(Ignition.java:346)
... 6 more
Caused by: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.h2.jdbcx.JdbcDataSource] for bean with name 'h2-example-db' defined in URL [file:/C:/temp/apache-ignite-fabric-1.7.0-bin/examples/config/example-default.xml]; nested exception is java.lang.ClassNotFoundException: org.h2.jdbcx.JdbcDataSource
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1325)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:623)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:592)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1394)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:957)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:705)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
at org.apache.ignite.internal.util.spring.IgniteSpringHelperImpl.applicationContext(IgniteSpringHelperImpl.java:364)
... 14 more
Caused by: java.lang.ClassNotFoundException: org.h2.jdbcx.JdbcDataSource
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.springframework.util.ClassUtils.forName(ClassUtils.java:246)
at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:395)
at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1346)
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1317)
... 22 more
The code is:
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCache;
import org.apache.ignite.IgniteException;
import org.apache.ignite.Ignition;
import org.apache.ignite.cache.CacheAtomicityMode;
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.spi.indexing.IndexingQueryFilter;
/**
* Created by s.kachkin on 9/30/2016.
*/
public class CacheApiExample {
public static void main(String[] args) throws IgniteException {
Ignition.setClientMode(true);
try(Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
CacheConfiguration<Integer, String> cfg = new CacheConfiguration<>();
cfg.setName("Democache");
cfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
IgniteCache<Integer, String> cache = ignite.getOrCreateCache(cfg);
cache.put(1, "cache item 1");
cache.put(2, "cache item 2");
System.out.println(cache.get(1));
System.out.println(cache.get(2));
}
}
}
Please be sure that $IGNITE_HOME/libs/ignite-indexing/* is in the classpath.
Or your project must contain dependency on H2:
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.3.175</version>
</dependency>

WebSphere 8,5 spring job with remote ejb xa transaction error

I'm working with spring batch and WebSphere 8.5. Batch uses a remote ejb in xa distribuited transaction:
org.springframework.transaction.TransactionSystemException: UOWManager transaction processing failed; nested exception is com.ibm.wsspi.uow.UOWException: javax.transaction.SystemException
at org.springframework.transaction.jta.WebSphereUowTransactionManager.execute(WebSphereUowTransactionManager.java:297) ~[spring-tx-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:127) ~[spring-tx-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:271) ~[spring-batch-core-3.0.3.RELEASE.jar:3.0.3.RELEASE]
at org.spr....
Caused by: com.ibm.wsspi.uow.UOWException: javax.transaction.SystemException
at com.ibm.ws.uow.embeddable.EmbeddableUOWManagerImpl.runUnderNewUOW(EmbeddableUOWManagerImpl.java:823) ~[com.ibm.ws.runtime.jar:na]
at com.ibm.ws.uow.embeddable.EmbeddableUOWManagerImpl.runUnderUOW(EmbeddableUOWManagerImpl.java:370) ~[com.ibm.ws.runtime.jar:na]
at org.springframework.transaction.jta.WebSphereUowTransactionManager.execute(WebSphereUowTransactionManager.java:290) ~[spring-tx-4.1.6.RELEASE.jar:4.1.6.RELEASE]
... 18 common frames omitted
Caused by: javax.transaction.SystemException: null
at com.ibm.tx.jta.impl.TransactionImpl.stage3CommitProcessing(TransactionImpl.java:1251) ~[com.ibm.tx.jta.jar:na]
at com.ibm.tx.jta.impl.TransactionImpl.processCommit(TransactionImpl.java:1042) ~[com.ibm.tx.jta.jar:na]
at com.ibm.tx.jta.impl.TransactionImpl.commit(TransactionImpl.java:963) ~[com.ibm.tx.jta.jar:na]
at com.ibm.ws.tx.jta.TranManagerImpl.commit(TranManagerImpl.java:439) ~[com.ibm.ws.runtime.jar:na]
at com.ibm.tx.jta.impl.TranManagerSet.commit(TranManagerSet.java:191) ~[com.ibm.tx.jta.jar:na]
at com.ibm.ws.uow.UOWManagerImpl.uowCommit(UOWManagerImpl.java:807) ~[com.ibm.ws.runtime.jar:na]
at com.ibm.ws.uow.embeddable.EmbeddableUOWManagerImpl.uowEnd(EmbeddableUOWManagerImpl.java:881) ~[com.ibm.ws.runtime.jar:na]
at com.ibm.ws.uow.UOWManagerImpl.uowEnd(UOWManagerImpl.java:782) ~[com.ibm.ws.runtime.jar:na]
at com.ibm.ws.uow.embeddable.EmbeddableUOWManagerImpl.runUnderNewUOW(EmbeddableUOWManagerImpl.java:818) ~[com.ibm.ws.runtime.jar:na]
Any ideas?
Thanks
Giancarlo
after Greycon's help, I resolved disabling security on transaction service.
For WAS 8.5, the procedure is the same as that of WAS 7 described in the following link:
https://www-01.ibm.com/support/knowledgecenter/SSWSR9_11.4.0/com.ibm.mdmhs.bil_install.doc/t_disable_protocol_security.html

Error in setting Hibernate Configuration

I am getting error coming in to configure hibernate for postgresql database -
Error Log Details -
org.hibernate.HibernateException: could not instantiate RegionFactory [org.hibernate.cache.impl.bridge.RegionFactoryCacheProviderBridge]
at org.hibernate.cfg.SettingsFactory.createRegionFactory(SettingsFactory.java:402)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:270)
at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2163)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2159)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1383)
at org.hibernate.console.ConsoleConfiguration$5.execute(ConsoleConfiguration.java:278)
at org.hibernate.console.execution.DefaultExecutionContext.execute(DefaultExecutionContext.java:63)
at org.hibernate.console.ConsoleConfiguration.execute(ConsoleConfiguration.java:107)
at org.hibernate.console.ConsoleConfiguration.buildSessionFactory(ConsoleConfiguration.java:273)
at org.hibernate.eclipse.console.workbench.LazySessionFactoryAdapter.getChildren(LazySessionFactoryAdapter.java:43)
at org.hibernate.eclipse.console.workbench.BasicWorkbenchAdapter.getChildren(BasicWorkbenchAdapter.java:100)
at org.hibernate.eclipse.console.workbench.BasicWorkbenchAdapter.fetchDeferredChildren(BasicWorkbenchAdapter.java:106)
at org.eclipse.ui.progress.DeferredTreeContentManager$1.run(DeferredTreeContentManager.java:235)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.hibernate.cfg.SettingsFactory.createRegionFactory(SettingsFactory.java:397)
... 13 more
Caused by: org.hibernate.cache.CacheException: could not instantiate CacheProvider [org.hibernate.cache.internal.NoCacheProvider]
at org.hibernate.cache.impl.bridge.RegionFactoryCacheProviderBridge.<init>(RegionFactoryCacheProviderBridge.java:66)
... 18 more
Caused by: java.lang.ClassNotFoundException: org.hibernate.cache.internal.NoCacheProvider cannot be found by org.hibernate.eclipse.libs_3.7.1.Final-v20131205-0918-B107
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:501)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:421)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:412)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:191)
at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:192)
at org.hibernate.cache.impl.bridge.RegionFactoryCacheProviderBridge.<init>(RegionFactoryCacheProviderBridge.java:63)
... 18 more
UPDATE:
After the changes mentioned by #ConMan, I am getting a new error at the same place -
org.hibernate.HibernateException: Could not instantiate dialect class
at org.hibernate.dialect.resolver.DialectFactory.constructDialect(DialectFactory.java:163)
at org.hibernate.dialect.resolver.DialectFactory.buildDialect(DialectFactory.java:109)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:146)
at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2163)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2155)
at org.hibernate.console.ConsoleConfiguration$6.execute(ConsoleConfiguration.java:430)
at org.hibernate.console.execution.DefaultExecutionContext.execute(DefaultExecutionContext.java:63)
at org.hibernate.console.ConsoleConfiguration.execute(ConsoleConfiguration.java:107)
at org.hibernate.console.ConsoleConfiguration.getSettings(ConsoleConfiguration.java:428)
at org.hibernate.eclipse.console.workbench.LazyDatabaseSchemaWorkbenchAdapter$2.execute(LazyDatabaseSchemaWorkbenchAdapter.java:119)
at org.hibernate.console.execution.DefaultExecutionContext.execute(DefaultExecutionContext.java:63)
at org.hibernate.console.ConsoleConfiguration.execute(ConsoleConfiguration.java:107)
at org.hibernate.eclipse.console.workbench.LazyDatabaseSchemaWorkbenchAdapter.readDatabaseSchema(LazyDatabaseSchemaWorkbenchAdapter.java:115)
at org.hibernate.eclipse.console.workbench.LazyDatabaseSchemaWorkbenchAdapter.getChildren(LazyDatabaseSchemaWorkbenchAdapter.java:65)
at org.hibernate.eclipse.console.workbench.BasicWorkbenchAdapter.fetchDeferredChildren(BasicWorkbenchAdapter.java:106)
at org.eclipse.ui.progress.DeferredTreeContentManager$1.run(DeferredTreeContentManager.java:235)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)
Caused by: java.lang.ClassCastException: org.hibernate.dialect.PostgreSQLDialect cannot be cast to org.hibernate.dialect.Dialect
at org.hibernate.dialect.resolver.DialectFactory.constructDialect(DialectFactory.java:157)
... 16 more
The problem is here:
Caused by: java.lang.ClassNotFoundException: org.hibernate.cache.internal.NoCacheProvider cannot be found by org.hibernate.eclipse.libs_3.7.1.Final-v20131205-0918-B107
This basically means that the implementation of hibernate you are using (org.hibernate.eclipse.libs...) does not contain the class NoCacheProvider.class.
An implementation of the NoCacheProvider can be found in the following dependencies:
hibernate-core - 3.6.0.Final, 3.5.0-Final, 3.3.0.SP1, 3.3.0.GA
com.springsource.org.hibernate - 3.3.2, 3.3.1, 3.2.6
hibernate-core - 3.6.10.Final-patched-play-1.2.5, 3.6.1.Final-patched-play-1.2, 3.5.6-Final-patched-play-1.1.1, 3.5.6-Final-patched-play-1.1
hibernate - 3.2.7.ga, 3.2.6.ga, 3.2.5.ga, 3.2.4.sp1, 3.2.4.ga,
3.2.3.ga, 3.2.2.ga, 3.2.1.ga, 3.2.0.ga, 3.2.0.cr3, 3.2.0.cr2, 3.2.0.cr1, 3.1.3, 3.1.2, 3.1.1, 3.1
hibernate - 3.1beta3, 3.1beta2, 3.1beta1, 3.0.5, 3.0.3
hibernate-all - beta3.SP15
Source: Grep Code
EDIT:
I have just seen that you are using hibernate-core 4.3.0.Final. It would appear that the NoCacheProvider class no longer exists in this version of hibernate. The recommended alternative is to use the following class instead:
org.hibernate.cache.internal.NoCachingRegionFactory

Categories

Resources