error creating table and also MysqlInnoBDailect is not coming in propeties - spring

org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "create table dept (dept_id bigint not null, dep_name varchar(255), hod varchar(255), primary key (dept_id)) type=InnoDB" via JDBC Statement

Related

Unable to extract JDBC value for position `3`

I am switching from MYSQL to ORACLE.
I have JPA Authentication setup like this:
#Override
#Transactional(readOnly = true)
public UserDetails loadUserByUsername(String email) throws UsernameNotFoundException {
AppUser user = userRepository.findByUseremailIgnoreCase(email);
With MySQL all works fine. But for Oracle, during login using JPA authentication I am getting this exception.
org.springframework.security.authentication.InternalAuthenticationServiceException: Unable to extract JDBC value for position `3`
Followed by these exceptions:
Caused by: org.springframework.orm.jpa.JpaSystemException: Unable to extract JDBC value for position `3`
Caused by: java.sql.SQLException: Invalid conversion requested
Caused by: java.lang.IllegalArgumentException: Timestamp format must be yyyy-mm-dd hh:mm:ss[.fffffffff]
Any clue what I am missing and where to debug?
My table structure is as per below:
create table CONTENTPLUSPLUS.app_user (
id NUMBER GENERATED ALWAYS as IDENTITY(START with 1 INCREMENT by 1) NOT NULL,
useremail VARCHAR(150) NOT NULL,
userpassword VARCHAR(150) NOT NULL,
useruuid VARCHAR(50) NOT NULL,
userfirstname VARCHAR(150) NOT NULL,
userlastname VARCHAR(150) NOT NULL,
userenabled NUMBER(1) DEFAULT 0 NOT NULL,
created_by VARCHAR(150) NOT NULL,
created_date VARCHAR(150) NOT NULL,
modified_by VARCHAR(150) NOT NULL,
modified_date VARCHAR(150) NOT NULL,
CONSTRAINT appuser_pk PRIMARY KEY (id), UNIQUE (useremail, useruuid));
create table CONTENTPLUSPLUS.app_role(
id NUMBER GENERATED ALWAYS as IDENTITY(START with 1 INCREMENT by 1) NOT NULL,
name VARCHAR(150) NOT NULL,
CONSTRAINT approle_pk PRIMARY KEY (id),UNIQUE (name));
CREATE TABLE CONTENTPLUSPLUS.app_department (
id NUMBER GENERATED ALWAYS as IDENTITY(START with 1 INCREMENT by 1) NOT NULL,
departmentuuid VARCHAR(150),
departmentheadname varchar(255) NOT NULL,
departmentheademail varchar(255) NOT NULL,
departmentname varchar(255) NOT NULL,
userid NUMBER NOT NULL,
created_by VARCHAR(150) NOT NULL,
created_date VARCHAR(150) NOT NULL,
modified_by VARCHAR(150) NOT NULL,
modified_date VARCHAR(150) NOT NULL,
CONSTRAINT appdepartment_pk PRIMARY KEY (id),UNIQUE (departmentname, departmentuuid));
CREATE TABLE CONTENTPLUSPLUS.app_user_department (
userid NUMBER NOT NULL,
departmentid NUMBER NOT NULL
);
ALTER TABLE CONTENTPLUSPLUS.app_user_department ADD CONSTRAINT FK_AUSERDEPTUSERID FOREIGN KEY (userid) REFERENCES app_user (id);
ALTER TABLE CONTENTPLUSPLUS.app_user_department ADD CONSTRAINT FK_AUSERDEPTDEPTID FOREIGN KEY (departmentid) REFERENCES app_department (id);
ALTER TABLE CONTENTPLUSPLUS.app_department ADD CONSTRAINT FK_AUSERUSERID FOREIGN KEY (userid) REFERENCES app_user (id);
CREATE TABLE CONTENTPLUSPLUS.app_user_role (
id NUMBER GENERATED ALWAYS as IDENTITY(START with 1 INCREMENT by 1) NOT NULL,
userid NUMBER NOT NULL,
roleid NUMBER NOT NULL,
CONSTRAINT appuserrole_pk PRIMARY KEY (id));
ALTER TABLE CONTENTPLUSPLUS.app_user_role ADD CONSTRAINT FK_AURUSERID FOREIGN KEY (userid) REFERENCES app_user (id);
ALTER TABLE CONTENTPLUSPLUS.app_user_role ADD CONSTRAINT FK_AURROLEID FOREIGN KEY (roleid) REFERENCES app_role (id);
Below is the query which gets fired during the login operation (shows up only for MySQL):
Hibernate:
select
a1_0.id,
a1_0.created_by,
a1_0.created_date,
a1_0.modified_by,
a1_0.modified_date,
a1_0.useremail,
a1_0.userenabled,
a1_0.userfirstname,
a1_0.userlastname,
a1_0.userpassword,
a1_0.useruuid
from
app_user a1_0
where
upper(a1_0.useremail)=upper(?)
Hibernate:
select
r1_0.userid,
r1_1.id,
r1_1.name
from
app_user_role r1_0
join
app_role r1_1
on r1_1.id=r1_0.roleid
where
r1_0.userid=?
You map Date in Java with VARCHAR2 in SQL: bad idea. You probably get lucky with the default conversion format of TS and the locale in MySQL: back to my first comment... look at the SQL Office Hours session code...

Spring Test H2 Flyway - error in sql statement

I have the following sql migration, that doesn't work with h2. If I remove the following SQL - everything works fine. How can i solve it?
SQL State : 42001
Error Code : 42001
Message : Syntax error in SQL statement "CREATE TABLE USER_AUTHORITY
(
USER_AUTHORITY_ID BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
USER_ID BIGINT REFERENCES USR (USER_ID) NOT NULL[*],
AUTHORITY_ID BIGINT REFERENCES AUTHORITY (AUTHORITY_ID) NOT NULL,
OPERATION VARCHAR(2) NOT NULL,
CREATION_DATETIME TIMESTAMP WITH TIME ZONE NOT NULL,
MODIFYING_DATETIME TIMESTAMP WITH TIME ZONE NOT NULL
)"; expected "DEFERRABLE";
Location : db/migration/V1__Schema.sql (/home/v/IdeaProjects/stocky/user-service/build/resources/main/db/migration/V1__Schema.sql)
Line : 29
Statement : create table user_authority
This is a bug of the parser. I filled a new issue about it:
https://github.com/h2database/h2database/issues/3413
You can specify NOT NULL before REFERENCES as a workaround.
USER_ID BIGINT NOT NULL REFERENCES USR (USER_ID),
AUTHORITY_ID BIGINT NOT NULL REFERENCES AUTHORITY (AUTHORITY_ID),

Spring boot unable to run schema.sql

I am on spring boot 2.3, and have following in my schema.sql
CREATE TABLE customer (id SERIAL PRIMARY KEY, first_name VARCHAR(255), last_name VARCHAR(255));
Pom file has h2 dependency.
When I run application, I get error:
Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "CUSTOMER" not found; SQL statement:
INSERT INTO customer (first_name, last_name) VALUES ($1, $2) [42102-200]
Is some change needed in application.properties to make spring boot execute schema.sql?
You can drop table if exist before creation :
DROP TABLE IF EXISTS customer;
CREATE TABLE customer (id SERIAL PRIMARY KEY, first_name VARCHAR(255), last_name VARCHAR(255));

Spring H2 created table not found after successful creation

I am using Spring Boot's schema.sql magic to create an in memory H2 database. The script contains the following statements:
create table PERSON
(
ID BIGINT not null primary key,
NAME VARCHAR(255) not null
);
create index IDX_PERSON_NAME on PERSON (NAME);
Upon launch Spring Boo fails with the following exception:
Caused by: org.springframework.jdbc.datasource.init.ScriptStatementFailedException: Failed to execute SQL script statement #2 of URL [file:/D:/git/.../build/resources/main/schema.sql]: create index IDX_PERSON_NAME on PERSON (NAME); nested exception is org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "PERSON" not found; SQL statement:
create index IDX_PERSON_NAME on PERSON (NAME) [42102-200]
How can the statement fail to find the table that was created in the preceding statement?
Simply because NAME is not mentioned as Unique constraint, you have only specified it as NOT NULL constraint
create table PERSON
(
ID BIGINT not null primary key,
NAME VARCHAR(255) not null,
CONSTRAINT Person_Name_Unique UNIQUE (NAME)
);
create index IDX_PERSON_NAME on PERSON (NAME);
Here are the possible reasons,
The schema needs to be mentioned on while referring to table like test_schema.person
Your syntax for creating the index might be wrong. Refer to this link for H2 Syntax,https://www.baeldung.com/spring-yaml

Error in creating MySQL table with multiple foreign keys

I am trying to create a table with multiple foreign keys , but getting error msg...
Here is the query
create table REVIEW (
REVIEWER_ID varchar(255) not null,
DOCTOR_ID integer not null,
REVIEW varchar(255),
DATE datetime,
primary key (REVIEWER_ID, DOCTOR_ID)
) ENGINE=InnoDB
alter table REVIEW
add constraint FK_n1a9feqfl96wayocqr6n04p2y
foreign key (DOCTOR_ID)
references DOCTORS_INFORMATION (DOCTOR_ID)
It has executed the upper statement. But when i do the following it is showing error.
alter table REVIEW
add constraint FK_fpmwq7vslmp90var2qmw2lhf4
foreign key (REVIEWER_ID)
references REVIEWER_INFORMATION (REVIEWER_ID)
Reviewer_information table was created using the following command
create table REVIEWER_INFORMATION (
REVIEWER_ID integer not null auto_increment,
EMAIL varchar(255),
FIRSTNAME varchar(255),
LASTNAME varchar(255),
PHONE_NUMBER integer,
primary key (REVIEWER_ID)
) ENGINE=InnoDB

Resources