Re: Transaction Rollback not working with iBatis + Spring
Both tables are linked by constraints on primary keys, so i can't make only one insert. I must have missed something with the ibatis config or the doa manager. Thanks for your time. Bruno - To unsubscribe, e-mail: user-java-unsubscr...@ibatis.apache.org For additional commands, e-mail: user-java-h...@ibatis.apache.org
Re: Transaction Rollback not working with iBatis + Spring
Larry Meadors larry.meadors at gmail.com writes: Wait - I'm REALLY confused. Can you post a stack trace? Doh, I just noticed - this conversation should be on the new list. Maybe it's time to start this as a new thread and give us the stack trace and the relevant code anew. :) The ibatis project has moved and been renamed. It is no longer being maintained as an Apache project, but has moved (along with the development team) here: http://www.mybatis.org/ Please join us at the new location by joining the mailing list here: http://groups.google.com/group/mybatis-user Larry My SqlMapConfig.xml wasn't ok, i was using an EXTERNAL transaction manager instead of a JDBC... (sorry for that) Next time i'll post on the new list. Larry and Vinaya Thanks for your help ! Bruno - To unsubscribe, e-mail: user-java-unsubscr...@ibatis.apache.org For additional commands, e-mail: user-java-h...@ibatis.apache.org
Re: Transaction Rollback not working with iBatis + Spring
Hi, I'm facing the same problem. Did you solved it ? Thanks - To unsubscribe, e-mail: user-java-unsubscr...@ibatis.apache.org For additional commands, e-mail: user-java-h...@ibatis.apache.org
Re: Transaction Rollback not working with iBatis + Spring
You don't need the batch, and I'm pretty sure it won't ever work with the batch because the inserts don't happen when you call them (they happen when you call executeBatch()) so your ids don't get set when you expect them to. Remove the lines related to the batch, and I think it'll work. Larry On Wed, Jul 21, 2010 at 10:19 AM, Bruno Issenmann b.issenm...@labsoft.fr wrote: Hi, I'm facing the same problem. Did you solved it ? Thanks - To unsubscribe, e-mail: user-java-unsubscr...@ibatis.apache.org For additional commands, e-mail: user-java-h...@ibatis.apache.org - To unsubscribe, e-mail: user-java-unsubscr...@ibatis.apache.org For additional commands, e-mail: user-java-h...@ibatis.apache.org
Re: Transaction Rollback not working with iBatis + Spring
Thanks for ansering. I do not use the batch. I'm just doing two inserts then i commit. I still have an integrity contraint violation. - To unsubscribe, e-mail: user-java-unsubscr...@ibatis.apache.org For additional commands, e-mail: user-java-h...@ibatis.apache.org
RE: Transaction Rollback not working with iBatis + Spring
Sorry!! I missed the thread. Does it give you a runtime exception? Only if the code throws a runtime exception the transaction will be rolled back Vinaya -Original Message- From: Bruno Issenmann [mailto:b.issenm...@labsoft.fr] Sent: Wednesday, July 21, 2010 1:07 PM To: user-java@ibatis.apache.org Subject: Re: Transaction Rollback not working with iBatis + Spring Thanks for ansering. I do not use the batch. I'm just doing two inserts then i commit. I still have an integrity contraint violation. - To unsubscribe, e-mail: user-java-unsubscr...@ibatis.apache.org For additional commands, e-mail: user-java-h...@ibatis.apache.org This electronic message is intended only for the use of the individual(s) or entity(ies) named above and may contain information which is privileged and/or confidential. If you are not the intended recipient, be aware that any disclosure, copying, distribution, dissemination or use of the contents of this message is prohibited. If you received this message in error, please notify the sender immediately. - To unsubscribe, e-mail: user-java-unsubscr...@ibatis.apache.org For additional commands, e-mail: user-java-h...@ibatis.apache.org
How to do logging in iBatis + Spring
We use iBatis + Spring and make use of stored procedures to fetch information from Oracle DB. To find out what parameters (HashMap) is sent to the stored procedure we have to actually set debug points. We'd like this information to go to a log. Basically print out name of the Stored Proc + all that a HashMap contains (before calling the Stored procedure). Our setup is as below: Mapping: procedure id=getReportData parameterMap=getReportDataCall {call get_rpt (?,?,?,?)} /procedure parameterMap id=getReportDataCall class=map parameter property=type jdbcType=String javaType=java.lang.String mode=IN/ parameter property=month jdbcType=Int javaType=java.lang.Integer mode=IN/ parameter property=Result0 jdbcType=ORACLECURSOR javaType=java.sql.ResultSet mode=OUT resultMap=result1/ parameter property=Result1 jdbcType=ORACLECURSOR javaType=java.sql.ResultSet mode=OUT resultMap=result2/ /parameterMap resultMap id=select-first-result-hq class=VO result property=column1 column=columna/ result property=column2 column=columnb/ /resultMap We call our procedures like this: HashMap parm = new HashMap (); parm.put(type, type_val); parm.put(month, month_val); getSqlMapClientTemplate().queryForList(mymappingName.getReportData, parm); I could make a method that would take SP name + HashMap as parm and then just put it on the log but then i'd have to explicitly make a call to that method before I call the Stored procedure. I will take this as the last option as it involves me touching all my existing code. Is there any simpler solution to this?
Re: How to do logging in iBatis + Spring
Yes use standard logging or a logging framework like log4j. just set the following category name=java.sql priority value=debug / /category category name=org.ibatis priority value=debug / /category You can define them at a more granular level if you want. On Sun, Mar 7, 2010 at 8:13 AM, Bhaarat Sharma bhaara...@gmail.com wrote: We use iBatis + Spring and make use of stored procedures to fetch information from Oracle DB. To find out what parameters (HashMap) is sent to the stored procedure we have to actually set debug points. We'd like this information to go to a log. Basically print out name of the Stored Proc + all that a HashMap contains (before calling the Stored procedure). Our setup is as below: Mapping: procedure id=getReportData parameterMap=getReportDataCall {call get_rpt (?,?,?,?)} /procedure parameterMap id=getReportDataCall class=map parameter property=type jdbcType=String javaType=java.lang.String mode=IN/ parameter property=month jdbcType=Int javaType=java.lang.Integer mode=IN/ parameter property=Result0 jdbcType=ORACLECURSOR javaType=java.sql.ResultSet mode=OUT resultMap=result1/ parameter property=Result1 jdbcType=ORACLECURSOR javaType=java.sql.ResultSet mode=OUT resultMap=result2/ /parameterMap resultMap id=select-first-result-hq class=VO result property=column1 column=columna/ result property=column2 column=columnb/ /resultMap We call our procedures like this: HashMap parm = new HashMap (); parm.put(type, type_val); parm.put(month, month_val); getSqlMapClientTemplate().queryForList(mymappingName.getReportData, parm); I could make a method that would take SP name + HashMap as parm and then just put it on the log but then i'd have to explicitly make a call to that method before I call the Stored procedure. I will take this as the last option as it involves me touching all my existing code. Is there any simpler solution to this?
Ibatis + Spring
-- View this message in context: http://www.nabble.com/Ibatis-%2B-Spring-tp22745182p22745182.html Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
Transaction Rollback not working with iBatis + Spring
Hi, I have 2 tables CUSTOMER and DEPENDENT. In CUSTOMER table the primary key is cust_id which is foreign key to DEPENDENT table. I would like to make insert to both tables together as a batch and also if one fails than other must roll back. If I remove the constraints of having cust_id as a foreign key to DEPENDENT table than both insert works fine as required, it gets committed together and if any of it fails than none of the transaction will commit. But as soon as I have two tables related, it works fine for first insert to CUSTOMER table, when I make a call to insert() statement, it does not commit yet, but when it reaches second insert() stmt to DEPENDENT table it throws below exception: -- The error occurred in org/nexweb/qol/gcc/ibatis/dao/xml/Customer.xml. --- The error occurred while applying a parameter map. --- Check the insertCustomerDependent-InlineParameterMap. --- Check the statement (update failed). --- Cause: java.sql.SQLException: ORA-02291: integrity constraint (DEPENDENT_CUST_ID_FK) violated - parent key not found Can you check what am I missing ? I have also tried using SqlMapSession explicitly opening session and do all transaction but did not work. I have been trying since last 2 days, please help me out. Here is my code: I am using JDeveloper 10.1.3 as my IDE which has embedded OC4J application server. SqlMapConfig.xml properties resource=jdbc.properties/ transactionManager type=JDBC dataSource type=SIMPLE property name=JDBC.Driver value=${jdbc.driverClassName}/ property name=JDBC.ConnectionURL value=${jdbc.url}/ property name=JDBC.Username value=${jdbc.username}/ property name=JDBC.Password value=${jdbc.password}/ property name=JDBC.Class value=oracle.jdbc.pool.OracleDataSource/ property name=JDBC.DefaultAutoCommit value=false / property name=Pool.MaximumActiveConnections value=10/ property name=Pool.MaximumIdleConnections value=5/ property name=Pool.MaximumCheckoutTime value=12/ property name=Pool.TimeToWait value=500/ /dataSource /transactionManager sqlMap resource=org/nexweb/qol/gcc/ibatis/dao/xml/Customer.xml/ spring.xml beans bean id=sqlMapClient class=org.springframework.orm.ibatis.SqlMapClientFactoryBean property name=configLocation valueclasspath:org/nexweb/qol/gcc/ibatis/config/SqlMapConfig.xml/value /property /bean bean id=sqlMapClientTemplate class=org.springframework.orm.ibatis.SqlMapClientTemplate property name=sqlMapClient ref bean=sqlMapClient/ /property /bean bean id=customerDao class=org.nexweb.qol.gcc.ibatis.dao.sqlmaps.CustomerSqlMapDAO property name=sqlMapClient ref bean=sqlMapClient/ /property /bean bean id=customerService class=org.nexweb.qol.gcc.ibatis.services.CustomerService constructor-arg index=0 ref=customerDao/ /bean CustomerSqlMapDAO public class CustomerSqlMapDAO extends SqlMapClientTemplate implements CustomerDAO { public Integer insertCustomer(CustomerVO customerVo) throws DataAccessException { return (Integer)insert(insertCustomer, customerVo); } public Integer insertCustomerDependent(CustomerDependentVO customerDependentVo) throws DataAccessException { return (Integer)insert(insertCustomerDependent, customerDependentVo); } CustomerService public class CustomerService extends CommonService { private CustomerDAO customerDAO; public CustomerService(CustomerDAO customerDAO) { super(customerDAO); this.customerDAO = customerDAO; } public Integer insertCustomer(CustomerVO customerVo) throws DataAccessException { return customerDAO.insertCustomer(customerVo); } public Integer insertCustomerDependent(CustomerDependentVO customerDependentVo) throws DataAccessException { return customerDAO.insertCustomerDependent(customerDependentVo); } CustomerAction.java CustomerService customerService = SpringBeans.getCustomerService(); try { // retrieve cust_id from QOL_CUSTOMER using qol_customer_seq.NEXTVAL custId = customerService.getCustomerId(); customerService.startTransaction(); // start batch process customerService.startBatch(); // insert record into QOL_CUSTOMER table (add to batch process) customerService.insertCustomer(customerVo); // retrive dependent first/last name for insertion check to QOL_DEPENDENT tabel String custDepFirstName = customerPersonalForm.getDepFirstName(); String custDepLastName = customerPersonalForm.getDepLastName(); // insert into DEPENDENT table only if dependent first/last name enterd on the form if (StringUtils.isNotBlank(custDepFirstName) || StringUtils.isNotBlank(custDepLastName)) { customerDependentVo.setCustId(custId);
Ibatis + Spring : log4j does not work
Hello, I have a problem using log4j with ibatis. Log4j works well but i can't see the log for SQL requests and results. I think i need to add this line LogFactory.selectLog4JLogging(); but i don't know where i should add it. I am currently using spring framework and i don't know where i can put this line so it will be loaded at the initialisation of my web application. -- View this message in context: http://www.nabble.com/Ibatis-%2B-Spring-%3A-log4j-does-not-work-tp21142261p21142261.html Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
Re: Ibatis + Spring : log4j does not work
Add this line in log4j.properties. log4j.logger.java.sql=DEBUG 2008/12/23 oci zarbi...@hotmail.com Hello, I have a problem using log4j with ibatis. Log4j works well but i can't see the log for SQL requests and results. I think i need to add this line LogFactory.selectLog4JLogging(); but i don't know where i should add it. I am currently using spring framework and i don't know where i can put this line so it will be loaded at the initialisation of my web application. -- View this message in context: http://www.nabble.com/Ibatis-%2B-Spring-%3A-log4j-does-not-work-tp21142261p21142261.html Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
Re: Ibatis + Spring : log4j does not work
It has no effects :( Hereafter, my log4j.properties : # Global logging configuration log4j.rootLogger=INFO, stdout # Console output... log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%d{-MM-dd HH:mm:ss} %-5p [%c{1}] %m%n # SqlMap logging configuration... log4j.logger.com.ibatis=DEBUG log4j.logger.com.ibatis.common.jdbc.SimpleDataSource=DEBUG log4j.logger.java.sql.Connection=DEBUG log4j.logger.java.sql.Statement=DEBUG log4j.logger.java.sql.PreparedStatement=DEBUG log4j.logger.java.sql.ResultSet=DEBUG log4j.logger.java.sql=DEBUG -- View this message in context: http://www.nabble.com/Ibatis-%2B-Spring-%3A-log4j-does-not-work-tp21142261p21144300.html Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
Ibatis+Spring related: Update over a dblink doesn't update the table
Hi, I am using Ibatis with Spring and updating a table (on the remote DB) over a dblink, but the changes are not being seen when I login to the remote DB. When I update any table in the local DB, I can observe the changes in the database, but not in case of update over a dblink. Looks like, I need to issue an explicit commit statement, if the update is over a dblink; am I correct? If so, please let me know how to do that. Any other solution that can solve my issue, is also very much appreciated. Thanks Rakesh -- View this message in context: http://www.nabble.com/Ibatis%2BSpring-related%3A-Update-over-a-dblink-doesn%27t-update-the-table-tp19205467p19205467.html Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
Re: Ibatis+Spring related: Update over a dblink doesn't update the table
Got it working the following way. DaoImpl: getSqlMapClientTemplate().queryForObject(datapull.commit); sql: --- statement id=commitcommit/statement -Rakesh mailtorakeshp wrote: Hi, I am using Ibatis with Spring and updating a table (on the remote DB) over a dblink, but the changes are not being seen when I login to the remote DB. When I update any table in the local DB, I can observe the changes in the database, but not in case of update over a dblink. Looks like, I need to issue an explicit commit statement, if the update is over a dblink; am I correct? If so, please let me know how to do that. Any other solution that can solve my issue, is also very much appreciated. Thanks Rakesh -- View this message in context: http://www.nabble.com/Ibatis%2BSpring-related%3A-Update-over-a-dblink-doesn%27t-update-the-table-tp19205467p19206718.html Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
RE: Ibatis+Spring related: Update over a dblink doesn't update the table
Are you using Spring's transaction management? Look at Spring declarative transactions if you didn't do so. http://static.springframework.org/spring/docs/2.5.x/reference/transaction.html#transaction-declarative Christian -Original Message- From: mailtorakeshp [mailto:[EMAIL PROTECTED] Sent: Thursday, August 28, 2008 2:45 PM To: user-java@ibatis.apache.org Subject: Re: Ibatis+Spring related: Update over a dblink doesn't update the table Got it working the following way. DaoImpl: getSqlMapClientTemplate().queryForObject(datapull.commit); sql: --- statement id=commitcommit/statement -Rakesh mailtorakeshp wrote: Hi, I am using Ibatis with Spring and updating a table (on the remote DB) over a dblink, but the changes are not being seen when I login to the remote DB. When I update any table in the local DB, I can observe the changes in the database, but not in case of update over a dblink. Looks like, I need to issue an explicit commit statement, if the update is over a dblink; am I correct? If so, please let me know how to do that. Any other solution that can solve my issue, is also very much appreciated. Thanks Rakesh -- View this message in context: http://www.nabble.com/Ibatis%2BSpring-related%3A-Update-over-a-dblink-doesn%27t-update-the-table-tp19205467p19206718.html Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
RE: iBATIS, Spring, and transactions...
Hi Christian, Thanks for your extensive answer, unfortunately I don't seem to be clever enough to understand it.. I've never worked with Listeners before and don't understand most of what is going on :-( Anyway, I added your sample code into a com.listeners package, and added a entry into web.xml to call it; listener listener-classcom.listeners.SpringInit/listener-class /listener I put a debug line into the context Initialization to check if it finds the Spring bean, it doesn't.. WebApplicationContextUtils.getWebApplicationContext(event.getServletContext( )); returns null My service class seems to get created by the spring framework, (it does stop at a breakpoint I put in). So my entry in Spring.xml is probably correct (how do you debug all these configuration file?!) bean id=theService class=com.service.TheService constructor-arg index=0 ref=theDao/ /bean _ From: Poitras Christian [mailto:[EMAIL PROTECTED] Sent: 10 April 2007 07:10 PM To: user-java@ibatis.apache.org Subject: RE: iBATIS, Spring, and transactions... First, you can still use BeanAction with Spring DAO. The most simple solution to set your static variable is to get it from Spring. First get the SpringContext and do the following. private static final TheService instance = springContext.getBean(theService); The way you can get SpringContext is relaitve on how you initialize it. This is a code sample of how you can access it if you use org.springframework.web.context.ContextLoaderListener. /** * Listen for Spring initialization. * * @author poitrac */ public class SpringInit implements ServletContextListener { /** * Spring's WebApplicationContext. */ private static WebApplicationContext springContext; public SpringInit() { super(); } /* (non-Javadoc) * @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.Servle tContextEvent) */ public void contextInitialized(ServletContextEvent event) { springContext = WebApplicationContextUtils.getWebApplicationContext(event.getServletContext( )); } /* (non-Javadoc) * @see javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.ServletC ontextEvent) */ public void contextDestroyed(ServletContextEvent event) { } /** * Returns Spring's WebApplicationContext. * @return Spring's WebApplicationContext. */ public static ApplicationContext getApplicationContext() { return springContext; } } Christian _ From: Meindert [mailto:[EMAIL PROTECTED] Sent: Tuesday, 10 April 2007 12:30 To: user-java@ibatis.apache.org Subject: RE: iBATIS, Spring, and transactions... I'm busy converting and went to the site http://www.learntechnology.net/content/ibatis/spring_ibatis.jsp What is quite a clear explanation :-) I'm converting a project that is based on the jpetstore, what is using org.apache.struts.beanaction.BeanAction in my struts-config.xml The above mentioned site has got a different approach. My question is; a) can I still use org.apache.struts.beanaction.BeanAction? I only want to change the DAO to Spring DAO because IBATIS DAO is depreciated and if so b) The BeanAction class is using private static final TheService theService = TheService.getInstance(); to connect with the service object, what created itself static; private static final TheService instance = new TheService(); How do I get a instance from the spring created service object? My service object get's created by spring using the following config in spring.xml; bean id= theService class=com.service.TheService constructor-arg index=0 ref=theDao/ /bean And code; public TheService (TheDao theDao){ this.theDao = theDao; } Kind Regards Meindert -Original Message- From: Poitras Christian [mailto:[EMAIL PROTECTED] Sent: 10 April 2007 04:25 PM To: user-java@ibatis.apache.org; [EMAIL PROTECTED] Subject: RE: iBATIS, Spring, and transactions... That would be a great idea! It's always welcome to see some code to show each steps. My app is already to big to use it direclty as an example... Christian I'll check if I can provide you with my smaller app (contains only 2 actions, but it does not have any transaction). I'll just add the insert/updates I used at first to fill database. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Larry Meadors Sent: Tuesday, 10 April 2007 10:16 To: user-java@ibatis.apache.org Subject: Re: iBATIS, Spring, and transactions... That would be AWESOME, if you want, I can help with proofing, etc. Maybe someone else would be willing to provide a *simple* iBATIS DAO sample application that we could convert and then document the process. Larry On 4/10/07, Poitras Christian [EMAIL PROTECTED] wrote: I have to say that it would be really
RE: iBATIS, Spring, and transactions...
Here is my config file for Spring. It uses transaction with annotation. @Transactional can be put before method or class declaration to make the method/class transactional. (see Spring documentation for more details). !-- Transaction handling -- tx:annotation-driven transaction-manager=txManager/ bean id=txManager class=org.springframework.jdbc.datasource.DataSourceTransactionManager property name=dataSource ref=dataSource/ /bean !-- Initialize iBATIS -- bean id=dataSource class=org.apache.commons.dbcp.BasicDataSource destroy-method=close property name=driverClassName value=${driver}/ property name=url value=${url}/ property name=username value=${username}/ property name=password value=${password}/ /bean bean id=sqlMapClient class=org.springframework.orm.ibatis.SqlMapClientFactoryBean property name=configLocation value=classpath:ca/qc/ircm/proteus/persistence/dao/sqlmap/sql/sql-map-c onfig.xml/ property name=dataSource ref=dataSource/ /bean !-- Initialize DAOs -- bean id=aliasGroupDao class=ca.qc.ircm.proteus.persistence.dao.sqlmap.AliasGroupSqlMapDao property name=sqlMapClient ref=sqlMapClient/ /bean I have to say that it would be really nice to have an how to for passing from iBATIS DAO to Spring DAO... I made a french document about that question. I could transalte it to english in the next weeks and put it on the wiki... Christian -Original Message- From: Meindert [mailto:[EMAIL PROTECTED] Sent: Tuesday, 10 April 2007 04:52 To: user-java@ibatis.apache.org Subject: RE: iBATIS, Spring, and transactions... Hi All, Does anybody have an answer on the question posted below? I want to switch of from IBATIS DAO to spring because IBATIS DAO is depreciated. I can convert most of the code quite simply, but what must I do with my transactions? Kind Regards Meindert -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: 03 April 2007 07:15 PM To: user-java@ibatis.apache.org Subject: iBATIS, Spring, and transactions... Hi, Another newbie question. If I am implementing DAOs using Spring's iBATIS support, am I required to also use Spring's transaction controls, or can I still use the startTransaction(), commitTransaction() and endTransaction() calls supplied by iBATIS? If I can, I'm afraid that it's not clear to me how to specify that I want to do this in the relevant XML configuration files. Thanks, Brendan
Re: iBATIS, Spring, and transactions...
That would be AWESOME, if you want, I can help with proofing, etc. Maybe someone else would be willing to provide a *simple* iBATIS DAO sample application that we could convert and then document the process. Larry On 4/10/07, Poitras Christian [EMAIL PROTECTED] wrote: I have to say that it would be really nice to have an how to for passing from iBATIS DAO to Spring DAO... I made a french document about that question. I could transalte it to english in the next weeks and put it on the wiki...
RE: iBATIS, Spring, and transactions...
That would be a great idea! It's always welcome to see some code to show each steps. My app is already to big to use it direclty as an example... Christian I'll check if I can provide you with my smaller app (contains only 2 actions, but it does not have any transaction). I'll just add the insert/updates I used at first to fill database. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Larry Meadors Sent: Tuesday, 10 April 2007 10:16 To: user-java@ibatis.apache.org Subject: Re: iBATIS, Spring, and transactions... That would be AWESOME, if you want, I can help with proofing, etc. Maybe someone else would be willing to provide a *simple* iBATIS DAO sample application that we could convert and then document the process. Larry On 4/10/07, Poitras Christian [EMAIL PROTECTED] wrote: I have to say that it would be really nice to have an how to for passing from iBATIS DAO to Spring DAO... I made a french document about that question. I could transalte it to english in the next weeks and put it on the wiki...
RE: iBATIS, Spring, and transactions...
I'm busy converting and went to the site http://www.learntechnology.net/content/ibatis/spring_ibatis.jsp What is quite a clear explanation :-) I'm converting a project that is based on the jpetstore, what is using org.apache.struts.beanaction.BeanAction in my struts-config.xml The above mentioned site has got a different approach. My question is; a) can I still use org.apache.struts.beanaction.BeanAction? I only want to change the DAO to Spring DAO because IBATIS DAO is depreciated and if so b) The BeanAction class is using private static final TheService theService = TheService.getInstance(); to connect with the service object, what created itself static; private static final TheService instance = new TheService(); How do I get a instance from the spring created service object? My service object get's created by spring using the following config in spring.xml; bean id= theService class=com.service.TheService constructor-arg index=0 ref=theDao/ /bean And code; public TheService (TheDao theDao){ this.theDao = theDao; } Kind Regards Meindert -Original Message- From: Poitras Christian [mailto:[EMAIL PROTECTED] Sent: 10 April 2007 04:25 PM To: user-java@ibatis.apache.org; [EMAIL PROTECTED] Subject: RE: iBATIS, Spring, and transactions... That would be a great idea! It's always welcome to see some code to show each steps. My app is already to big to use it direclty as an example... Christian I'll check if I can provide you with my smaller app (contains only 2 actions, but it does not have any transaction). I'll just add the insert/updates I used at first to fill database. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Larry Meadors Sent: Tuesday, 10 April 2007 10:16 To: user-java@ibatis.apache.org Subject: Re: iBATIS, Spring, and transactions... That would be AWESOME, if you want, I can help with proofing, etc. Maybe someone else would be willing to provide a *simple* iBATIS DAO sample application that we could convert and then document the process. Larry On 4/10/07, Poitras Christian [EMAIL PROTECTED] wrote: I have to say that it would be really nice to have an how to for passing from iBATIS DAO to Spring DAO... I made a french document about that question. I could transalte it to english in the next weeks and put it on the wiki...
RE: iBATIS, Spring, and transactions...
First, you can still use BeanAction with Spring DAO. The most simple solution to set your static variable is to get it from Spring. First get the SpringContext and do the following. private static final TheService instance = springContext.getBean(theService); The way you can get SpringContext is relaitve on how you initialize it. This is a code sample of how you can access it if you use org.springframework.web.context.ContextLoaderListener. /** * Listen for Spring initialization. * * @author poitrac */ public class SpringInit implements ServletContextListener { /** * Spring's WebApplicationContext. */ private static WebApplicationContext springContext; public SpringInit() { super(); } /* (non-Javadoc) * @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.Se rvletContextEvent) */ public void contextInitialized(ServletContextEvent event) { springContext = WebApplicationContextUtils.getWebApplicationContext(event.getServletCont ext()); } /* (non-Javadoc) * @see javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.Serv letContextEvent) */ public void contextDestroyed(ServletContextEvent event) { } /** * Returns Spring's WebApplicationContext. * @return Spring's WebApplicationContext. */ public static ApplicationContext getApplicationContext() { return springContext; } } Christian From: Meindert [mailto:[EMAIL PROTECTED] Sent: Tuesday, 10 April 2007 12:30 To: user-java@ibatis.apache.org Subject: RE: iBATIS, Spring, and transactions... I'm busy converting and went to the site http://www.learntechnology.net/content/ibatis/spring_ibatis.jsp What is quite a clear explanation :-) I'm converting a project that is based on the jpetstore, what is using org.apache.struts.beanaction.BeanAction in my struts-config.xml The above mentioned site has got a different approach. My question is; a) can I still use org.apache.struts.beanaction.BeanAction? I only want to change the DAO to Spring DAO because IBATIS DAO is depreciated and if so b) The BeanAction class is using private static final TheService theService = TheService.getInstance(); to connect with the service object, what created itself static; private static final TheService instance = new TheService(); How do I get a instance from the spring created service object? My service object get's created by spring using the following config in spring.xml; bean id= theService class=com.service.TheService constructor-arg index=0 ref=theDao/ /bean And code; public TheService (TheDao theDao){ this.theDao = theDao; } Kind Regards Meindert -Original Message- From: Poitras Christian [mailto:[EMAIL PROTECTED] Sent: 10 April 2007 04:25 PM To: user-java@ibatis.apache.org; [EMAIL PROTECTED] Subject: RE: iBATIS, Spring, and transactions... That would be a great idea! It's always welcome to see some code to show each steps. My app is already to big to use it direclty as an example... Christian I'll check if I can provide you with my smaller app (contains only 2 actions, but it does not have any transaction). I'll just add the insert/updates I used at first to fill database. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Larry Meadors Sent: Tuesday, 10 April 2007 10:16 To: user-java@ibatis.apache.org Subject: Re: iBATIS, Spring, and transactions... That would be AWESOME, if you want, I can help with proofing, etc. Maybe someone else would be willing to provide a *simple* iBATIS DAO sample application that we could convert and then document the process. Larry On 4/10/07, Poitras Christian [EMAIL PROTECTED] wrote: I have to say that it would be really nice to have an how to for passing from iBATIS DAO to Spring DAO... I made a french document about that question. I could transalte it to english in the next weeks and put it on the wiki...
Re: iBatis, Spring and postgres stored procedure
Thanks Volker, I receive the same error even when using {? = call insert_country(?, ?, ?, ?)} Danke im Voraus! On 12/3/05, Volker Reichel [EMAIL PROTECTED] wrote: lunohodo, your stored procedure returns a value to the caller (the insert_id) but your SQLMap does not provide an OUT parameter for the value to be returned. I think you should use the following {? = call insert_country(?, ?, ?, ?)} in your sqlmap. -Ursprüngliche Nachricht- Von: Lunohodov [mailto:[EMAIL PROTECTED] Gesendet: Freitag, 2. Dezember 2005 16:18 An: user-java@ibatis.apache.org Betreff: iBatis, Spring and postgres stored procedure I stuck into a problem and after a few resultless hours I would like to aks for your help. I searched for a similar problem(the forum as also fired some googles) but could not find anything so I am starting a new thread... I have a PostgreSQL database with several stored procedures for fetching, updating, inserting and deleting data. A stored procedure takes four parameters and inserts data into two tables. Code is as follows: Code: CREATE OR REPLACE FUNCTION public.insert_country (varchar, varchar, varchar, varchar) RETURNS bigint AS $body$ declare insert_id bigint; countryIso ALIAS FOR $1; countryName ALIAS FOR $2; countryDesc ALIAS FOR $3; langIso ALIAS FOR $4; begin INSERT INTO tb_Countries (CountryCode_ISO) VALUES (countryIso); insert_id := currval('public.tb_Countries_CountryID_seq'); INSERT INTO tb_CountryNamesDescriptions (CountryID, CountryName, Description, LanguageCode_ISO) VALUES (insert_id, countryName, countryDesc, langIso); return insert_id; end; $body$ LANGUAGE 'plpgsql' VOLATILE CALLED ON NULL INPUT SECURITY INVOKER; The procedure alone works OK. So the problem is not in the procedure itself. The coresponding section from the SQL-MAP xml definition file is as follows: Code: parameterMap id=insert-country-params class=java.util.Map parameter property=isoCode jdbcType=VARCHAR javaType=java.lang.String mode=IN/ parameter property=name jdbcType=VARCHAR javaType=java.lang.String mode=IN/ parameter property=description jdbcType=VARCHAR javaType=java.lang.String mode=IN/ parameter property=langIso jdbcType=VARCHAR javaType=java.lang.String mode=IN/ /parameterMap procedure id=insert-country-sp parameterMap=insert-country-params resultClass=java.lang.Long ![CDATA[ {call insert_country(?, ?, ?, ?)} ]] /procedure The Java code is as follows: Code: public void createCountry(ICountry c, Locale l) { // code snip Map params = new HashMap(); params.put(isoCode, c.getIsoCode()); params.put(name, c.getName()); params.put(description, c.getDescription()); params.put(langIso, l.getLanguage()); getSqlMapClientTemplate().insert(insert-country-sp, params); } When I run a test application I receive the following error: Code: org.springframework.dao.DataIntegrityViolationException: SqlMapClient operation; SQL []; --- The error occurred in locality/postgres/maps/Country.xml. --- The error occurred while applying a parameter map. --- Check the Country.insert-country-params. --- Check the parameter mapping for the 'isoCode' property. --- Cause: org.postgresql.util.PSQLException: The column index is out of range: 0, number of columns: 4.; nested exception is com.ibatis.common.jdbc.exception.NestedSQLException: --- The error occurred in locality/postgres/maps/Country.xml. --- The error occurred while applying a parameter map. --- Check the Country.insert-country-params. --- Check the parameter mapping for the 'isoCode' property. Can someone help me? Thank you in advance! Regards lunohodo
AW: iBatis, Spring and postgres stored procedure
lunohodo, your stored procedure returns a value to the caller (the insert_id) but your SQLMap does not provide an OUT parameter for the value to be returned. I think you should use the following {? = call insert_country(?, ?, ?, ?)} in your sqlmap. -Ursprüngliche Nachricht- Von: Lunohodov [mailto:[EMAIL PROTECTED] Gesendet: Freitag, 2. Dezember 2005 16:18 An: user-java@ibatis.apache.org Betreff: iBatis, Spring and postgres stored procedure I stuck into a problem and after a few resultless hours I would like to aks for your help. I searched for a similar problem(the forum as also fired some googles) but could not find anything so I am starting a new thread... I have a PostgreSQL database with several stored procedures for fetching, updating, inserting and deleting data. A stored procedure takes four parameters and inserts data into two tables. Code is as follows: Code: CREATE OR REPLACE FUNCTION public.insert_country (varchar, varchar, varchar, varchar) RETURNS bigint AS $body$ declare insert_id bigint; countryIso ALIAS FOR $1; countryName ALIAS FOR $2; countryDesc ALIAS FOR $3; langIso ALIAS FOR $4; begin INSERT INTO tb_Countries (CountryCode_ISO) VALUES (countryIso); insert_id := currval('public.tb_Countries_CountryID_seq'); INSERT INTO tb_CountryNamesDescriptions (CountryID, CountryName, Description, LanguageCode_ISO) VALUES (insert_id, countryName, countryDesc, langIso); return insert_id; end; $body$ LANGUAGE 'plpgsql' VOLATILE CALLED ON NULL INPUT SECURITY INVOKER; The procedure alone works OK. So the problem is not in the procedure itself. The coresponding section from the SQL-MAP xml definition file is as follows: Code: parameterMap id=insert-country-params class=java.util.Map parameter property=isoCode jdbcType=VARCHAR javaType=java.lang.String mode=IN/ parameter property=name jdbcType=VARCHAR javaType=java.lang.String mode=IN/ parameter property=description jdbcType=VARCHAR javaType=java.lang.String mode=IN/ parameter property=langIso jdbcType=VARCHAR javaType=java.lang.String mode=IN/ /parameterMap procedure id=insert-country-sp parameterMap=insert-country-params resultClass=java.lang.Long ![CDATA[ {call insert_country(?, ?, ?, ?)} ]] /procedure The Java code is as follows: Code: public void createCountry(ICountry c, Locale l) { // code snip Map params = new HashMap(); params.put(isoCode, c.getIsoCode()); params.put(name, c.getName()); params.put(description, c.getDescription()); params.put(langIso, l.getLanguage()); getSqlMapClientTemplate().insert(insert-country-sp, params); } When I run a test application I receive the following error: Code: org.springframework.dao.DataIntegrityViolationException: SqlMapClient operation; SQL []; --- The error occurred in locality/postgres/maps/Country.xml. --- The error occurred while applying a parameter map. --- Check the Country.insert-country-params. --- Check the parameter mapping for the 'isoCode' property. --- Cause: org.postgresql.util.PSQLException: The column index is out of range: 0, number of columns: 4.; nested exception is com.ibatis.common.jdbc.exception.NestedSQLException: --- The error occurred in locality/postgres/maps/Country.xml. --- The error occurred while applying a parameter map. --- Check the Country.insert-country-params. --- Check the parameter mapping for the 'isoCode' property. Can someone help me? Thank you in advance! Regards lunohodo
iBatis, Spring and postgres stored procedure
I stuck into a problem and after a few resultless hours I would like to aks for your help. I searched for a similar problem(the forum as also fired some googles) but could not find anything so I am starting a new thread... I have a PostgreSQL database with several stored procedures for fetching, updating, inserting and deleting data. A stored procedure takes four parameters and inserts data into two tables. Code is as follows: Code: CREATE OR REPLACE FUNCTION public.insert_country (varchar, varchar, varchar, varchar) RETURNS bigint AS $body$ declare insert_id bigint; countryIso ALIAS FOR $1; countryName ALIAS FOR $2; countryDesc ALIAS FOR $3; langIso ALIAS FOR $4; begin INSERT INTO tb_Countries (CountryCode_ISO) VALUES (countryIso); insert_id := currval('public.tb_Countries_CountryID_seq'); INSERT INTO tb_CountryNamesDescriptions (CountryID, CountryName, Description, LanguageCode_ISO) VALUES (insert_id, countryName, countryDesc, langIso); return insert_id; end; $body$ LANGUAGE 'plpgsql' VOLATILE CALLED ON NULL INPUT SECURITY INVOKER; The procedure alone works OK. So the problem is not in the procedure itself. The coresponding section from the SQL-MAP xml definition file is as follows: Code: parameterMap id=insert-country-params class=java.util.Map parameter property=isoCode jdbcType=VARCHAR javaType=java.lang.String mode=IN/ parameter property=name jdbcType=VARCHAR javaType=java.lang.String mode=IN/ parameter property=description jdbcType=VARCHAR javaType=java.lang.String mode=IN/ parameter property=langIso jdbcType=VARCHAR javaType=java.lang.String mode=IN/ /parameterMap procedure id=insert-country-sp parameterMap=insert-country-params resultClass=java.lang.Long ![CDATA[ {call insert_country(?, ?, ?, ?)} ]] /procedure The Java code is as follows: Code: public void createCountry(ICountry c, Locale l) { // code snip Map params = new HashMap(); params.put(isoCode, c.getIsoCode()); params.put(name, c.getName()); params.put(description, c.getDescription()); params.put(langIso, l.getLanguage()); getSqlMapClientTemplate().insert(insert-country-sp, params); } When I run a test application I receive the following error: Code: org.springframework.dao.DataIntegrityViolationException: SqlMapClient operation; SQL []; --- The error occurred in locality/postgres/maps/Country.xml. --- The error occurred while applying a parameter map. --- Check the Country.insert-country-params. --- Check the parameter mapping for the 'isoCode' property. --- Cause: org.postgresql.util.PSQLException: The column index is out of range: 0, number of columns: 4.; nested exception is com.ibatis.common.jdbc.exception.NestedSQLException: --- The error occurred in locality/postgres/maps/Country.xml. --- The error occurred while applying a parameter map. --- Check the Country.insert-country-params. --- Check the parameter mapping for the 'isoCode' property. Can someone help me? Thank you in advance! Regards lunohodo