springdawn2003
Sep 16th, 2004, 02:08 AM
The problem is hibernate can make uuid after call save() method,but nothing save into db.
code:
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName"><value>oracle.jdbc.OracleDriver</value></property>
<property name="url"><value>jdbc:oracle:thin:@localhost:1521:orcl</value></property>
<property name="username"><value>Acc4</value></property>
<property name="password"><value>oracle</value></property>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate.LocalSessionFact oryBean">
<property name="mappingResources">
<list>
<value>domain/pojos/base/ContactInformation.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="dialect.Dialect">net.sf.hibernate.dialect.Oracle9Dialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="jdbc.fetch_size">50</prop>
<prop key="jdbc.batch_size">25</prop>
<prop key="jdbc.use_scrollable_resultset">false</prop>
<prop key="connection.useUnicode">true</prop>
<prop key="connection.characterEncoding">UTF-8</prop>
</props>
</property>
<property name="dataSource">
<ref local="dataSource" />
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate.HibernateTransac tionManager">
<property name="sessionFactory"><ref local="sessionFactory"/></property>
</bean>
<!-- ========================= DAO Definitions: Hibernate implementation ========================= -->
<bean id="contactInformationDAO" class="server.persistence.hibernate.ContactInformationDAO HibernateImpl">
<property name="sessionFactory"><ref local="sessionFactory"/></property>
</bean>
<!-- ========================= Business Object Definitions ======================== -->
<bean id="baseTxProxy" lazy-init="true"
class="org.springframework.transaction.interceptor.Transa ctionProxyFactoryBean">
<property name="transactionManager"><ref bean="transactionManager"/></property>
<property name="transactionAttributes">
<props>
<prop key="create*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="update*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="save*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="delete*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
</bean>
<bean id="employeeService" parent="baseTxProxy">
<property name="target">
<bean class="server.business.facade.impl.EmployeeServiceImpl">
<property name="contactInformationDAO"><ref bean="contactInformationDAO"/></property>
</bean>
</property>
</bean>
code:
public class EmployeeServiceImpl implements EmployeeService {
/**
*
* @param o
* @return
*/
public String createContactInformation(ContactInformationView o) throws Exception {
String result = null;
try {
ContactInformation pojo = (ContactInformation)BeanUtilsFactory.getBeanUtils( )
.copyProperties(o);
result = contactInformationDAO.createContactInformation(poj o);
}
catch (BeanConvertedException bce) {
System.out.println(bce.getLocalizedMessage());
}
catch (Exception e) {
System.out.println("exception:" + e.getLocalizedMessage());
throw e;
}
return result;
}
public class ContactInformationDAOHibernateImpl extends HibernateDaoSupport
implements ContactInformationDAO {
/**
*
* @param o
* @return
*/
public String createContactInformation(ContactInformation o) throws DAOException {
String result = null;
try {
result = (String)this.getHibernateTemplate().save(o);
}
catch (DataAccessException dae) {
throw new DAOException(dae.getMessage());
}
System.out.println("uuid:" + result);
return result;
}
code:
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName"><value>oracle.jdbc.OracleDriver</value></property>
<property name="url"><value>jdbc:oracle:thin:@localhost:1521:orcl</value></property>
<property name="username"><value>Acc4</value></property>
<property name="password"><value>oracle</value></property>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate.LocalSessionFact oryBean">
<property name="mappingResources">
<list>
<value>domain/pojos/base/ContactInformation.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="dialect.Dialect">net.sf.hibernate.dialect.Oracle9Dialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="jdbc.fetch_size">50</prop>
<prop key="jdbc.batch_size">25</prop>
<prop key="jdbc.use_scrollable_resultset">false</prop>
<prop key="connection.useUnicode">true</prop>
<prop key="connection.characterEncoding">UTF-8</prop>
</props>
</property>
<property name="dataSource">
<ref local="dataSource" />
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate.HibernateTransac tionManager">
<property name="sessionFactory"><ref local="sessionFactory"/></property>
</bean>
<!-- ========================= DAO Definitions: Hibernate implementation ========================= -->
<bean id="contactInformationDAO" class="server.persistence.hibernate.ContactInformationDAO HibernateImpl">
<property name="sessionFactory"><ref local="sessionFactory"/></property>
</bean>
<!-- ========================= Business Object Definitions ======================== -->
<bean id="baseTxProxy" lazy-init="true"
class="org.springframework.transaction.interceptor.Transa ctionProxyFactoryBean">
<property name="transactionManager"><ref bean="transactionManager"/></property>
<property name="transactionAttributes">
<props>
<prop key="create*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="update*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="save*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="delete*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
</bean>
<bean id="employeeService" parent="baseTxProxy">
<property name="target">
<bean class="server.business.facade.impl.EmployeeServiceImpl">
<property name="contactInformationDAO"><ref bean="contactInformationDAO"/></property>
</bean>
</property>
</bean>
code:
public class EmployeeServiceImpl implements EmployeeService {
/**
*
* @param o
* @return
*/
public String createContactInformation(ContactInformationView o) throws Exception {
String result = null;
try {
ContactInformation pojo = (ContactInformation)BeanUtilsFactory.getBeanUtils( )
.copyProperties(o);
result = contactInformationDAO.createContactInformation(poj o);
}
catch (BeanConvertedException bce) {
System.out.println(bce.getLocalizedMessage());
}
catch (Exception e) {
System.out.println("exception:" + e.getLocalizedMessage());
throw e;
}
return result;
}
public class ContactInformationDAOHibernateImpl extends HibernateDaoSupport
implements ContactInformationDAO {
/**
*
* @param o
* @return
*/
public String createContactInformation(ContactInformation o) throws DAOException {
String result = null;
try {
result = (String)this.getHibernateTemplate().save(o);
}
catch (DataAccessException dae) {
throw new DAOException(dae.getMessage());
}
System.out.println("uuid:" + result);
return result;
}