My client class uses the updateCustomer method in CustomerService class:
Customer updatedCustomer = new Customer("2314DD0", "POJO World", "Offers POJO service.");
customerService.updateCustomer(updatedCustomer);
I’ve tried all sorts of things to work around “updateOrSave”, different arguments for update, and so on. The problem that I am encountering according to the stack trace is a (HibernateOptimisticLockingFailureException) and a (org.hibernate.StaleStateException). But let me explain first: All my other data accesses (i.e. save, delete, and query) work perfectly well. I am suspicious about my customer domain class, as well as the Customer.hbm.xml that I’ve set up.
So, my Customer Service class:
public void updateCustomer(Customer updatedCustomer)
{
this.dao.update(updatedCustomer);
}
Customer Service Dao:
public void update(Customer customerToUpdate)
{
template.update("Customer", customerToUpdate);
}
domain.Customer class:
public class Customer
{
private int id;
private String customerId, companyName, email, telephone, notes;
private Customer() {}
public Customer(String customerId, String companyName, String email,
String telephone, String notes)
{
this.customerId = customerId;
this.companyName = companyName;
this.email = email;
this.telephone = telephone;
this.notes = notes;
}
//Getters and Setters for ALL instance variables listed after this point.
}
Finally, my Customer.hbm.xml:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.crm.domain.Customer">
<id name="id" column="ID">
<generator class="native"/>
</id>
<property name="customerId"/>
<property name="companyName"/>
<property name="email"/>
<property name="telephone"/>
<property name="notes"/>
</class>
If it’s a new object, which is implied by
new Customer("2314DD0", "POJO World", "Offers POJO service.");then shouldn’t you be callingsave()orpersist()instead ofupdate()?