Related
I am trying to integrate Spring batch admin to existing spring batch program. This runs fine with hsqldb, but when we configure it to DB2 it throws SqlIntegrityConstraintViolationException. Db2 tables were already created in the DB2 with the default script provided in the admin jar.
We are using quartz scheduler to trigger the jobs.
Here is the exception trace
Caused by: org.springframework.dao.DataIntegrityViolationException: PreparedStatementCallback; SQL [INSERT into OD1.ABC_BATCH_JOB_EXECUTION(JOB_EXECUTION_ID, JOB_INSTANCE_ID, START_TIME, END_TIME, STATUS, EXIT_CODE, EXIT_MESSAGE, VERSION, CREATE_TIME, LAST_UPDATED, JOB_CONFIGURATION_LOCATION) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)]; AN UPDATE, INSERT, OR SET VALUE IS NULL, BUT THE OBJECT COLUMN *N CANNOT CONTAIN NULL VALUES. SQLCODE=-407, SQLSTATE=23502, DRIVER=3.62.56; nested exception is com.ibm.db2.jcc.am.SqlIntegrityConstraintViolationException: AN UPDATE, INSERT, OR SET VALUE IS NULL, BUT THE OBJECT COLUMN *N CANNOT CONTAIN NULL VALUES. SQLCODE=-407, SQLSTATE=23502, DRIVER=3.62.56
at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:249)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:605)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:818)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:874)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:878)
at org.springframework.batch.core.repository.dao.JdbcJobExecutionDao.saveJobExecution(JdbcJobExecutionDao.java:157)
Configuration is as follows
#DB2 configuration
batch.job.jndi=jdbc/DBOMS
batch.tableprefix=OD1.ABC_BATCH_
batch.schema.script=
batch.drop.script=
batch.business.schema.script=
batch.database.incrementer.class=org.springframework.jdbc.support.incrementer.DB2SequenceMaxValueIncrementer
batch.job.configuration.file.dir=target/config
batch.data.source.init=false
batch.job.service.reaper.interval=60000
batch.isolationlevel=ISOLATION_READ_COMMITTED
batch.jdbc.testWhileIdle=false
batch.jdbc.validationQuery=
batch.database.incrementer.parent=sequenceIncrementerParent
batch.table.prefix=OD1.ABC_BATCH_
We found the issue , We gave the table scripts to DBA. But DBA created the table to match the standards they follow and made it
START_TIME TIMESTAMP NOT NULL WITH DEFAULT instead of START_TIME TIMESTAMP DEFAULT NULL. This is causing the issue, hope this helps someone.
I recently updated customer and order information on my dev site and then pushed it live (without updating the increment_last_id). Our checkout is no longer processing credit card orders and when I check the exception log I get these 2 related errors:
exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '100000001' for key 'UNQ_SALES_FLAT_INVOICE_INCREMENT_ID'' in /home/tebostorefixture/public_html/lib/Zend/Db/Statement/Pdo.php:228
Next exception 'Zend_Db_Statement_Exception' with message 'SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '100000001' for key 'UNQ_SALES_FLAT_INVOICE_INCREMENT_ID', query was: INSERT INTO `sales_flat_invoice` (`store_id`, `base_grand_total`, `shipping_tax_amount`, `tax_amount`, `base_tax_amount`, `store_to_order_rate`, `base_shipping_tax_amount`, `base_discount_amount`, `base_to_order_rate`, `grand_total`, `shipping_amount`, `subtotal_incl_tax`, `base_subtotal_incl_tax`, `store_to_base_rate`, `base_shipping_amount`, `total_qty`, `base_to_global_rate`, `subtotal`, `base_subtotal`, `discount_amount`, `billing_address_id`, `order_id`, `state`, `shipping_address_id`, `store_currency_code`, `transaction_id`, `order_currency_code`, `base_currency_code`, `global_currency_code`, `increment_id`, `created_at`, `updated_at`, `hidden_tax_amount`, `base_hidden_tax_amount`, `shipping_hidden_tax_amount`, `discount_description`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, '2016-12-12 18:48:11', '2016-12-12 18:48:11', ?, ?, ?, ?)' in /home/mystore/public_html/lib/Zend/Db/Statement/Pdo.php:235
At first, the error had been attempting to duplicate entries around 100000027 and was going up each time we tried an order. So I went into eav_entity_store and changed the increment_last_id to 1 higher than our last order (100000117).
I re-indexed and cleared the cache. But now I'm getting this same error except its trying to duplicate 100000001. No matter how many times I try it, it keeps trying to duplicate that first order number. I went back and checked and the increment_last_id is going up correctly with each transaction that we try, but this error of duplicating 100000001 continues.
Problem Solved.
For some reason I was missing 3 rows in eav_entity_store. One of those rows was for invoices and was necessary.
I wasn't able to export/import the rows successfully from our old database so I copied down their numbers and manually created the tables with the appropriate numbers.
Use the following code to resolve your error:
TRUNCATE dataflow_batch_export ;
TRUNCATE dataflow_batch_import ;
TRUNCATE log_customer ;
TRUNCATE log_quote ;
TRUNCATE log_summary ;
TRUNCATE log_summary_type ;
TRUNCATE log_url ;
TRUNCATE log_url_info ;
TRUNCATE log_visitor ;
TRUNCATE log_visitor_info ;
TRUNCATE log_visitor_online ;
TRUNCATE report_event ;
Or
You can try following.
In app/code/core/Mage/Sales/Model/Resource/Quote.php
Search for isOrderIncrementIdUsed method
In that method,
replace
$bind = array(':increment_id' => (int)$orderIncrementId);
with
$bind = array(':increment_id' => $orderIncrementId);
Hope, one of these two solutions will resolve your problem.
Feel free to ask for any other help!
I am writing one spring batch based application in which i have to write a consolidated xml file data into multiple tables of database.
bean id="mysqlItemWriter"
class="org.springframework.batch.item.database.JdbcBatchItemWriter">
<property name="dataSource" ref="dataSource" />
<property name="sql">
<value>
<![CDATA[
INSERT INTO LEASE (LEASE_ID, CONTRACT_TYPE, CONTRACT_NUMBER, LEASE_AMOUNT, DESCRIPTION, CREATE_DATE, REGISTER_DATE)
VALUES ( :leaseId, :contractType, :contactNumber, :leaseAmount, :description, :leaseCreateDate, :leaseUpdateDate)
INSERT INTO CUSTOMER (CUSTOMER_ID ,FIRST_NAME, LAST_NAME, SURNAME, CUSTOMER_NUMBER, RECORD_CODE,
SOURCE_SYSTEM, BIRTH_DATE,CREATE_DATE, UPDATE_DATE,ADDRESS,STREET,HOUSE_NUMBER,
STATE, POSTAL_CODE, COUNTRY_CODE )
VALUES ( :customerId , :firstname, :lastName ,:surname, :customerNumber, :recordCode, :SourceSystem,
:birthDate, :leaseCreateDate, :leaseUpdateDate, :address, :houseNumber, :city, :state, :postalcode,
:countryCode)
]]>
</value>
In the above code when only one SQL statement is there it is working fine but for two insert statements it is not working fine. It is giving the error as
"ORA-00933: SQL command not properly ended" .
When i am inserting ; after first insert statement it is showing the same error
I am not able to resolve this..
You can always try wrapping your 2 statements inside a PL/SQL anonymous block (Make sure you don't forget any of the required semi colons).
begin
insert into ...;
insert into ...;
end;
Technically, it should then be treated as a single statement and should work.
bean id="mysqlItemWriter"
class="org.springframework.batch.item.database.JdbcBatchItemWriter">
<property name="dataSource" ref="dataSource" />
<property name="sql">
<value>
<![CDATA[
begin
INSERT INTO LEASE (LEASE_ID, CONTRACT_TYPE, CONTRACT_NUMBER, LEASE_AMOUNT, DESCRIPTION, CREATE_DATE, REGISTER_DATE)
VALUES ( :leaseId, :contractType, :contactNumber, :leaseAmount, :description, :leaseCreateDate, :leaseUpdateDate);
INSERT INTO CUSTOMER (CUSTOMER_ID ,FIRST_NAME, LAST_NAME, SURNAME, CUSTOMER_NUMBER, RECORD_CODE,
SOURCE_SYSTEM, BIRTH_DATE,CREATE_DATE, UPDATE_DATE,ADDRESS,STREET,HOUSE_NUMBER,
STATE, POSTAL_CODE, COUNTRY_CODE )
VALUES ( :customerId , :firstname, :lastName ,:surname, :customerNumber, :recordCode, :SourceSystem,
:birthDate, :leaseCreateDate, :leaseUpdateDate, :address, :houseNumber, :city, :state, :postalcode,
:countryCode);
end;
]]>
</value>
There is a good description of the issue here:
http://forum.liquibase.org/topic/formatted-sql-enddelimiter-issue
I suggest adding the "/" to see if that works in combination with
endDelimiter:/ or using splitStatement:false
I'm having an error when I'm creating my in-memory database.
When I start up my program on my Tomcat Server, it seems to run fine, until I try and insert into the database.
My Tomcat log reveals the following:
Hibernate: alter table BrokerReferrerJoin drop constraint FK_cfc92321040c4c7e94cd7d7f0f0
Hibernate: alter table BrokerTable drop constraint FK_85c86a6cd9d14a23840e4746545
Hibernate: alter table LeadTable drop constraint FK_26c301acde8d4daa93734bda8ff
Hibernate: alter table LeadTable drop constraint FK_d358f93455874bcba7ed6afd996
Hibernate: alter table ReferrerBrokerJoin drop constraint FK_60dc4e2e6a44406a8fdf4e869e8
Hibernate: alter table ReferrerTable drop constraint FK_910ad4a791e9434da73fbc24ba5
Hibernate: drop table BrokerReferrerJoin if exists
Hibernate: drop table BrokerTable if exists
Hibernate: drop table LeadTable if exists
Hibernate: drop table Person if exists
Hibernate: drop table ReferrerBrokerJoin if exists
Hibernate: drop table ReferrerTable if exists
Hibernate: alter table BrokerReferrerJoin drop constraint FK_7100b66fe58043ed9fcba0c116c
Hibernate: alter table BrokerTable drop constraint FK_b5a6bbb0789c46b39597c4eb788
Hibernate: alter table LeadTable drop constraint FK_e19293e489d2443f80cef09bf10
Hibernate: alter table LeadTable drop constraint FK_0a56acd9932f4f4f930f1b4c23b
Hibernate: alter table ReferrerBrokerJoin drop constraint FK_c700fee7563d461fb33336901e7
Hibernate: alter table ReferrerTable drop constraint FK_c449adf2fb9e4f4d985c944d852
Hibernate: drop table BrokerReferrerJoin if exists
Hibernate: drop table BrokerTable if exists
Hibernate: drop table LeadTable if exists
Hibernate: drop table Person if exists
Hibernate: drop table ReferrerBrokerJoin if exists
Hibernate: drop table ReferrerTable if exists
Hibernate: create table BrokerReferrerJoin (FlexRowIDLink varchar(255) not null, InternalReferrerIDLink varchar(255) not null)
Hibernate: create table BrokerTable (AdminID varchar(255), isAdmin boolean, FlexRowID varchar(255) not null, primary key (FlexRowID))
Hibernate: create table LeadTable (LeadID varchar(255) generated by default as identity (start with 1), Amount double, FlexRowID varchar(255), LeadEmail varchar(50), LeadFName varchar(50) not null, HPhoneNo integer, LeadLName varchar(50) not null, MPhoneNo bigint, Notes varchar(4095), WPhoneNo integer, Status varchar(255), LoanType varchar(255), leadBroker_FlexRowID varchar(255), leadReferrer_FlexRowID varchar(255), primary key (LeadID))
Hibernate: create table Person (FlexRowID varchar(255) not null, CreatedOn date, Email varchar(255), FName varchar(255), LName varchar(255), LastUpdated date, OrgID varchar(255), OrgName varchar(255), Username varchar(255), primary key (FlexRowID))
Hibernate: create table ReferrerBrokerJoin (InternalReferrerIDLink varchar(255) not null, FlexRowIDLink varchar(255) not null)
Hibernate: create table ReferrerTable (LTSRowID varchar(255), FlexRowID varchar(255) not null, primary key (FlexRowID))
Hibernate: alter table BrokerReferrerJoin add constraint UK_bc91f298149c4420bc453811411 unique (InternalReferrerIDLink)
Hibernate: alter table BrokerReferrerJoin add constraint FK_7100b66fe58043ed9fcba0c116c foreign key (FlexRowIDLink) references BrokerTable
Hibernate: alter table BrokerTable add constraint FK_b5a6bbb0789c46b39597c4eb788 foreign key (FlexRowID) references Person
Hibernate: alter table LeadTable add constraint FK_e19293e489d2443f80cef09bf10 foreign key (leadBroker_FlexRowID) references BrokerTable
Hibernate: alter table LeadTable add constraint FK_0a56acd9932f4f4f930f1b4c23b foreign key (leadReferrer_FlexRowID) references ReferrerTable
Hibernate: alter table ReferrerBrokerJoin add constraint UK_836e448745504545aaa39709e22 unique (FlexRowIDLink)
Hibernate: alter table ReferrerBrokerJoin add constraint FK_c700fee7563d461fb33336901e7 foreign key (FlexRowIDLink) references BrokerTable
Hibernate: alter table ReferrerTable add constraint UK_b0c668bb487b4a1d8b5f7b9657b unique (LTSRowID)
Hibernate: alter table ReferrerTable add constraint FK_c449adf2fb9e4f4d985c944d852 foreign key (FlexRowID) references Person
18:52:45.573 [http-bio-8080-exec-3] ERROR com.au.curtin.Lead.HibernateLeadDao - The sessionFactory was set: org.springframework.orm.hibernate4.LocalSessionFactoryBean#6c80d028
18:52:45.592 [http-bio-8080-exec-3] ERROR com.au.curtin.Lead.LeadServiceClass - The HibernateLeadDao was set: com.au.curtin.Lead.HibernateLeadDao#1c90a278
18:52:49.862 [http-bio-8080-exec-7] ERROR com.au.curtin.LoginController - Starting logger
18:52:54.253 [http-bio-8080-exec-9] ERROR com.au.curtin.LeadController - Returning Referrer Home View
18:53:01.035 [http-bio-8080-exec-10] ERROR com.au.curtin.LeadController - org.springframework.validation.BeanPropertyBindingResult: 0 errors
18:53:01.035 [http-bio-8080-exec-10] ERROR com.au.curtin.Lead.LeadServiceClass - Home Phone Number: 94572707Work Phone Number : nullMobile Phone Number: nullEmail :
18:53:01.098 [http-bio-8080-exec-10] ERROR com.au.curtin.Lead.LeadServiceClass - com.au.curtin.Lead.HibernateLeadDao#1c90a278
18:53:01.098 [http-bio-8080-exec-10] ERROR com.au.curtin.Lead.HibernateLeadDao - Lead : Lead [leadID=null, flexRowID=null, leadFirstName=James, leadLastName=Massey, leadHomePhoneNumber=94572707, leadWorkPhoneNumber=null, leadMobilePhoneNumber=null, borrowingAmount=1000.0, leadEmail=, loanType=null, leadNotes=, leadBroker=null, leadReferrer=null, loanStatus=null]Session is: SessionImpl(PersistenceContext[entityKeys=[],collectionKeys=[]];ActionQueue[insertions=[] updates=[] deletions=[] collectionCreations=[] collectionRemovals=[] collectionUpdates=[] unresolvedInsertDependencies=UnresolvedEntityInsertActions[]])
Hibernate: insert into LeadTable (LeadID, Amount, FlexRowID, leadBroker_FlexRowID, LeadEmail, LeadFName, HPhoneNo, LeadLName, MPhoneNo, Notes, leadReferrer_FlexRowID, WPhoneNo, Status, LoanType) values (default, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
I don't know why it is suddenly causing this error.
All the fields are set with annotations.
Here is my Spring .xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">
<tx:annotation-driven transaction-manager="transactionManager" />
<jdbc:embedded-database id="LTSDatabase" type="HSQL" />
<context:component-scan base-package="x.y" />
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="LTSDatabase" />
<property name="annotatedClasses">
<list>
<value>x.y.Lead</value>
<value>x.y.Broker</value>
<value>x.y.Referrer</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
</bean>
<bean id="PersistenceAnnotationPostProcessor"
class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
<bean id="hibernateExceptionTranslator"
class="org.springframework.orm.hibernate4.HibernateExceptionTranslator" />
<bean
class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"
id="PersistenceExceptionTranslator" depends-on="hibernateExceptionTranslator" />
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
</beans>
As you can see I'm using annotations for setting up the database, and for my transactions.
I don't know why this error is occurring. If anyone knows why this is happening, please tell me.
I'm using Spring 3, Hibernate 4.2, and Tomcat 7 if that helps.
Just in case this helps anyone, my problem was that I was trying to make my field that was going to be my primary key declared as a String. Hibernate can't handle a non-numerical auto-generated primary key.
i am working on a project using Hibernate 3.3.SP1 + Spring 1.2.6 on Weblogic 10.3.1 with Oracle DB 10g. Recently, we migrated Hibernate from v3.0.5 to 3.3.SP1.A strange error occurs (that did not happen before) when trying to insert LOB (BLOB or CLOB). I get the following error :
189202 [[ACTIVE] ExecuteThread: '10' for queue: 'weblogic.kernel.Default (self-tuning)']
WARN org.hibernate.util.JDBCExceptionReporter - SQL Error: 0, SQLState: null
189202 [[ACTIVE] ExecuteThread: '10' for queue: 'weblogic.kernel.Default (self-tuning)']
ERROR org.hibernate.util.JDBCExceptionReporter - Pool connect failed :
weblogic.common.ResourceException:
my.wls.datasource(dtJndiName): 0:
Could not connect to 'oracle.jdbc.OracleDriver'.
The returned message is:
ORA-01017: invalid username/password; logon denied
It is likely that the login or password is not valid.
It is also possible that something else is invalid in
the configuration or that the database is not available.
After that, the datasource gets "corrupted" and after 10 consecutive false connection attempts Oracle locks the account.
I must notice that the application has absolutely no code for connecting to the database, other than the pre-configured datasource in Weblogic. Since the application works just fine until a LOB is inserted in the DB it is safe to assume that the datasource is properly configured.
A sample mapping (I cannot post the exact hbm.xml) is :
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="my.model.persist">
<class name="LobTable" table="LOB_TABLE">
<id name="id" type="long" column="RS_ID" unsaved-value="null" length="10">
<generator class="native"></generator>
</id>
<property name="blob1" type="org.springframework.orm.hibernate3.support.BlobByteArrayType" column="BLOB1"></property>
<property name="blob2" type="org.springframework.orm.hibernate3.support.BlobByteArrayType" column="BLOB2"></property>
</class>
</hibernate-mapping>
The code tries to persist some LOB values in three tables. The error appears when trying to save to the first. If I remove the code for saving to the first, the error appears on the second and so on.
The only solution I have found up to now, is to set the Initial Capacity of the datasource connections to the max connections (15). In this case, the system seems stable. However this solution is not acceptable since we do not understand the nature of the problem.
I have tried this in four different environments (Weblogic + Oracle). The error does not appear always with the same frequency (in some systems it works for a while before failing to insert a LOB). Also, while debugging I noticed that if I increase the log output (I simply added more debug messages in log4j) the error stop appearing. This made me think it could be a sync problem between WLS and DB.
Do you have any ideas? Please let me know if you need more clarifications.
The result after enabling Hibernate query output and changing the hbm.xml to have LOBs as the last fields declared is still the same error:
Hibernate: select hibernate_sequence.nextval from dual
Hibernate: select hibernate_sequence.nextval from dual
Hibernate: insert into LOB_TABLE_1 (field20, field21, field22, field23, field24, field25, field26, field27, field28, field29, field30, field31, LOB_FIELD_3, LOB_FIELD_4, ID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
Hibernate: insert into LOB_TABLE_2 (field1, field2, field3, field4, field5, field6, field7, field8, field9, field10, field11, field12, field13, field14, field15, field16, LOB_FIELD_1, LOB_FIELD_2, ID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
105039 [[ACTIVE] ExecuteThread: '11' for queue: 'weblogic.kernel.Default (self-tuning)'] WARN org.hibernate.util.JDBCExceptionReporter - SQL Error: 0, SQLState: null
105039 [[ACTIVE] ExecuteThread: '11' for queue: 'weblogic.kernel.Default (self-tuning)'] ERROR org.hibernate.util.JDBCExceptionReporter - Pool connect failed : weblogic.common.ResourceException:
my.wls.datasource(dtJndiName): 0:
Could not connect to 'oracle.jdbc.OracleDriver'.
The returned message is: ORA-01017: invalid username/password; logon denied
It is likely that the login or password is not valid.
It is also possible that something else is invalid in
the configuration or that the database is not available.