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
postsales-service.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE beans PUBLIC "-SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<!-- application context -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close" singleton="true">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/storeoperations" />
<property name="username" value="Guest" />
<property name="password" value="welcome" />
</bean>
<!-- Hibernate Session and xml mapping -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"
singleton="true">
<property name="dataSource" ref="dataSource" />
<property name="mappingResources">
<list>
<value>conf/user.hbm.xml</value>
<value>conf/product.hbm.xml</value>
<value>conf/invoice.hbm.xml</value>
<!-- <value>conf/salesdetails.hbm.xml</value> -->
<value>conf/delSchedule.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<value>
hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
</value>
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager"
singleton="true">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="abstractService"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
abstract="true">
<property name="transactionManager" ref="transactionManager" />
<property name="transactionAttributes">
<props>
<prop key="insert">PROPAGATION_REQUIRED</prop>
<prop key="update">PROPAGATION_REQUIRED</prop>
<prop key="delete">PROPAGATION_REQUIRED</prop>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<!-- Dao Implementation -->
<!-- User -->
<bean id="hibernateuserDao" class="com.postsales.domain.dao.hibernate.HibernateUserDao"
singleton="true">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- Invoice -->
<bean id="hibernateInvoiceDao" class="com.postsales.domain.dao.hibernate.HibernateInvoiceDao"
singleton="true">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- Product -->
<bean id="hibernateProductDao" class="com.postsales.domain.dao.hibernate.HibernateProductDao"
singleton="true">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- Service APIs -->
<!-- Login Service -->
<bean id="loginService" parent="abstractService" singleton="true">
<property name="target">
<bean class="com.postsales.service.impl.LoginServiceImpl"
singleton="true">
<property name="hibernateuserDao" ref="hibernateuserDao" />
</bean>
</property>
</bean>
<!-- Invoice Service -->
<bean id="productService" parent="abstractService" singleton="true">
<property name="target">
<bean class="com.postsales.service.impl.ProductServiceImpl">
<property name="hibernateProductDao" ref="hibernateProductDao" />
</bean>
</property>
</bean>
<bean id="invoiceService" parent="abstractService" singleton="true">
<property name="target">
<bean class="com.postsales.service.impl.InvoiceServiceImpl">
<property name="hibernateInvoiceDao" ref="hibernateInvoiceDao" />
</bean>
</property>
</bean>
</beans>
postsales-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="messageSource"
class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename">
<value>messages</value>
</property>
</bean>
<!-- you can have more than one handler defined -->
<bean id="urlMapping"
class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="urlMap">
<map>
<entry key="/login.do">
<ref bean="loginController" />
</entry>
<entry key="/header.do">
<ref bean="headerController" />
</entry>
<entry key="/createInvoice.do">
<ref bean="createInvoiceController" />
</entry>
<entry key="/logout.do">
<ref bean="logoutController" />
</entry>
<entry key="/suggestPage.do">
<ref bean="pageController" />
</entry>
</map>
</property>
</bean>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass">
<value>org.springframework.web.servlet.view.JstlView</value>
</property>
<property name="prefix">
<value>/WEB-INF/jsp/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
<!-- Validator Bean classes -->
<bean id="loginValidator" class="com.postsales.web.validators.LoginValidator">
</bean>
<!-- Controllers -->
<bean id="pageController" class="com.postsales.web.controller.PageController"
singleton="true" init-method="loadProducts">
<property name="productService" ref="productService"></property>
</bean>
<bean id="loginController" class="com.postsales.web.controller.LoginController"
singleton="true">
<property name="loginService" ref="loginService" />
<property name="validator" ref="loginValidator" />
<property name="commandName">
<value>loginCommand</value>
</property>
<property name="commandClass">
<value>com.postsales.web.commands.LoginCommand</value>
</property>
<property name="formView">
<value>login</value>
</property>
<property name="invoiceView">
<value>createInvoice.do</value>
</property>
</bean>
<bean id="createInvoiceController"
class="com.postsales.web.controller.secured.CreateInvoiceController"
singleton="true">
<property name="invoiceService" ref="invoiceService" />
<property name="commandName">
<value>createInvoiceCommand</value>
</property>
<property name="commandClass">
<value>com.postsales.web.commands.CreateInvoiceCommand</value>
</property>
<property name="invoiceView">
<value>createInvoice</value>
</property>
</bean>
<bean id="logoutController" class="com.postsales.web.controller.secured.LogoutController"
singleton="true">
<property name="loginService" ref="loginService" />
<property name="loginAction" value="login.do" />
</bean>
<bean id="headerController" class="com.postsales.web.controller.HeaderController"
singleton="true">
</bean>
</beans>
accountmanagement-service.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE beans PUBLIC "-SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" singleton="true">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/bankingmanagement"/>
<property name="username" value="root"/>
<property name="password" value="admin"/>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean" singleton="true">
<property name="dataSource" ref="dataSource"/>
<property name="mappingResources">
<list>
<value>conf/user.hbm.xml</value>
<value>conf/account.hbm.xml</value>
<value>conf/transaction.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<value>
hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
</value>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"
singleton="true">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<!-- Dao Implementation -->
<bean id="userDao" class="com.softnet.domain.dao.hibernate.HibernateUserDao" singleton="true">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<bean id="accountDao" class="com.softnet.domain.dao.hibernate.HibernateAccountDao" singleton="true">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<bean id="transactionDao" class="com.softnet.domain.dao.hibernate.HibernateTransactionDao" singleton="true">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<!-- Dao Factory -->
<bean id="daoFactory" class="com.softnet.domain.dao.DaoFactory" singleton="true">
<property name="userDao" ref="userDao"/>
<property name="accountDao" ref="accountDao"/>
<property name="transactionDao" ref="transactionDao"/>
</bean>
<!-- Services -->
<bean id="abstractService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
abstract="true">
<property name="transactionManager" ref="transactionManager"/>
<property name="transactionAttributes">
<props>
<prop key="insert">PROPAGATION_REQUIRED</prop>
<prop key="update">PROPAGATION_REQUIRED</prop>
<prop key="delete">PROPAGATION_REQUIRED</prop>
<prop key="withdraw">PROPAGATION_REQUIRED</prop>
<prop key="charge">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<bean id="userService" parent="abstractService" singleton="true">
<property name="target">
<bean class="com.softnet.service.impl.UserServiceImpl">
<property name="daoFactory" ref="daoFactory"/>
</bean>
</property>
</bean>
<bean id="accountService" parent="abstractService" singleton="true">
<property name="target">
<bean class="com.softnet.service.impl.AccountServiceImpl">
<property name="daoFactory" ref="daoFactory"/>
</bean>
</property>
</bean>
</beans>
accountmanagement-servlet.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE beans PUBLIC "-SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename">
<value>messages</value>
</property>
</bean>
<bean id="simpleUrlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"
singleton="true">
<property name="mappings">
<props>
<prop key="/login.do">loginController</prop>
<prop key="/accountDetail.do">accountDetailController</prop>
<prop key="/accountOperation.do">accountOperationController</prop>
<prop key="/logout.do">logoutController</prop>
</props>
</property>
</bean>
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"
singleton="true">
<property name="viewClass">
<value>org.springframework.web.servlet.view.JstlView</value>
</property>
<property name="prefix">
<value>/jsp/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
<!-- Validators -->
<bean id="loginValidator" class="com.softnet.web.validators.LoginValidator"/>
<bean id="accountOperationValidator" class="com.softnet.web.validators.AccountOperationValidator"/>
<!-- Controllers -->
<bean id="loginController" class="com.softnet.web.controller.LoginController" singleton="true">
<property name="userService" ref="userService"/>
<property name="validator" ref="loginValidator"/>
<property name="commandName">
<value>loginCommand</value>
</property>
<property name="commandClass">
<value>com.softnet.web.commands.LoginCommand</value>
</property>
<property name="formView">
<value>login</value>
</property>
<property name="successView">
<value>accountDetail.do</value>
</property>
</bean>
<bean id="accountDetailController" class="com.softnet.web.controller.secured.AccountDetailController" singleton="true">
<property name="accountService" ref="accountService"/>
<property name="loginAction" value="login.do"/>
<property name="viewName" value="accountDetail"/>
</bean>
<bean id="accountOperationController" class="com.softnet.web.controller.secured.AccountOperationController"
singleton="true">
<property name="accountService" ref="accountService"/>
<property name="validator" ref="accountOperationValidator"/>
<property name="commandName">
<value>accountOperationCommand</value>
</property>
<property name="commandClass">
<value>com.softnet.web.commands.AccountOperationCommand</value>
</property>
<property name="formView">
<value>accountOperations</value>
</property>
<property name="successView">
<value>accountOperations</value>
</property>
</bean>
<bean id="logoutController" class="com.softnet.web.controller.secured.LogoutController" singleton="true">
<property name="userService" ref="userService"/>
<property name="loginAction" value="login.do"/>
</bean>
</beans>
The latest I found that the following link was handy
http://www.java2s.com/Code/Java/Hibernate/OneToManyMappingList.htm
Accourdingly I have changed my invoice.hbm.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.postsales.domain.model">
<class name="Invoice" table="invoice">
<id name="invoiceNumber" column="InvoiceNumber" />
<property name="invoiceDate" column="InvoiceDate" not-null="true" />
<property name="invoiceTotal" column="InvoiceTotal" not-null="true" />
<property name="customerName" column="CustName" not-null="true" />
<list name="sales" cascade="all">
<key column="invoiceNumber"/>
<index column="salesNumber"/>
<one-to-many class="Sales"/>
</list>
</class>
<class name="Sales" table="salesdetails">
<id name="salesNumber" column="Sales_Number" />
<property name="prodCode" column="Prod_Code" not-null="true" />
<property name="salesDate" column="Sales_Date" not-null="true" />
<property name="storeID" column="From_Store" not-null="true" />
<property name="associatedInvoice" column="InvoiceNumber"
not-null="true" />
<property name="empID" column="Emp_ID" not-null="true" />
</class>
</hibernate-mapping>
Thank you,
Kavitha.