I haven't seen a script to do the DDL modification necessary to go from Spring Batch 2 -> 3 in MySQL. Curious if one exists?
After running a quick comparison of the schemas, these appear to be the changes for upgrading from Spring Batch 2.2.7.RELEASE -> 3.0.1.RELEASE on MySQL.
ALTER TABLE `BATCH_JOB_EXECUTION` MODIFY COLUMN `EXIT_CODE` varchar(2500) DEFAULT NULL;
ALTER TABLE `BATCH_JOB_EXECUTION` ADD COLUMN `JOB_CONFIGURATION_LOCATION` varchar(2500) DEFAULT NULL;
ALTER TABLE `BATCH_JOB_EXECUTION_SEQ` ADD COLUMN `UNIQUE_KEY` char(1) NOT NULL;
ALTER TABLE `BATCH_JOB_EXECUTION_SEQ` ADD UNIQUE KEY `UNIQUE_KEY_UN` (`UNIQUE_KEY`);
ALTER TABLE `BATCH_JOB_SEQ` ADD COLUMN `UNIQUE_KEY` char(1) NOT NULL;
ALTER TABLE `BATCH_JOB_SEQ` ADD UNIQUE KEY `UNIQUE_KEY_UN` (`UNIQUE_KEY`);
ALTER TABLE `BATCH_STEP_EXECUTION` MODIFY COLUMN `EXIT_CODE` varchar(2500) DEFAULT NULL;
ALTER TABLE `BATCH_STEP_EXECUTION_SEQ` ADD COLUMN `UNIQUE_KEY` char(1) NOT NULL;
ALTER TABLE `BATCH_STEP_EXECUTION_SEQ` ADD UNIQUE KEY `UNIQUE_KEY_UN` (`UNIQUE_KEY`);
For anyone who wants to know the DDL changes for postgresql:
ALTER TABLE BATCH_JOB_EXECUTION ALTER COLUMN EXIT_CODE TYPE varchar(2500);
ALTER TABLE BATCH_JOB_EXECUTION ADD COLUMN JOB_CONFIGURATION_LOCATION varchar(2500) DEFAULT NULL;
ALTER TABLE BATCH_STEP_EXECUTION ALTER COLUMN EXIT_CODE TYPE varchar(2500);
This worked for me when I upgraded from 2.2.7.RELEASE -> 3.0.7.RELEASE.
Really surprised there's no migration guide/or scripts, at least that I could find.
Related
I have a table in oracle with primary key and auto increment attribute. But sometimes I have preset ID value for the record.
So when I try to insert record I get exception your trying to insert into table with auto increment field.
So in SQLDeveloper I tried by disabling triggering and inserting values and then enabling trigger which worked perfectly
ALTER TABLE TABLE_NAME DISABLE ALL TRIGGERS;
INSERT INTO TABLE_NAME SELECT * FROM ARCHIVE_TABLE_NAME WHERE TABLE_NAME_COLUMN >= '27-JUN-16 10.35.12.945000000';
ALTER TABLE TABLE_NAME ENABLE ALL TRIGGERS;
But I would like to do this grammatically through hibernate.
So I have following questions
1) If is there any other way of inserting records in table with auto incremtn field?
2) If no then how to execute above 3 statements in hibernate
you can insert records with auto increment key by using the following jpa annotation on your auto incremented field
#GeneratedValue(generator="InvSeq")
#SequenceGenerator(name="InvSeq",sequenceName="INV_SEQ", allocationSize=5)
private long autoIncId;
see this link http://www.oracle.com/technetwork/middleware/ias/id-generation-083058.html
I am trying to create a Vertica table with JOOQ 3.5.x:
Connection connection = create();
DSLContext dslContext = DSL.using(connection);
Field<String> myColumn = DSL.field("my_column", SQLDataType.VARCHAR);
Table table = DSL.tableByName("my_schema", "my_table");
dslContext.createTable(table)
.column(myColumn, myColumn.getDataType())
.execute();
This fails on Schema "my_schema" does not exist.
I can solve it with:
dslContext.execute("create schema if not exists my_schema");
But is there a more elegant way to create a schema with JOOQ?
Currently JOOQ covers just a subset of the possible DDL statements that can be executed against a server and schema management is not yet included so you have to drop back to plan old SQL.
If you need to do a lot of DDL work you should start to look at the latest version 3.8 as this has extend the capabilities to include
DEFAULT column values in CREATE TABLE or ALTER TABLE statements
IF EXISTS in DROP statements
IF NOT EXISTS in CREATE statements
ALTER TABLE .. { RENAME | RENAME COLUMN | RENAME CONSTRAINT } statements
Version 3.6 added
ALTER TABLE ADD CONSTRAINT (with UNIQUE, PRIMARY KEY, FOREIGN KEY, CHECK)
ALTER TABLE DROP CONSTRAINT
CREATE TEMPORARY TABLE
I am using java DB database and NetBeans 8.0 for a desktop application
I am also using a PreparedStatement to query the database.
below is the code for creating the tables.
CREATE TABLE ALUMNUS (
ALUMNUA_ID INT NOT NULL PRIMARY KEY
GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1),
FIRST_NAME VARCHAR (45),
LAST_NAME VARCHAR (45),
OTHER_NAME VARCHAR (100)
);
CREATE TABLE DUES (
ID INT NOT NULL PRIMARY KEY
GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1),
PAYMENT_YEAR DATE,
AMOUNT DOUBLE,
ALUMNUS_ID INT
);
--FOREIGN KEY
ALTER TABLE APP.DUES
ADD FOREIGN KEY (ALUMNUS_ID) REFERENCES APP.ALUMNUS(ID);
Now I want to insert, delete and update the foreign key values in APP.DUES table. what is the best option; trigger , stored procedure or the preparedstatement?
An example will be good.
If you want to primarily insert into the DUES table, you would use a sub select in SQL. I havent tested it with Java DB, but it basically looks like:
INSERT INTO DUES(PAYMENT_YEAR, AMOUNT,ALUMNUS_ID)
VALUES(2014, 100.0,
(SELECT ALUMNUA_ID from ALUMNUS where ...));
You need to catch the "not found" error case and prepend a INSERT (and need to catch the duplicate case for that as well).
See also: Insert Data Into Tables Linked by Foreign Key
Till recent time i was using hibernate #Entity annotation to map to database tables.All the primary keys are annotated with #GeneratedValue(strategy = GenerationType.IDENTITY)
I got a scenario where i need to create new schema + migrate data from old schema into new schema.(with few column changes like drop, length and type)
After successful migration of data to new schema tables when i try to insert data using Application its throwing an exception
[ERROR] util.JDBCExceptionReporter DB2 SQL Error: SQLCODE=-803, SQLSTATE=23505, SQLERRMC=1; _NewSchema_._TableName_ , DRIVER=3.51.90
I believe that application is trying to insert rows again with Primary key value starting from 1 because same application is working fine with empty tables.
I want data rows to be inserted with its primary key value as highest value of existing rows primary key .
Any help will be thank full :)
Yes you can do that by altering the table. Alter the table and set starting index for identity column in DB2.
Suppose maximum rows for TBALE_A is 50 and name of identity column is TABLE_ID
ALTER TABLE TBALE_A ALTER COLUMN TABLE_ID
RESTART WITH 51
Your guess is correct, here is my solution, execute the following SQL to give the ID column a specified start position, then your application will work fine.
alter table TABLE_NAME alter column ID set GENERATED BY DEFAULT RESTART WITH 10000;
Hope to help you :)
In case of generation type , IDENTITY, you should look for identity column to be auto incemental.
#GeneratedValue(strategy = GenerationType.IDENTITY) required primary key column to be auto incremental.
Am using JPA into my application and then the when insert different objects the database use sequential ids.
For Example:
If i have table member and table user , when inserting object of type user will take id = 1 then add object into table member will take id = 2 .
The problem is : i imported a .sql file into the database.
Then when i insert a new record from my application it cause an exception because it use ids already added.
How can i solve this problem ?
You can set the start value for AUTO_INCREMENT as
ALTER TABLE tbl AUTO_INCREMENT = 100;
See also:
3.6.9. Using AUTO_INCREMENT