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.
Related
Things Board Version: V3.4.1 CE
OS: Window
Database: postgreSQL timescale
Queue: Rabbitmq
I discover that the telemetry data unable to pass through things board root rule chain with the node of the name save timeseries, i am not sure what is happening, i confirm there should be no problem on the connection between thingsboard and also postgreSQL...
I can see debug from here to know the problem is because failed to save to timeseries data....
2022-11-02 09:04:27,148 [sql-queue-2-ts timescale-11-thread-1] ERROR o.t.s.dao.sql.TbSqlBlockingQueue - [TS Timescale] Failed to save 2 entities
org.springframework.transaction.TransactionSystemException: Could not roll back JPA transaction; nested exception is org.hibernate.TransactionException: Unable to rollback against JDBC Connection
at org.springframework.orm.jpa.JpaTransactionManager.doRollback(JpaTransactionManager.java:593)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processRollback(AbstractPlatformTransactionManager.java:835)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.rollback(AbstractPlatformTransactionManager.java:809)
at org.springframework.transaction.interceptor.TransactionAspectSupport.completeTransactionAfterThrowing(TransactionAspectSupport.java:672)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:392)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:119)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:708)
at org.thingsboard.server.dao.sqlts.insert.timescale.TimescaleInsertTsRepository$$EnhancerBySpringCGLIB$$693764a7.saveOrUpdate()
at org.thingsboard.server.dao.sqlts.timescale.TimescaleTimeseriesDao.lambda$init$1(TimescaleTimeseriesDao.java:89)
at org.thingsboard.server.dao.sql.TbSqlBlockingQueue.lambda$init$2(TbSqlBlockingQueue.java:74)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: org.hibernate.TransactionException: Unable to rollback against JDBC Connection
at org.hibernate.resource.jdbc.internal.AbstractLogicalConnectionImplementor.rollback(AbstractLogicalConnectionImplementor.java:127)
at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl$TransactionDriverControlImpl.rollback(JdbcResourceLocalTransactionCoordinatorImpl.java:304)
at org.hibernate.engine.transaction.internal.TransactionImpl.rollback(TransactionImpl.java:142)
at org.springframework.orm.jpa.JpaTransactionManager.doRollback(JpaTransactionManager.java:589)
... 16 common frames omitted
Caused by: java.sql.SQLException: Connection is closed
at com.zaxxer.hikari.pool.ProxyConnection$ClosedConnection.lambda$getClosedConnection$0(ProxyConnection.java:515)
at com.sun.proxy.$Proxy153.rollback(Unknown Source)
at com.zaxxer.hikari.pool.ProxyConnection.rollback(ProxyConnection.java:396)
at com.zaxxer.hikari.pool.HikariProxyConnection.rollback(HikariProxyConnection.java)
at org.hibernate.resource.jdbc.internal.AbstractLogicalConnectionImplementor.rollback(AbstractLogicalConnectionImplementor.java:121)
... 19 common frames omitted
2022-11-02 09:04:27,148 [tb-rule-engine-consumer-37-thread-35 | QK(Main,TB_RULE_ENGINE,system)-10] INFO o.t.s.s.q.DefaultTbRuleEngineConsumerService - Failed to process 1 messages
2022-11-02 09:04:27,148 [tb-rule-engine-consumer-37-thread-35 | QK(Main,TB_RULE_ENGINE,system)-10] INFO o.t.s.s.q.DefaultTbRuleEngineConsumerService - [c1737420-58eb-11eb-808a-dfdc947dc52b] Failed to process message: TbMsg(queueName=Main, id=1318aa98-0755-49b0-9685-a71a2326ff7d, ts=1667351067141, type=POST_TELEMETRY_REQUEST, originator=354d8300-aa84-11ec-9a47-4727b3504d5d, customerId=d7094170-5c4c-11eb-b06a-c93fc5e45132, metaData=TbMsgMetaData(data={deviceType=Sensor, deviceName=RMS Voltage Sensor, ts=1667351067141}), dataType=JSON, data={"timestamp":1667351069011,"values":[{"id":"CnB Prai Gateway.RMS Shearline.Sensor5_Active","v":true,"t":1667291491472},{"id":"CnB Prai Gateway.RMS Shearline.Sensor5_Battery","v":296,"t":1667342191745},{"id":"CnB Prai Gateway.RMS Shearline.Sensor5_Signal","v":65478,"t":1667350910940},{"id":"CnB Prai Gateway.RMS Shearline.Sensor5_Voltage","v":0,"t":1667351068948}]}, ruleChainId=c1c082b0-58eb-11eb-808a-dfdc947dc52b, ruleNodeId=null, ctx=org.thingsboard.server.common.msg.TbMsgProcessingCtx#4c99aecc, callback=org.thingsboard.server.common.msg.queue.TbMsgCallback$1#415dca17), Last Rule Node: [RuleChain: Root Rule Chain|RuleNode: Save raw telemetry(71b87e70-177d-11ec-9530-3197ec48e7c5)]
I would suggest to use generator node to test where the problem is.
First you should test if you can save basic message (like the one you get when you open generator node). With this you will confirm that you can save data to database.
After that you should configure generator node to act as your device, and have same data and metadata as you would get from you device/integration.
Reach out back here with your findings from that.
Generator rule node ref: https://thingsboard.io/docs/user-guide/rule-engine-2-0/action-nodes/#generator-node
When I increase load on PostgreSQL server, by hitting REST APIs through LOAD Testing Tool. Postgres starts throwing exception ERROR: cannot execute UPDATE in a read-only transaction. Once it starts throwing exception, Even If I try to execute a update query directly to PG SQL command line, same exception is thrown there also. Then around 5-10 minutes later, it automatically comes in normal mode.
In the test suite, I have multiple APIs performing mulitple select, update, insert operations on various tables. Here We have one such table having a column with bytea data type stores a excel file in binary format. Don't know this information is relevant or not.
But my concern is why Postgres automatically switches to READ-ONLY mode, that causes my APIs fails abruptly. It is an intermittent issue, we need to increase lots of load on database server to replicate it.I am not sure it is happening due to LOAD or above mentioned "bytea" column having large binary data causing such issue?
PostgreSql version: 12
PG Driver: 42.2.18
Any suggestion or clue please?
below are logs:
Caused by: org.hibernate.exception.GenericJDBCException: could not execute statement
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:54) ~[hibernate-core-4.3.5.Final.jar:4.3.5.Final]
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:126) ~[hibernate-core-4.3.5.Final.jar:4.3.5.Final]
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:112) ~[hibernate-core-4.3.5.Final.jar:4.3.5.Final]
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:190) ~[hibernate-core-4.3.5.Final.jar:4.3.5.Final]
at org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch.addToBatch(NonBatchingBatch.java:62) ~[hibernate-core-4.3.5.Final.jar:4.3.5.Final]
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:3281) ~[hibernate-core-4.3.5.Final.jar:4.3.5.Final]
at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:3183) ~[hibernate-core-4.3.5.Final.jar:4.3.5.Final]
......
....
Caused by: org.postgresql.util.PSQLException: ERROR: cannot execute UPDATE in a read-only transaction
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2553) ~[postgresql-42.2.18.jar:42.2.18]
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2285) ~[postgresql-42.2.18.jar:42.2.18]
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:323) ~[postgresql-42.2.18.jar:42.2.18]
at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:473) ~[postgresql-42.2.18.jar:42.2.18]
at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:393) ~[postgresql-42.2.18.jar:42.2.18]
at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:164) ~[postgresql-42.2.18.jar:42.2.18]
at org.postgresql.jdbc.PgPreparedStatement.executeUpdate(PgPreparedStatement.java:130) ~[postgresql-42.2.18.jar:42.2.18]
at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeUpdate(ProxyPreparedStatement.java:61) ~[HikariCP-2.4.5.jar:na]
at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeUpdate(HikariProxyPreparedStatement.java) ~[HikariCP-2.4.5.jar:na]
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:187) ~[hibernate-core-4.3.5.Final.jar:4.3.5.Final]
... 46 common frames omitted
I am new to spring data jpa.
i have a legacy database , which i am trying to connect to via spring data jpa.
i have a certain extension created in postgres which is used for some of the columns in my tables
for e.g
CREATE EXTENSION IF NOT EXISTS citext WITH SCHEMA public;
this extension is created mostly for (case-insensitive text)
now when i try to map the tables using standard entity annotations, it gives me error, as its unable to understand this extension
The error i get is
g.springframework.boot.SpringApplication - Application startup failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: wrong column type encountered in column [domain_obj_nm] in table [attr_grp_defn]; found [citext (Types#OTHER)], but expecting [varchar(255) (Types#VARCHAR)]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1634)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:312)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:308)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1080)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:857)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107)
at com.sas.mkt.example.app.Application.main(Application.java:43)
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: wrong column type encountered in column [domain_obj_nm] in table [attr_grp_defn]; found [citext (Types#OTHER)], but expecting [varchar(255) (Types#VARCHAR)]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:396)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:371)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:336)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1692)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1630)
... 16 common frames omitted
Caused by: org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: wrong column type encountered in column [domain_obj_nm] in table [attr_grp_defn]; found [citext (Types#OTHER)], but expecting [varchar(255) (Types#VARCHAR)]
i want a way via annotations to solve this issue, its ok if it is treated just as text column.
Hibernate is validating the schema on start-up as the ddl.auto property is set to validate.
You can either disable validation entirely or specify a column definition for the relevant #Columnproperty which should allow the validation to pass:
https://docs.oracle.com/javaee/5/api/javax/persistence/Column.html#columnDefinition()
#Column(columnDefinition = "citext") //or "other"?
private String myField;
Note that the column definition only affects DDL operations i.e. schema creation or validation.
Disabling validation entirely depends on your set-up. In a spring-boot app for example you set spring.jpa.hibernate.ddl-auto = false
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
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]