Spring-Data-Jdbc with ArcadeDB - spring-data

Using a Spring-Data-JDBC repository and ArcadeDB as persistence, a simple "count()" runs on an error.
2022-07-10 12:54:33.755 DEBUG 14320 --- [ main] o.s.jdbc.support.JdbcTransactionManager : Creating new transaction with name [org.springframework.data.jdbc.repository.support.SimpleJdbcRepository.count]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT,readOnly
2022-07-10 12:54:33.760 DEBUG 14320 --- [ main] o.s.jdbc.support.JdbcTransactionManager : Acquired Connection [org.postgresql.jdbc.PgConnection#9263c54] for JDBC transaction
2022-07-10 12:54:33.797 DEBUG 14320 --- [ main] o.s.jdbc.datasource.DataSourceUtils : Setting JDBC Connection [org.postgresql.jdbc.PgConnection#9263c54] read-only
2022-07-10 12:54:33.802 DEBUG 14320 --- [ main] o.s.jdbc.support.JdbcTransactionManager : Switching JDBC Connection [org.postgresql.jdbc.PgConnection#9263c54] to manual commit
2022-07-10 12:54:34.802 DEBUG 14320 --- [ main] o.s.jdbc.core.JdbcTemplate : Executing SQL query [SELECT COUNT(*) FROM `Team`]
org.springframework.jdbc.BadSqlGrammarException: StatementCallback; bad SQL grammar [SELECT COUNT(*) FROM `Team`]; nested exception is org.postgresql.util.PSQLException: ERROR: Syntax error on parsing query: Encountered " <READ> "READ "" at line 1, column 7. Was expecting one of:
<EOF>
<ISOLATION> ...
";" ...
<ISOLATION> ..
But the same sql-query executed in a plain JdbcTemplate runs succesfully:
jdbcTemplate.execute("select count(*) from `Team`")
I suspect that the error occurs because the repository call runs the sql-statement in a transaction, whereas the plain JdbcTemplate call is invoked without a transaction.
My question is: Can I make ArcadeDB work with a Spring transaction manager? If not, can I use the repositories of Spring Data without transactions?

Your problem might be caused by the release you are using.
Recent versions fixed an annoying bug with the Postgres driver.
From the error, it looks like a "READ" keyword was used.
It could be the Spring Data layer that added it.

Related

Kubernetes java.io.IOException: Broken pipe error

I am trying deploy a pod to a kubernetes 11.2 cluster and seeing this error.
Weird part is that this workers fine on another cluster (different envs) and config is same exact. Only thing, I noticed is with this failing cluster, I felt like the nodes were little slow to login. But everything seems to be deploying correctly, except for this error.
There are no changes to the code or the config to deploy, what could be the reason for this to happen only on this particular cluster and not other envs. (It works on dev, test and pre-prod) doesn't work on prod, totally dazed I am and not sure if this is infrastructure issue possibly to the kubernetes config or the application needs to be able to handle this. another thing is that i don't see the nodes going down or any errors related to the memory or lack of resources, like disk pressure and such.
any advise would be highly appreciated.
2018-09-02 18:29:51.048 INFO 29 --- [-nio-443-exec-6] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2018-09-02 18:29:56.493 ERROR 29 --- [-nio-443-exec-6] c.t.s.est.server.ServletDispatcher : An unexpected error occured while processing a request on the following uri /.well-known/est/App Service/senroll
org.apache.catalina.connector.ClientAbortException: java.io.IOException: Broken pipe
...
Caused by: java.io.IOException: Broken pipe
at sun.nio.ch.FileDispatcherImpl.write0(Native Method) ~[na:1.8.0_171]
at sun.nio.ch.SocketDispatcher.write(SocketDispatcher.java:47) ~[na:1.8.0_171]
...
2018-09-02 18:29:56.499 ERROR 29 --- [-nio-443-exec-6] o.a.c.c.C.[.[.[/].[servletDispatcher] : Servlet.service() for servlet [servletDispatcher] in context with path [] threw exception
java.lang.IllegalStateException: Cannot call sendError() after the response has been committed
at org.apache.catalina.connector.ResponseFacade.sendError(ResponseFacade.java:472) ~[tomcat-embed-core-8.5.16.jar!/:8.5.16]
at com.trilliantnetworks.security.est.server.ServletDispatcher.unexpectedError(ServletDispatcher.java:230) ~[est-servlet-1.0.1-SNAPSHOT.jar!/:na]
at com.trilliantnetworks.security.est.server.ServletDispatcher.doPost(ServletDispatcher.java:211) ~[est-servlet-1.0.1-SNAPSHOT.jar!/:na]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:661) ~[tomcat-embed-core-8.5.16.jar!/:8.5.16]
...
...
2018-09-02 18:29:56.527 ERROR 29 --- [-nio-443-exec-6] o.a.c.c.C.[Tomcat].[localhost] : Exception Processing ErrorPage[errorCode=0, location=/error]
org.apache.catalina.connector.ClientAbortException: java.io.IOException: Broken pipe
at org.apache.catalina.connector.OutputBuffer.doFlush(OutputBuffer.java:321) ~[tomcat-embed-core-8.5.16.jar!/:8.5.16]
at org.apache.catalina.connector.OutputBuffer.flush(OutputBuffer.java:284) ~[tomcat-embed-core-8.5.16.jar!/:8.5.16]
The nodes are fine. They are not going down or anything. I also looked at the events to see if any errors related to memory show up, but unfortunately nothing.
So, I am seeing this error in one of the pods, which installs some things to the database. This is the first step and should not fail
Mainly this is happening, the read timeout. So, I am wondering if there is some kind of timeout that  I can set in the cluster, to wait for the API response, little longer.
2018-09-02 18:33:35.818 INFO 29 --- [ main] c.t.s.c.i.r.impl.ExternalSignerService : Exception while generatePermanentKeyStore:java.net.SocketTimeoutException: Read timed out

Table not found on postresql connection from spring boot 2

I am trying to perform a basic connection between to a local postgresql DB from a very basic SpringBootProject (for training purpose).
# configure postgresql
spring.datasource.platform=postgres
spring.datasource.jdbc-url=jdbc:postgresql://localhost:5432/db
spring.datasource.username=postgres
spring.datasource.password=
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.database-platform = org.hibernate.dialect.PostgreSQL94Dialect
spring.jpa.hibernate.ddl-auto=none
So far, I have managed to have it compile and run... but when I am trying to access my DB, I get a "Table "FILMS" not found" error (org.h2.jdbc.JdbcSQLException). When I insert data from a data.sql, I get the inserted movies. But without this initializer, I cannot get data from my db...
Table "FILMS" not found; SQL statement:
select film0_.code as
code1_0_, film0_.date_prod as date_pro2_0_, film0_.did as did3_0_,
film0_.kind as kind4_0_, film0_.title as title5_0_ from films film0_
[42102-197]
2018-07-26 12:24:18.151 ERROR 10376 --- [nio-9000-exec-1]
o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for
servlet [dispatcherServlet] in context with path [] threw exception
[Request processing failed; nested exception is
org.springframework.dao.InvalidDataAccessResourceUsageException: could
not prepare statement; SQL [select film0_.code as code1_0_,
film0_.date_prod as date_pro2_0_, film0_.did as did3_0_, film0_.kind
as kind4_0_, film0_.title as title5_0_ from films film0_]; nested
exception is org.hibernate.exception.SQLGrammarException: could not
prepare statement] with root cause
org.h2.jdbc.JdbcSQLException: Table "FILMS" non trouvée
Spring boot is in version 2.03 RELEASE; both postgresql connector AND server's ones are 9.4.
I am using spring boot parent starter, as well as data-jpa-starter (with no extra hibernate/jpa depencies defined).
The source code is here
My postresql server is up, the database "db" exists, and its table public."FILMS" is full of data...
Any idea on what I am doing (or undestanding) wrong?
In your application properties file try
spring.jpa.hibernate.ddl-auto=validate
It will try to check the table in your db

spring-boot configure hibernate-ogm for MongoDB

APPLICATION FAILED TO START
Description:
Cannot determine embedded database driver class for database type NONE
Action:
If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (the profiles "local" are currently active).
2016-11-10 18:36:52.335 ERROR 1288 --- [ main] o.s.test.context.TestContextManager : Caught exception while allowing TestExecutionListener [org.springframework.test.context.web.ServletTestExecutionListener#d83da2e] to prepare test instance [com.example.DemoApplicationTests#1f68e4e8]
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124) ~[spring-test-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83) ~[spring-test-4.3.4.RELEASE.jar:4.3.4.RELEASE]

How to create a large object (CLOB) in a HSQLDB resource database?

I have created a HSQLDB (version 2.3.3) database preloaded with data and bundled it up as a resource (db.properties and db.script) to be used by automated tests where I do not need the data generated by the tests to be saved back to disk. This works fine for most of the JPA entities I have (all CRUD operations work as expected). However, I have two entities that include a column annotated with '#Lob' where I cannot create new entities because HSQLDB fails saying 'the table data is read only'.
I've read through the documentation about Large Objects but it doesn't describe the behaviour when using a resource database. I'm guessing HSQLDB is trying to create 'db.lobs' but it can't because effectively files_readonly=true.
Does anyone know if it is possible to create an entity with a 'large object' column with a HSQLDB resource database?
The stack trace is:
WARN 12-09-2016 00:57:26 - SQL Error: -458, SQLState: S1000
ERROR 12-09-2016 00:57:26 - org.hsqldb.HsqlException: The table data is read only
javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not execute statement
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1763)
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1677)
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1683)
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:1338)
..app classes...
Caused by: org.hibernate.exception.GenericJDBCException: could not execute statement
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:54)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:126)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:112)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:211)
at org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch.addToBatch(NonBatchingBatch.java:62)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3124)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3581)
at org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:104)
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:465)
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:351)
at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:350)
at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:56)
at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1258)
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:1335)
... 29 more
Caused by: java.sql.SQLException: org.hsqldb.HsqlException: The table data is read only
at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
at org.hsqldb.jdbc.JDBCPreparedStatement.fetchResult(Unknown Source)
at org.hsqldb.jdbc.JDBCPreparedStatement.executeUpdate(Unknown Source)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeUpdate(NewProxyPreparedStatement.java:147)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:208)
... 39 more
Caused by: org.hsqldb.HsqlException: org.hsqldb.HsqlException: The table data is read only
at org.hsqldb.error.Error.error(Unknown Source)
at org.hsqldb.SessionData.allocateLobForResult(Unknown Source)
at org.hsqldb.Session.allocateResultLob(Unknown Source)
at org.hsqldb.jdbc.JDBCPreparedStatement.performPreExecute(Unknown Source)
... 43 more
Caused by: org.hsqldb.HsqlException: The table data is read only
at org.hsqldb.error.Error.error(Unknown Source)
at org.hsqldb.error.Error.error(Unknown Source)
at org.hsqldb.persist.LobManager.setCharsForNewClob(Unknown Source)
... 46 more
java.lang.RuntimeException: javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not execute statement
The code I am running looks like this:
#Test
public void testCreateUserSettings() throws Exception {
MyDatabase db = MyDatabaseFactory.createMyDatabase("jdbc:hsqldb:mem:db1;sql.syntax_ora=true", new Properties());
//MyDatabase db = MyDatabaseFactory.getMyDatabase("jdbc:hsqldb:res:/my-db-base");
Properties properties = new Properties();
properties.putAll(db.getConnectionProperties());
properties.setProperty("javax.persistence.provider", "org.hibernate.jpa.HibernatePersistenceProvider");
EntityManagerFactory emf = Persistence.createEntityManagerFactory("InMemorySeederPU", properties);
EntityManager em = emf.createEntityManager();
try {
Date now = new Date();
String defaultData = "{\"key\": \"value\"}";
String defaultId = UUID.randomUUID().toString();
String userId = "uA1";
UserSetting setting = new UserSetting();
setting.setIdObject(defaultId);
setting.setDateCreate(now);
setting.setDateUpdate(now);
setting.setDateArrive(now);
setting.setIdDatabase("A");
setting.setIdUserCreate(userId);
setting.setIdUserUpdate(userId);
setting.setIdOwner(userId);
setting.setNamespace(defaultId);
setting.setEntityVersion(1L);
setting.setData(defaultData);
setting.setEtag(DigestUtils.md5Hex(defaultData));
em.getTransaction().begin();
em.persist(setting);
em.flush();
em.getTransaction().commit();
UserSetting setting2 = em.find(UserSetting.class, defaultId);
Assert.assertEquals(setting2, setting);
}
finally {
em.close();
}
}
MyDatabase is just a wrapper to get a connection to a database. If I use 'jdbc:hsqldb:mem:...' the test works fine (the createMyDatabase() method loads the in-memory database with the data I need). However, if I replace that with the commented-out line that uses 'jdbc:hsqldb:res:...' then the test fails and HSQLDB reports the exception 'The table data is read only'.
Putting Hibernate into DEBUG mode shows the following:
DEBUG 12-09-2016 16:46:22 - Initializing EntityManagerFactoryRegistry : org.hibernate.jpa.internal.EntityManagerFactoryRegistry#59ce792e
DEBUG 12-09-2016 16:46:22 - Registering EntityManagerFactory: InMemorySeederPU
DEBUG 12-09-2016 16:46:23 - begin
DEBUG 12-09-2016 16:46:23 - Obtaining JDBC connection
DEBUG 12-09-2016 16:46:23 - Obtained JDBC connection
DEBUG 12-09-2016 16:46:23 - initial autocommit status: false
DEBUG 12-09-2016 16:46:23 - Generated identifier: d6d16b01-0181-4f2b-9e5f-2dac0bb097b1, using strategy: org.hibernate.id.Assigned
DEBUG 12-09-2016 16:46:23 - Processing flush-time cascades
DEBUG 12-09-2016 16:46:23 - Dirty checking collections
DEBUG 12-09-2016 16:46:23 - Flushed: 1 insertions, 0 updates, 0 deletions to 1 objects
DEBUG 12-09-2016 16:46:23 - Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
DEBUG 12-09-2016 16:46:23 - Listing entities:
DEBUG 12-09-2016 16:46:23 - com.ben.entity.UserSetting{data={"key": "value"}, dateArrive=Mon Sep 12 16:46:23 AEST 2016, idDatabase=A, idObject=d6d16b01-0181-4f2b-9e5f-2dac0bb097b1, idUserDelete=null, dateCreate=Mon Sep 12 16:46:23 AEST 2016, entityVersion=1, dateUpdate=Mon Sep 12 16:46:23 AEST 2016, idUserCreate=uA1, namespace=d6d16b01-0181-4f2b-9e5f-2dac0bb097b1, etag=88bac95f31528d13a072c05f2a1cf371, idUserUpdate=uA1, idOwner=uA1, dateDelete=null}
DEBUG 12-09-2016 16:46:23 - insert into user_settings (data, date_arrive, date_create, date_delete, date_update, entity_version, etag, id_database, id_owner, id_user_create, id_user_delete, id_user_update, namespace, id_object) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
DEBUG 12-09-2016 16:46:23 - could not execute statement [n/a]
java.sql.SQLException: org.hsqldb.HsqlException: The table data is read only
Thanks in advance,
Ben
According to the HSQLDB manual,
A res: catalog consists of the files for a small, read-only database
that can be stored inside a Java resource such as a ZIP or JAR archive
and distributed as part of a Java application program.
Consequently you cannot insert data into such a database, and the exception is expected
From the section RES and Files Readonly Databases:
There is another option which allows MEMORY tables to be writeable, but without persisting the changes at SHUTDOWN. This option is activated with the property, value pair, files_readonly=true, which can be added to the .properties file of the database, or included in the URL of the first connection to the database.
A res: catalog, is a set of database files on the classpath (inside a
jar or alongside class files). The database is opened with a URL in
the form of jdbc:hsqldb:res:. These databases are
always files_readonly and have the same restrictions as files_readonly
file: catalogs.
CACHED tables and LOBS in these catalogs are readonly. It is not
possible to create new LOBs in these catalogs, but you can use
existing LOBs in new rows.

