-
Dec 18th, 2005, 09:24 PM
#1
BatchSqlUpdate inconsistent dependency injection to normal object creation
Hi
I wanted to use BatchSqlUpdate feature as I wanted to insert 30000 records from a web-app to DB. I am using a DAO class by extending org.springframework.jdbc.core.support.JdbcDaoSuppo rt class. I have written a method in the DAO class as below...
private BatchSqlUpdate batchSqlUpdate;
// set and get methods for BatchSqlUpdate...
pulic void processBatch(Object [] data) {
batchSqlUpdate.update(data);
}
Now I wanted to induce the BatchSqlUpdate as a dependency which is failing.
<bean id="batchSqlUpdate"
class="org.springframework.jdbc.object.BatchSqlUpd ate">
<constructor-arg index="0"><ref bean="dataSource"/></constructor-arg>
<constructor-arg index="1"><value>INSERT INTO RINGTONES_LOAD ( PROVIDER_NM, PERIOD_START_DT, PERIOD_END_DT, VENDOR_NM, COUNTRY_CD, PRODUCT_NO, UPC_CD, ISRC_CD, GRID_NO, BMG_TRACK_NO, PROD_TYPE, UNITS_DELIVERED_QT, PPD, WHOLESALE_VAL, RETAIL_VAL, CURRENCY_CD, TRANS_TYPE, SERVICE_TYPE, DIGITAL_USE, MEDIA_TYPE_KY, PRODUCT_ARTIST_NM, PRODUCT_NM, SONG_TITLE_TX ) VALUES ( ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)</value></constructor-arg>
</bean>
Above is the batchSqlUpdate object configuration. How to induce BatchSqlUpdate as a dependency ?
Can any one tell me what is the best way to use BatchSqlUpdate where I need to process a large a file uploaded and the use the DAO to insert the data using BatchSqlUpdate in to DB. And also I have to seperate the file processing and DB operations seperate. Looking forward for a help!!!
Exception:
2005-11-04 22:01:19,906 ERROR [org.springframework.web.context.ContextLoader] - Context initialization failed
org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'batchSqlUpdate' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is org.springframework.dao.InvalidDataAccessApiUsageE xception: SQL 'INSERT INTO RINGTONES_LOAD ( PROVIDER_NM, PERIOD_START_DT, PERIOD_END_DT, VENDOR_NM, COUNTRY_CD, PRODUCT_NO, UPC_CD, ISRC_CD, GRID_NO, BMG_TRACK_NO, PROD_TYPE, UNITS_DELIVERED_QT, PPD, WHOLESALE_VAL, RETAIL_VAL, CURRENCY_CD, TRANS_TYPE, SERVICE_TYPE, DIGITAL_USE, MEDIA_TYPE_KY, PRODUCT_ARTIST_NM, PRODUCT_NM, SONG_TITLE_TX ) VALUES ( ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)' requires 23 bind variables, but 0 variables were declared for this object
org.springframework.dao.InvalidDataAccessApiUsageE xception: SQL 'INSERT INTO RINGTONES_LOAD ( PROVIDER_NM, PERIOD_START_DT, PERIOD_END_DT, VENDOR_NM, COUNTRY_CD, PRODUCT_NO, UPC_CD, ISRC_CD, GRID_NO, BMG_TRACK_NO, PROD_TYPE, UNITS_DELIVERED_QT, PPD, WHOLESALE_VAL, RETAIL_VAL, CURRENCY_CD, TRANS_TYPE, SERVICE_TYPE, DIGITAL_USE, MEDIA_TYPE_KY, PRODUCT_ARTIST_NM, PRODUCT_NM, SONG_TITLE_TX ) VALUES ( ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)' requires 23 bind variables, but 0 variables were declared for this object
at org.springframework.jdbc.object.SqlOperation.compi leInternal(SqlOperation.java:55)
at org.springframework.jdbc.object.RdbmsOperation.com pile(RdbmsOperation.java:303)
at org.springframework.jdbc.object.RdbmsOperation.aft erPropertiesSet(RdbmsOperation.java:281)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.invokeInitMethods(Abstr actAutowireCapableBeanFactory.java:809)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.initializeBean(Abstract AutowireCapableBeanFactory.java:778)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:359)
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:226)
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:147)
at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:262)
at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:330)
at org.springframework.web.context.support.AbstractRe freshableWebApplicationContext.refresh(AbstractRef reshableWebApplicationContext.java:150)
at org.springframework.web.context.ContextLoader.crea teWebApplicationContext(ContextLoader.java:246)
at org.springframework.web.context.ContextLoader.init WebApplicationContext(ContextLoader.java:184)
at org.springframework.web.context.ContextLoaderListe ner.contextInitialized(ContextLoaderListener.java: 49)
at org.apache.catalina.core.StandardContext.listenerS tart(StandardContext.java:3692)
at org.apache.catalina.core.StandardContext.start(Sta ndardContext.java:4127)
at org.apache.catalina.core.ContainerBase.addChildInt ernal(ContainerBase.java:759)
at org.apache.catalina.core.ContainerBase.addChild(Co ntainerBase.java:739)
at org.apache.catalina.core.StandardHost.addChild(Sta ndardHost.java:524)
at org.apache.catalina.startup.HostConfig.deployDirec tory(HostConfig.java:910)
at org.apache.catalina.startup.HostConfig.deployDirec tories(HostConfig.java:873)
at org.apache.catalina.startup.HostConfig.deployApps( HostConfig.java:474)
at org.apache.catalina.startup.HostConfig.start(HostC onfig.java:1118)
at org.apache.catalina.startup.HostConfig.lifecycleEv ent(HostConfig.java:310)
at org.apache.catalina.util.LifecycleSupport.fireLife cycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.core.ContainerBase.start(Conta inerBase.java:1020)
at org.apache.catalina.core.StandardHost.start(Standa rdHost.java:718)
at org.apache.catalina.core.ContainerBase.start(Conta inerBase.java:1012)
at org.apache.catalina.core.StandardEngine.start(Stan dardEngine.java:442)
at org.apache.catalina.core.StandardService.start(Sta ndardService.java:450)
at org.apache.catalina.core.StandardServer.start(Stan dardServer.java:680)
at org.apache.catalina.startup.Catalina.start(Catalin a.java:536)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknow n Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Un known Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootst rap.java:275)
at org.apache.catalina.startup.Bootstrap.main(Bootstr ap.java:413)
Thanks & Regards
Ramesh Mandaleeka
Last edited by RameshMandaleeka; Dec 20th, 2005 at 05:10 AM.
-
Dec 19th, 2005, 06:43 AM
#2
Hi,
Since you are not passing in the values to the sql insert statement you are getting this error.For each of the parameters you have to give a declaration.
It is similar to what you do in case of Stored Procedures.And when you are calling the update function pass in the values.
Hope that helps.
-
Dec 19th, 2005, 07:14 PM
#3
BatchSqlUpdate inconsistent dependency injection to normal object creation
BatchSqlUpdate class is having overloaded constructors. The BatchSqlUpdate(DataSource , String) is the constructor i used for dependency injection. But the DI container is expecting BatchSqlUpdate(DataSource, String, int[]) as the super class RdbmsOperation afterPropertiesSet() method is trying to compile the Statement. As I am using the BatchSqlUpdate(DataSourcde, String) construtor. The object initialization is not complete so there by DI is failing.
But programatically
BatchSqlUpdate bsu = new BatchSqlUpdate(DataSorce, SQL);
Object [] someObjects = ...;
bsu.update(someObjects);
Will work fine though I didnt specified int [] types of the parameters.
So what is the way out. Can I DI int[] ??? If yes how can do? Can any one mention the syntax for this.
Any other solutions please kindly post.
Thanks & Regards
Ramesh
-
Mar 2nd, 2007, 04:57 AM
#4
I have the same issue. Could you please help me?
Regards,
Sreedhar
-
Mar 2nd, 2007, 07:21 AM
#5
This appears to be a bug. BatchSqlUpdate doesn't have declared parameters. I believe it wouldn't normally come up because BatchSqlUpdate is not thread-safe and is not usually created inside an ApplicationContext. But that shouldn't disqualify its use. You certainly could make it a non-singleton bean. I would recommend posting a bug on Jira.
However, I would also recommend not creating one inside an application context, but using new and using inside a DAO which has the DataSource set, so you can construct a new object for each batch operation.
Bill
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules