I have the following three tables which I have mapped 1:1,
DC -<1:1>- SUPPLIER -<1:1>- CUSTOMER
In the db however there CUSTOMER table can have multiple entries for each SUPPLIER. Not ideal, but this is an existing project and I can't change it.
So, In the SUPPLIER mapping file I have the following to map the 1:1 relationship:
Code:
<one-to-one
name="customer"
property-ref="supplierFk"
class="Customer"
formula="SELECT s.*
FROM CUSTOMER s
WHERE last_upd = (SELECT MAX(last_upd)
FROM CUSTOMER
WHERE supplier_fk = s.SUPPLIER_FK)"/>
The sql inside the formula removes the duplicate entries by choosing the last_updated entry, making the mapping what I want, 1:1.
(I have tried the SQL "manually" and it works)
This isnt working, I get the following stack trace:
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.orm.hibernate3.HibernateSystemException: More than one row with the given identifier was found: 773, for class: uk.co.formfill.nhhdcadmin.domain.Supplier; nested exception is org.hibernate.HibernateException: More than one row with the given identifier was found: 773, for class: uk.domain.Supplier
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:406)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:358)
javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
Any suggestions anyone?