Quarkus + Hibernate + h2 - cannot create id - postgresql

I'm using quarkus application with Postgres DB. For testing, I'm using h2 in-memory DB.
When I upgraded the version of hibernate to 5.6 I started facing issues with h2 tests. I found spring developers recommending hibernate.id.new_generator_mappings=false or set
#GeneratedValue(strategy = GenerationType.IDENTITY). The first thing does nothing if I put it in application.properties. The second thing helps for testing but now the application cannot generate an id (error like: cannot save id null).
When running tests:
Error executing DDL "create sequence hibernate_sequence start 1 increment 1" via JDBC Statement: org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "create sequence hibernate_sequence start 1 increment 1" via JDBC Statement
h2 configured as documented in quarkus.
%in-memory-profile.quarkus.datasource.db-kind = h2
%in-memory-profile.quarkus.datasource.jdbc.url = jdbc:h2:mem:test
It worked before upgrading quarkus and hibernate.

Related

How to fix the DB calls exception - ERROR: Cannot execute INSERT in a read-only transaction in Spring boot JPA

I am facing the below error when doing insert/updates/deletes using Spring Boot -JPA
when executing the Postgres calls?
org.springframework.orm.jpa.JpaSystemException : could not execute statement ; nested exception is org.hibernate.exception.GenereircJDBCException : Could not execute statement with root cause org.postgreql.util.PSQLException: ERROR cannot execute INSERT in a read-only transaction
The application is kind of modeled along the lines as in
https://springframework.guru/how-to-configure-multiple-data-sources-in-a-spring-boot-application/
I am using the below stack
Spring boot - 2.2.7.RELEASE
JPA 2.0
This is a multidatasource application and i can't make any changes at the DB server.
Are there any changes that we can do at the java code end to fix the issue.
Regards

Failure to find table when using multiple schemas in PostgreSQL

WPF PostgreSQL 11.1
Npgsql.PostgresException: '42P01: relation "testme" does not exist'
When attempting to use a PostgreSQL database with multiple schemas, I have defined the following connection strings in the App.config. Note that the only difference is in the SearchPath:
<system.data>
<DbProviderFactories>
<add name="Npgsql Data Provider" invariant="Npgsql" support="FF" description=".Net Framework Data Provider for Postgresql Server" type="Npgsql.NpgsqlFactory, Npgsql, Version=4.0.4.0, Culture=neutral" />
</DbProviderFactories>
</system.data>
<connectionStrings>
<clear />
<add name="localconnection" providerName="Npgsql" connectionString="Server=127.0.0.1;Port=5432;Database=chaos;User Id=postgres;Password=****;Searchpath=nova" />
<add name="phoenixconnection" providerName="Npgsql" connectionString="Server=127.0.0.1;Port=5432;Database=chaos;User Id=postgres;Password=****;SearchPath=phoenix;" />
</connectionStrings>
The Npgsql data provider was installed using NuGet: Runtime Version:
v4.0.30319 Version: 4.0.4.0
In PostgreSQL, in the Phoenix schema:
CREATE TABLE phoenix.testme
(
name text COLLATE pg_catalog."default" NOT NULL
)
WITH (
OIDS = FALSE
)
TABLESPACE pg_default;
ALTER TABLE phoenix.testme
OWNER to postgres;
Using PgAdmin, displaying the testme table works without problem:
select * from phoenix.testme;
I have configured the WCF service using the above connection strings. Using PetaPoco, I write the following script:
public string SayHello()
{
string msg;
using (var db = new chaosDB("phoenixconnection"))
{
var m = db.ExecuteScalar<string>("select version()");
msg = string.Format("Hello from {0}", m);
m = db.ExecuteScalar<string>("select current_schema");
msg = string.Format("{0} Current Schema is {1}", msg, m);
var ss = db.ExecuteScalar<string>("show search_path");
var s = db.Fetch<string>("select * from testme"); <---THIS FAILS!
msg = string.Format("{0} I Am {1}", msg, m);
}
return msg;
}
All works correctly until the "select * from testme" is executed, when I receive the above error. Note: ss from "show search_path" returns correctly with "phoenix"
WHAT AM I DOING WRONG? How do I get this to work??
Any help is most appreciated?
After much head scratching the answer became self-evident. First I had reset the search_path in the database. This did not help. Then I rebuilt the POCO's with PetaPoco and quickly discovered that not only was the new table, "testme", not created, but nor were any POCO's. So, checking, the Database.tt file in PetaPoco showed it to have the wrong ConnectionStringName. Changing the ConnectionStringName to "phoenixconnection" allowed building the POCO's, but again failed to find the "testme" table.
Then the mistake became readily apparent, as stated above, both the "phoenixconnection" and the "localconnection" were pointed to the same port. From previous development, I had PostgreSQL v10.1 running on the same port as the newer PostgreSQL v11.1. Apparently, the first PostgreSQL v10.1 was receiving the connection (and not the newer PostgreSQL v11.1).
Going to services (services.msc) and shutting down v10.1 and running Database.TT now gave the error:
System.InvalidOperationException: Sequence contains more than one matching element
Apparently v10.1 (which I was using for development) only had ONE schema, but v11.1 has multiple schemas. I take the error message to mean that PetaPoco was seeing multiple tables with the same table name--i.e.,it was not distinguishing between schemas.
So, the problem is now solved.
Fix the ports! The older single-schema PostgreSQL v10.1 is kept on port: 5432.
The newer multiple-schema PostgreSQL is kept on port 5433. The v10.1 will be used for the POCO's.
Fix the connection strings in App.config of the WCF so that at run time, the WCF will use the newer v11.1. Once generated, LEAVE THE POCO'S alone and reference them in the WCF file.
Apparently, PetaPoco, can only work with one schema in generating its POCO's, but at runtime will read the connection strings from the App.Config of the WCF to execute its queries, etc. (So in the App.config where Database.TT resides, point PetaPoco to the "development" Database having only a single schema, but in the WCF environment, point the connection string to the new database with multiple schemas. The SearchPath of the connection string IS respected when running through Npgsql).
It would be nice if PetaPoco could generate POCO's specific to a schema in a multi-schema environment, but at the moment, I guess it can't :(
Addendum Note: It turns out that a given instance of PostgreSQL can have multiple DATABASES. So if the connection string for Npgsql is specific to a development database --i.e., a database with only one schema--then during development, PetaPoco works great to create the POCO's. These POCO's can then be directly used in a WCF Service project and uploaded to IIS website. The App.config files of the web site can then be directed to use the run-time database (again in the connection string) to the deployed database. All works well! :)

