PDA

View Full Version : Binding problem


radone
Feb 1st, 2005, 05:41 PM
What does it mean if my app returns error message:

(I am trying to store class TransportOffer - Class diagram:http://radone.php5.cz/classDiagram_new.png)

Data Access Failure

identifier of an instance of org.appfuse.model.Town altered from 10100 to 80800; nested exception is net.sf.hibernate.HibernateException: identifier of an instance of org.appfuse.model.Town altered from 10100 to 80800

Should it be problem in my springMVC mapping? All my DAO test seems to work correctly. It seems it is trying to store subclasses to and I have no idea why...
[/quote]
relation many-to-one:

<spring:bind path="transportOffer.townFrom.postalCode">
<select name="<c:out value="${status.expression}"/>" value="<c:out value="${status.value}" />">
<c:forEach items="${townList}" var="town">

<option value="<c:out value="${town.postalCode}"/>"
<c:choose>
<c:when test="${town.postalCode == status.value}"> selected="selected" </c:when>
</c:choose>
><c:out value="${town.country.code}"/>-<c:out value="${town.name_i18n}"/></option>
</c:forEach>
</select>
</spring:bind>


Has anyone had the same problem?

Any help will be very appreciated.[/url]

julien
Feb 1st, 2005, 05:46 PM
Quite funny that you post a poll when you have a problem.

I'd say the problem is that you modify the id of a persistent hibernate instance (I guess associated with a running session), which is forbidden.

Controller code + session handling strategy ?

radone
Feb 1st, 2005, 05:55 PM
I was interested what others think about SpringMVC :)
-----------
I need to update pointing of class TransportOffer to another town. When I do this - the result is this message :(

TransportFormController.java
package org.appfuse.webapp.action;

public class TransportRequestFormController extends BaseFormController {
private TransportRequestManager transportRequestManager = null;
private TownManager townManager = null;

public void setTransportRequestManager(TransportRequestManager transportRequestManager) {
this.transportRequestManager = transportRequestManager;
}

public void setTownManager(TownManager townManager) {
this.townManager = townManager;
}

protected Object formBackingObject(HttpServletRequest request)
throws Exception {
String id = request.getParameter("id");
TransportRequest transportRequest = null;

if (!StringUtils.isEmpty(id)) {
transportRequest = transportRequestManager.getTransportRequest(id);
} else {
Town t = new Town();
t.setPostalCode("10100");
Company c = new Company();
c.setId(new Long(1));

// default values
transportRequest = new TransportRequest();
transportRequest.setTownFrom(t);
transportRequest.setTownTo(t);
transportRequest.setCompany(getUser(request).getCo mpany());
}

return transportRequest;
}

public ModelAndView onSubmit(HttpServletRequest request,
HttpServletResponse response, Object command,
BindException errors)
throws Exception {
if (log.isDebugEnabled()) {
log.debug("entering 'onSubmit' method...");
}

TransportRequest transportRequest = (TransportRequest) command;
boolean isNew = (transportRequest.getId() == null);
Locale locale = request.getLocale();

if (request.getParameter("delete") != null) {
transportRequestManager.removeTransportRequest(tra nsportRequest.getId().toString());
saveMessage(request, getText("transportRequest.deleted", locale));
} else {
if (isNew){
transportRequestManager.saveTransportRequest(trans portRequest);
saveMessage(request, getText("transportRequest.added", locale));
} else {
transportRequestManager.updateTransportRequest(tra nsportRequest);
saveMessage(request, getText("transportRequest.updated", locale));
return new ModelAndView("redirect:editTransportRequest.html", "id", transportRequest.getId());
}
}

return new ModelAndView(getSuccessView());
}

protected Map referenceData(HttpServletRequest request) throws Exception {
Map model = new HashMap();
model.put(Constants.TOWN_LIST, townManager.getTowns(new Town()));
return model;
}
}


abstract public class TransportRequest extends BaseObject {
/**
* @return Returns the id.
* @hibernate.id column="id" generator-class="increment"
* unsaved-value="null"
*/
public Long getId() {
return id;
}
/**
* @return Returns the company.
*
* @hibernate.many-to-one
* column="FK_COMPANY_ID"
* class="org.appfuse.model.Company"
* unique="false"
* cascade="none"
*/
public Company getCompany() {
return company;
}
/**
* @return Returns the townFrom.
* @hibernate.many-to-one
* column="FK_TOWNFROM_ID"
* class="org.appfuse.model.Town"
* unique="false"
* cascade="none"
*/
public Town getTownFrom() {
return townFrom;
}
/**
* @return Returns the townTo.
* @hibernate.many-to-one
* column="FK_TOWNTO_ID"
* class="org.appfuse.model.Town"
* unique="false"
* cascade="none"
*/
public Town getTownTo() {
return townTo;
}
/**
* @hibernate.property column="note" length="2147483647"
* @return Returns the note.
*/
public String getNote() {
return note;
}