I am reading the book PySpark Recipes A Problem-Solution Approach with PySpark2
It connects hive to postgresql. When I run the command
hive> create database apress;
I am getting the following error.
FAILED: HiveException java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient
org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [SELECT JOB_INSTANCE_ID, JOB_NAME from BATCH_JOB_INSTANCE where JOB_NAME = ? order by JOB_INSTANCE_ID desc]; nested exception is java.sql.SQLSyntaxErrorException: ORA-00942: table or view does not exist
I guess you may need to edit you xml config file
<bean id="jobRepository"
class="org.springframework.batch.core.repository.support.JobRepositoryFactoryBean"
p:dataSource-ref="dataSource" p:transactionManager-ref="transactionManager"
p:tablePrefix="MYDB.BATCH_"/>
MYDB been your schema
Source
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.
I have a problem to use PostgreSQL with JPA.
When i try to execute my app on glassfish i got this error:
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: org.postgresql.util.PSQLException: ERROR: no schema has been selected to create in
Error Code: 0
Call: CREATE TABLE CABINET (ID INTEGER NOT NULL, PRIMARY KEY (ID))
Query: DataModifyQuery(sql="CREATE TABLE CABINET (ID INTEGER NOT NULL, PRIMARY KEY (ID))")
at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:331)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeDirectNoSelect(DatabaseAccessor.java:895)
So how can i specify the schema for JPA so it can be able to use postgresql
note: i have added the postgresql maven dependancy:
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.1-901-1.jdbc4</version>
</dependency>
Please help me; Thank you
The schema is specified with the "search_path" variable in postgres.
To solve your problem, you have 2 solutions:
Permanently add the search to the user used by your connection:
ALTER user username set search_path=yourschema ;
Add temporarly the search_path in the jdbc connection (which i find ugly)
set search_path=yourschema;
I'm working on a web project using EJB 3.0, and whenever EclipseLink tries to interact with the database, it says that the schema I'm using doesn't exist (which it does).
I get a massive, unhelpful stack trace from GlassFish 2.1, which begins with:
EclipseLink, version: Eclipse Persistence Services - 1.1.0.r3639-SNAPSHOT
file:/C:/Documents%20and%20Settings/nick/.personalDomain/personalDomain/applications/j2ee-apps/ScienceEar/lib/ScienceJpa-1.0-SNAPSHOT.jar-SciencePU login successful
Local Exception Stack:
Exception [EclipseLink-4002] (Eclipse Persistence Services - 1.1.0.r3639-SNAPSHOT): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLSyntaxErrorException: Schema 'BEAMLINE' does not exist
Error Code: -1
Call: SELECT exp_id, fac_family, public_viewable, group_name, created_ts, status, exp_num, date_received, exp_type, title, updated_ts, text_only_title, experiment_url, proposed_eec, start_of_prep FROM beamline.eec_exp_toc
Query: ReadAllQuery(name="Experiment.findAll" referenceClass=Experiment sql="SELECT exp_id, fac_family, public_viewable, group_name, created_ts, status, exp_num, date_received, exp_type, title, updated_ts, text_only_title, experiment_url, proposed_eec, start_of_prep FROM beamline.eec_exp_toc")
I could post more of the stack trace, but it's really boring. Any ideas for why EclipseLink can't see the schema?
More info: "beamline" is the only schema I use. The SQL in the stack trace is the stuff that was generated by a NamedQuery, the first interaction with this database (and the first JPA interaction at all) in my program.
Got it - I'm connecting directly to the database, when I should be using GlassFish's connection pool.