Entity Framework 5 IBM DB2 EntityException The underlying provider failed on ConnectionString

I am using Visual Studio 2012 to build a web application. The application uses webforms, Entity Framework 5 with an IBM DB2 database server. I have the latest IBM Drivers v10.1.2 installed on both my development machine and my web server. The web server is running Windows Server 2008 R2 Standard x64bit OS.
Problem Im having is running the app under Visual Studio's IIS Express on my local machine works fine, however when I deployed the app the web server I am getting problems EF and DB2 Drivers. Here is the error and stack trace. What am doing wrong?!
Server Error in '/' Application.
--------------------------------------------------------------------------------
ERROR [] [IBM][CLI Driver] SQL0000W Statement processing was successful.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: IBM.Data.DB2.DB2Exception: ERROR [] [IBM][CLI Driver] SQL0000W Statement processing was successful.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[DB2Exception (0x80004005): ERROR [] [IBM][CLI Driver] SQL0000W Statement processing was successful.]
IBM.Data.DB2.ConnSettingsFromXmlConfig.ProcessFromXmlConfig(DB2Connection connection, String dbname, String host, String port, String tmpClientEncAlg, String tmpAuthentication, String prevdb, String prevdb_ori, DB2ConnSettings& sSettings, DB2ConnSettingsInternal& sSettingsInternal, StringBuilder& modifiedValue) +21370
IBM.Data.DB2.DB2ConnPool.ReplaceConnectionStringParms(DB2Connection connection, String szValue, DB2ConnSettings& pSettings, DB2ConnSettingsInternal& pSettingsInternal, Boolean bAttach, Boolean pushDownStrAppended) +19113
IBM.Data.DB2.DB2Connection.set_ConnectionString(String value) +187
System.Data.EntityClient.EntityConnection.ChangeConnectionString(String newConnectionString) +325
[EntityException: The underlying provider failed on ConnectionString.]
System.Data.EntityClient.EntityConnection.ChangeConnectionString(String newConnectionString) +391
System.Data.EntityClient.EntityConnection..ctor(String connectionString) +43
System.Data.Entity.Internal.LazyInternalConnection.InitializeFromConnectionStringSetting(ConnectionStringSettings appConfigConnection) +78
System.Data.Entity.Internal.LazyInternalConnection.TryInitializeFromAppConfig(String name, AppConfig config) +32
System.Data.Entity.Internal.LazyInternalConnection.Initialize() +127
System.Data.Entity.Internal.LazyInternalConnection.CreateObjectContextFromConnectionModel() +13
System.Data.Entity.Internal.LazyInternalContext.InitializeContext() +281
System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) +18
System.Data.Entity.Internal.Linq.InternalSet`1.Initialize() +52
System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext() +15
System.Data.Entity.Infrastructure.DbQuery`1.System.Linq.IQueryable.get_Provider() +37
System.Linq.Queryable.Where(IQueryable`1 source, Expression`1 predicate) +63
....
I had the same problem and changing the app pool to Network Service did the trick.