Already value for key datasource - spring

org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is java.lang.IllegalStateException: Already value [org.springframework.jdbc.datasource.ConnectionHolder#278d31be] for key [HikariDataSource (HikariPool-1)] bound to thread [restartedMain]
while i am
Inserting data to table
I am getting the above listed error

Related

How to retrieve the row that caused exception using spring framework's namedParameterJdbcTemplate

I am inserting user information where a few columns have unique constraint on them one of which is email id. In testing when I try to insert the same user twice I get the
org.springframework.dao.DuplicateKeyException
it also does tell me which column violated the unique constraint but it does not give me back the row that triggered the violation. I have seen solution where the user has caught such exception and run a query based on column on which violation was triggered but does spring have anything that will return the row details along with the exception.
I tried looking but there is so much information explaining why the exception happened that I do not find a solution that returns the row that caused the violation.

How to obtain new hibernate transaction inside AsyncExceptionHandler?

I have 2 DB instances, say DB1 and DB2.
I need to write data to a table in DB2 asynchronously (#Async block).
If there is an exception while writing data to DB2, we need to write the data to another table in DB1.
I am using custom exception handler which implements AsyncUncaughtExceptionHandler (provided by Spring AOP) to catch the exception and do the operation 3. However, I am unable to do the transaction as there are two DB transactions involved and I loose the transaction. I get an error saying org.hibernate.HibernateException: Could not obtain transaction-synchronized Session for current thread
I am using Spring 5.0.3 and Hibernate 5.2.11.

Null value in column primary_id when a spring boot session is created

I have been trying to add session data to my application. For most part I have been following the docs here for creating a jdbc http session. Accordingly, I have
HttpSessionConfig.java
#EnableJdbcHttpSession
public class HttpSessionConfig {}
and I have my username,password, database name and so forth in my application.properties file. Furthermore, I created the session tables using the script found here. However, I go to my login page I get the error
PreparedStatementCallback; SQL [INSERT INTO SPRING_SESSION(SESSION_ID,
CREATION_TIME, LAST_ACCESS_TIME, MAX_INACTIVE_INTERVAL,
PRINCIPAL_NAME) VALUES (?, ?, ?, ?, ?)]; ERROR: null value in column
"primary_id" violates not-null constraint Detail: Failing row contains
(null, 835a7b12-d171-4f77-bd22-7da7ed78ca12, 1510171280672,
1510171280672, 1800, null, null).; nested exception is
org.postgresql.util.PSQLException: ERROR: null value in column
"primary_id" violates not-null constraint Detail: Failing row contains
(null, 835a7b12-d171-4f77-bd22-7da7ed78ca12, 1510171280672,
1510171280672, 1800, null, null).
However, as far I can tell from the docs this is suppose to work. Is there a step that I overlooked or isn't in the docs?
For me the solution was as #user5960886 pointed in one of their own replies.
I was using the wrong schema (master) for the spring table spring_session (and spring_session_attributes) which requires prinary_id to not be null where my application was running and populating the schema that does not populate this column (namely 1.3.0.RELEASE).
Here are the links that have the 2 schemas:
Version 1.3.0.RELEASE
https://github.com/spring-projects/spring-session/blob/1.3.0.RELEASE/spring-session/src/main/resources/org/springframework/session/jdbc/schema-postgresql.sql
Latest Master
https://github.com/spring-projects/spring-session/blob/master/spring-session-jdbc/src/main/resources/org/springframework/session/jdbc/schema-postgresql.sql
You may need to drop and recreate your existing tables if you have created them using the latest schema. NOTE: Existing data will be lost. Here is the drop SQL statements you can use:
https://raw.githubusercontent.com/spring-projects/spring-session/1.3.0.RELEASE/spring-session/src/main/resources/org/springframework/session/jdbc/schema-drop-postgresql.sql

Oracle BPEL DB Adapter constraint exception when writing in two tables - suddenly broken

I've got a Oracle BPEL process running on WebLogic which is writing in two tables using Database Adapters.
There are two tables, TableA and TableB. TableB has a foreign key to TableA.
I the process I create an entry in TableA with A_ID. When I create an entry in TableB using A_ID as a FK I get a constraint exception.
What is weird, this worked last week and now, using the same data, I get the error.
The datasource is set up as a standard - non-XA datasource.
This is the exception that is thrown:
<env:Fault>
<faultcode>env:Server</faultcode>
<faultstring>Exception occured when binding was invoked.
Exception occured during invocation of JCA binding: "JCA Binding execute of
Reference operation 'insert' failed due to: DBWriteInteractionSpec Execute
Failed Exception.
insert failed. Descriptor name: [Datawarehouse.TableB].
Caused by java.sql.BatchUpdateException: ORA-02291: integrity constraint
(DWH.TABLE_A_FK) violated - parent key not found
.
".
The invoked JCA adapter raised a resource exception.
Please examine the above error message carefully to determine a resolution.
</faultstring>
<faultactor/>
<detail>
<exception>ORA-02291: integrity constraint (DWH.TABLE_A_FK) violated - parent key not found</exception>
</detail>
</env:Fault>
This has nothing to do with Oracle BPEL. For some reason, either the insert onto Table A is not successful or the insert on to Table A is not visible to Table B (second insert being in a different transaction).

org.springframework.dao.DataIntegrityViolationException

while adding some data to table from jsp, only one row of data gets inserted
Also an org.springframework.dao.DataIntegrityViolationException is thrown.
Can you say why this exception is raised?
The exception is in most cases about database constraint violation. - In your case I would guess it is some unique constraint - but this is only guessing.

Resources