This week's book giveaway is in the OCAJP forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line! See this thread for details.
I am doing a small project using Spring framework. I am following a sample project that I found on the internet and using that archtecture. Following the sample project I created a transactionManager bean as shown in the below code snippet. But I am getting an exception. The xml and exception details are shown below. Also I dont know the meaning of the props PROPAGATION_REQUIRED. what it does and how the transaction is handled because of using all these beans. Please explain or give links to any article that will help me.
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'loginService' defined in ServletContext resource [/WEB-INF/postsales-services.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'transactionManager' of bean class [com.postsales.service.impl.LoginServiceImpl]: Bean property 'transactionManager' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
org.springframework.beans.NotWritablePropertyException: Invalid property 'transactionManager' of bean class [com.postsales.service.impl.LoginServiceImpl]: Bean property 'transactionManager' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
I did reply , but somehow my reply doesnt appear on the page, so pasting it again,
I had skipped the <parameter name="target"> part because of which I got this exception. But even though its working fine, I believe I am not able to best utilize the spring framwork. I do understand the controller and VOs but I dont understand transaction management part of the xml. I am doing something its working fine for me, but I dont know what I am doing and why? I would much appriciate if you could help me explain how can I use the transaction manager to best suit my project. I have a use case "Create Invoice" where I have to update two tables. The invoice table, generate invoice number, then go and update the sales table add all the items from the UI for that invoice and give reference of this invoice number to each entry in the sales table.
Now I believe I have done some transaction handling using the spring-hibernate transaction management. But not sure if thats the best way of doing it. Also while I was researching on this, I found a link which was handy. I have pasted the link as well in the end. Your comments and suggestions about my xml are welcome.
My project is postsales and the tutorial project is accountmanagement Following is the listing
Also where are you declaring which methods are transactional.
It looks like you don't want or like to use annotations. At your service layer is where you will declare your methods to be transactional. That way any call from the service layer to DAOs will all be within transactions, and in the use case you described you will have one transaction started at the service layer and propagated down to all the DAO calls.
To define which service layer methods or transactional can be done either by putting @Transactional on your Service class level (All public methods in that interface are then transactional) or right above each Service method you want Transactional. The other way to define it is through xml, and you can find that information on the Spring framework website documentation.
Hope that helps
Joined: Aug 14, 2009
Thank you for your response. Not that I dont like, but I guess I dont know annotations. In the last 4 years, I had never touched any java code, I had worked on java for 2 years before that. Lately I was working on SAP technology. This year I moved to New Zealand, and could not find jobs on Sap so freelancing on java project. I did work on java before sap, so using that knowledge and trying to figure out from the internet. Problem is I am taking more time than regular developer to finish this project, and I am afraid that the project might go off my hands if I delay further, so I guess I am kind of mixing spring framework for things I can easily follow, for things that are taking time in figuring out I just skip that part and use the traditional way of doing it. For example, in my createInvoice jsp, if I am binding the command object to the page elements, I am getting one exception saying "Neither Errors instance nor plain target object for bean name 'invoice' available as request attribute" but its fine incase of Login page, I wasted like half a day, I cant waste any more time so I just removed the spring bind and used request parameters directly. So thats about it. I will look for annotations and if its less time to learn it then I might as well use it if that makes my transaction processing life easy. thing is upgrading myself and finishing the project at the same time is being quiet hectic.
Thank you for your advice on my question. I shall post any quries that I have in future.