Hibernate fail to register REF_CURSOR parameter

I am new to Hibernate. Using the 5.2.10 FINAL version connecting to Oracle 11g using the Oracle10gDialect with JPA 2.1 and ojdbc8.jar
I try to access a simple stored procedure taking a String input parameter and output a Oracle SYS_REFCURSOR.
StoredProcedureQuery call = session.createStoredProcedureCall("sp_get_profile");
call.registerStoredProcedureParameter(1, String.class, ParameterMode.IN);
call.registerStoredProcedureParameter(2, Class.class, ParameterMode.REF_CURSOR);
call.execute();
An exception occur when I access the function
ERROR SqlExceptionHelper Invalid column type: 2012
DatabaseException::error=[Error registering REF_CURSOR parameter [2]]
I try to write a simple program connecting to DB with the Oracle Driver only. I will have the same error if I register Types.REF_CUSOR as the output parameter to CallableStatement.
cs.registerOutParameter(2, Types.REF_CURSOR);
And the problem can be solved by changing to OracleTypes
cs.registerOutParameter(2, OracleTypes.CURSOR);
Anyone know what is wrong? I need to fall back to use the traditional SQL programming if I cannot get the stored procedure access success. . . please help.
Finally got it work, I should check the Oracle JDBC document first before implementation.
ojdbc8 should be good for Oracle 12c + JDK8 + JPA2.1 with Oracle12cDialect.
For Oracle 11g, need to use ojdbc6.jar
I solved that issue by debugging OJDBC and Hibernate, the building from sources a patched Hibernate CORE library (5.4.15-Final).
I have patched the method ExtractedDatabaseMetaDataImpl.supportsRefCursors which returns always false.

Extracting properties from a Groovy object causes H2 database error

I'm using Grails 2.0, Groovy 1.8.4 on Eclipse STS 3.7. When I execute the following statement to extract properties from a groovy object, Grails throws a SQL exception, not sure why since I'm not using H2 database. I've deleted DataSources.groovy from my project and commented out all references to sql or h2 in other config files, but the problem persists
Note note = [title:'foo', details:'bar']
def objprops = note.properties.findAll{ !['class','metaClass'].contains(it.key)}
The exception...
org.h2.jdbc.JdbcSQLException: Table "NOTE" not found; SQL statement:
select this_.id as id0_0_, this_.version as version0_0_, this_.details as details0_0_, this_.title as title0_0_ from note this_ [42102-147]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:327)
at org.h2.message.DbException.get(DbException.java:167)
at org.h2.message.DbException.get(DbException.java:144)
at org.h2.command.Parser.readTableOrView(Parser.java:4562)
at org.h2.command.Parser.readTableFilter(Parser.java:1020)
at org.h2.command.Parser.parseSelectSimpleFromPart(Parser.java:1622)
at org.h2.command.Parser.parseSelectSimple(Parser.java:1729)

Unexpected token UNIQUE, requires COLLATION in statement [SET DATABASE UNIQUE])

Whenever I connect to HSQLDB from my application deployed on JBoss 5.1, it throws exception as : Caused by: org.jboss.resource.JBossResourceException: Could not create connection; - nested throwable: (java.sql.SQLException: error in script file line: 1 Unexpected token UNIQUE, requires COLLATION in statement [SET DATABASE UNIQUE]) .
My HSQLDB script file reads something as below :
`SET DATABASE UNIQUE NAME HSQLDB2E0BAD63B3
SET DATABASE GC 0
SET DATABASE DEFAULT RESULT MEMORY ROWS 0
SET DATABASE EVENT LOG LEVEL 0
.....`
Does anyone have idea what thos exception means or should I change something in my HSQLDB configuration?
Regards,
Satya
Your database files are created with version 2.x, but the version of database engine running on JBoss 5.1 is 1.8.x. You should be able to replace the hsqldb.jar in the JBoss configuration with a new version.