These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: identifier of an instance of com.kink.model.Depart altered
PostPosted: Wed Mar 08, 2006 6:59 pm 
Newbie

Joined: Wed Mar 08, 2006 3:31 am
Posts: 5
Hi
using Appfuse with spring and hibernate and in a 1:n relationship between a dropdown box with departments and a workorder form....when I try to update the dropdown box with another department(different department) I get the following error..


Data Access Failure
identifier of an instance of com.kink.model.Department altered from 2 to 4; nested exception is org.hibernate.HibernateException: identifier of an instance of com.kink.model.Department altered from 2 to 4


has anyone any ideas...............cheers


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 08, 2006 7:14 pm 
Newbie

Joined: Wed Mar 08, 2006 3:31 am
Posts: 5
this is the error output..............thanks for any help

org.springframework.orm.hibernate3.HibernateSystemException: identifier of an instance of com.kink.model.Department altered from 1 to 4; nested exception is org.hibernate.HibernateException: identifier of an instance of com.kink.model.Department altered from 1 to 4
org.hibernate.HibernateException: identifier of an instance of com.kink.model.Department altered from 1 to 4
at org.hibernate.event.def.DefaultFlushEntityEventListener.checkId(DefaultFlushEntityEventListener.java:51)
at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:82)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:190)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:70)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:730)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:324)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:86)
at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:490)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:495)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:468)
at org.springframework.transaction.interceptor.TransactionAspectSupport.doCommitTransactionAfterReturning(TransactionAspectSupport.java:258)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:144)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:174)
at $Proxy10.saveWorkorder(Unknown Source)
at com.kink.webapp.action.WorkorderFormController.onSubmit(WorkorderFormController.java:83)
at org.springframework.web.servlet.mvc.SimpleFormController.processFormSubmission(SimpleFormController.java:258)
at com.kink.webapp.action.BaseFormController.processFormSubmission(BaseFormController.java:149)
at org.springframework.web.servlet.mvc.AbstractFormController.handleRequestInternal(AbstractFormController.java:245)
at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:139)
at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:44)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:684)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:625)
at org.springframework.web.servlet.FrameworkServlet.serviceWrapper(FrameworkServlet.java:386)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:355)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at com.opensymphony.module.sitemesh.filter.PageFilter.parsePage(PageFilter.java:118)
at com.opensymphony.module.sitemesh.filter.PageFilter.doFilter(PageFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at com.kink.webapp.filter.GZIPFilter.doFilter(GZIPFilter.java:51)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.displaytag.filter.ResponseOverrideFilter.doFilter(ResponseOverrideFilter.java:125)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:75)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at com.opensymphony.clickstream.ClickstreamFilter.doFilter(ClickstreamFilter.java:42)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at com.kink.webapp.filter.ActionFilter.doFilter(ActionFilter.java:119)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:174)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at net.sf.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:292)
at net.sf.acegisecurity.intercept.web.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:84)
at net.sf.acegisecurity.intercept.web.SecurityEnforcementFilter.doFilter(SecurityEnforcementFilter.java:182)
at net.sf.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:303)
at net.sf.acegisecurity.providers.anonymous.AnonymousProcessingFilter.doFilter(AnonymousProcessingFilter.java:153)
at net.sf.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:303)
at net.sf.acegisecurity.wrapper.ContextHolderAwareRequestFilter.doFilter(ContextHolderAwareRequestFilter.java:50)
at net.sf.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:303)
at net.sf.acegisecurity.context.HttpSessionContextIntegrationFilter.doFilter(HttpSessionContextIntegrationFilter.java:226)
at net.sf.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:303)
at net.sf.acegisecurity.util.FilterChainProxy.doFilter(FilterChainProxy.java:173)
at net.sf.acegisecurity.util.FilterToBeanProxy.doFilter(FilterToBeanProxy.java:125)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:595)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 08, 2006 10:01 pm 
Expert
Expert

Joined: Mon Jan 09, 2006 5:01 pm
Posts: 311
Location: Sacramento, CA
sounds like the user is posting a "new" http request ie changing the selected department from (2 to 4). So if that is indeed the case, then you need to make sure to actually load the existing "Department(4)" and/or get a handle to this and then create a new Set for the dropdown.departments=new HashSet()... and add Department(4) to that new set, then save the dropdown. (or alternatively remove department(2) from the existing set, and add the new one). the inverse="false" should be set, such that the managing entity is the "One" side (dropdown).

Post your xml mappings and your java code used to save, so we can take a look at it... to make a better determination.

_________________
-JT

If you find my replies helpful, please rate by clicking 'Y' on them. I appreciate it.


Top
 Profile  
 
 Post subject: identifier of an instance of com.kink.model.Depart altered
PostPosted: Thu Mar 09, 2006 12:49 am 
Newbie

Joined: Wed Mar 08, 2006 3:31 am
Posts: 5
Thanks for the response…..

My department table has 4 entries and I’m changing from 2 to 4 in the drop down. It can retrieve and display the current entry in the dropdown, but if I try to change the department that the workorder was assigned to I get this error (I try to select a different department)………departments are displayed in the dropdown as strings (IT, Art, Admin, Facilities).

I’m storing departments as a Set, not HashSet.?

Department.hbm.xml(relevant part)

<hibernate-mapping
>
<class
name="com.kink.model.Department"
table="department"
>

<id
name="id"
column="id"
type="java.lang.Long"
>
<generator class="native">
<!--
To add non XDoclet generator parameters, create a file named
hibernate-generator-params-Department.xml
containing the additional parameters and place it in your merge dir.
-->
</generator>
</id>

</set>

<set
name="workorders"
lazy="true"
inverse="false"
cascade="none"
sort="unsorted"
>

<key
column="departmentId"
>
</key>

<one-to-many
class="com.kink.model.Workorder"
/>

</set>

</class>

</hibernate-mapping>


Workorder.hbm.xml (relevant part)



<hibernate-mapping
>
<class
name="com.kink.model.Workorder"
table="workorder"
>

<id
name="id"
column="id"
type="java.lang.Long"
>
<generator class="native">
<!--
To add non XDoclet generator parameters, create a file named
hibernate-generator-params-Workorder.xml
containing the additional parameters and place it in your merge dir.
-->
</generator>
</id>

<

<many-to-one
name="department"
class="com.kink.model.Department"
cascade="none"
outer-join="auto"
update="true"
insert="true"
>
<column
name="departmentId"
/>
</many-to-one>

</class>

</hibernate-mapping>


WorkOrderFormcontroller


public class WorkorderFormController extends BaseFormController {
private WorkorderManager workorderManager = null;
private DepartmentManager departmentManager = null;

public void setWorkorderManager(WorkorderManager workorderManager) {
this.workorderManager = workorderManager;
}

protected Map referenceData(HttpServletRequest request)
throws ServletException {
Map model = new HashMap();
model.put("departments", departmentManager.getDepartments(new Department()));

return model;
}

public void setDepartmentManager(DepartmentManager departmentManager){
this.departmentManager = departmentManager;
}

public DepartmentManager getDepartmentManager(){
return this.departmentManager;
}


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

if (!StringUtils.isEmpty(id)) {
workorder = workorderManager.getWorkorder(id);
} else {
workorder = new Workorder();
}

return workorder;
}

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

Workorder workorder = (Workorder) command;
boolean isNew = (workorder.getId() == null);
Locale locale = request.getLocale();

if (request.getParameter("delete") != null) {
workorderManager.removeWorkorder(workorder.getId().toString());

saveMessage(request, getText("workorder.deleted", locale));
} else {
workorderManager.saveWorkorder(workorder);

String key = (isNew) ? "workorder.added" : "workorder.updated";
saveMessage(request, getText(key, locale));

if (!isNew) {
return new ModelAndView("redirect:editWorkorder.html", "id", workorder.getId());
}
}

return new ModelAndView(getSuccessView());
}


=====================

would really appreciate it if you could fill in any blanks I'm having..


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 09, 2006 3:30 pm 
Expert
Expert

Joined: Mon Jan 09, 2006 5:01 pm
Posts: 311
Location: Sacramento, CA
you have Department(1) to (M)Workorders...
You should have unsaved-value="null" in your ID's.

proper procedure:
1) in your html form, you have a <select that has the ID's as values and the names as text displayed.
2) When you submit you query/load if not already in hibernates 2nd cache the department collection (read-only immutable data). Either way (w or w/o the cache) you do a session.load(passingid) to get a handle to the newly assigned department.
3) in the onsubmit the function: workorderManager.getWorkorder(id) will retrieve a handle to the existing work-order, managed by hibernate - object is in "attached" state.
4) the department object as found in #3 is assigned to the "workorder"
and
5) you saveOrUpdate the work order. w/ workorderManager.saveWorkorder(workorder);

Look over your code and verify all these steps. It should work... ;)

Hope this helps.

_________________
-JT

If you find my replies helpful, please rate by clicking 'Y' on them. I appreciate it.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 14, 2006 8:56 pm 
Newbie

Joined: Wed Mar 08, 2006 3:31 am
Posts: 5
Hi

I've posted this on a couple off different sites

http://www.nabble.com/Dropdown-box-i...7820c2369.html

and

http://forum.hibernate.org/viewtopic.php?t=956534

the biggest problem that I'm having is this all new and I don't have too much experience..........as you can see I've tried different approaches, but still unable to get it to work...could you give me some pointers on how to work with PropertyEditors

here what I have....how wold I tie this into WorkOrderFormController

package com.kink.webapp.propertyeditor;

import java.beans.PropertyEditorSupport;

import com.kink.model.Department;
import com.kink.service.Manager;


/**
* This class knows how to get a project instance from a project id and vice-versa.
*
* <p>$Date$</p>
* @author $Author$
* @version $Revision$
*/
public class DepartmentPropertyEditor extends PropertyEditorSupport {
private Manager manager;

public DepartmentPropertyEditor(Manager manager) {
this.manager = manager;
}

/*
* (non-Javadoc)
*
* @see java.beans.PropertyEditorSupport#getAsText()
*/
public String getAsText() {
Department p = (Department) getValue();
if (p != null)
return String.valueOf(p.getId());
else
return null;
}

/*
* (non-Javadoc)
*
* @see java.beans.PropertyEditorSupport#setAsText(java.la ng.String)
*/
public void setAsText(String departmentId) throws IllegalArgumentException {
Long id = Long.valueOf(departmentId);
Department d = (Department) manager.getObject(Department.class, id);
setValue(d);
}
}

/* ************************************************** **************
* $Log$
* ************************************************** *************/




package com.kink.webapp.action;

import java.util.Locale;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;

import org.apache.commons.lang.StringUtils;
import com.kink.model.Workorder;
import com.kink.model.Department;
import com.kink.service.WorkorderManager;
import com.kink.service.DepartmentManager;

import org.springframework.beans.PropertyValue;
import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;


public class WorkorderFormController extends BaseFormController {
private WorkorderManager workorderManager = null;
private DepartmentManager departmentManager = null;

public void setWorkorderManager(WorkorderManager workorderManager) {
this.workorderManager = workorderManager;
}

protected Map referenceData(HttpServletRequest request)
throws ServletException {
Map model = new HashMap();
model.put("departments", departmentManager.getDepartments(new Department()));

return model;
}

public void setDepartmentManager(DepartmentManager departmentManager){
this.departmentManager = departmentManager;
}

public DepartmentManager getDepartmentManager(){
return this.departmentManager;
}


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

if (!StringUtils.isEmpty(id)) {
workorder = workorderManager.getWorkorder(id);
} else {
workorder = new Workorder();
}

return workorder;
}

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

Workorder workorder = (Workorder) command;
boolean isNew = (workorder.getId() == null);
Locale locale = request.getLocale();

if (request.getParameter("delete") != null) {
workorderManager.removeWorkorder(workorder.getId() .toString());

saveMessage(request, getText("workorder.deleted", locale));
} else {
//PropertyValue v = new PropertyValue("department", departmentManager.setDepartmentDAO());

workorderManager.saveWorkorder(workorder);

String key = (isNew) ? "workorder.added" : "workorder.updated";
saveMessage(request, getText(key, locale));

if (!isNew) {
return new ModelAndView("redirect:editWorkorder.html", "id", workorder.getId());
}
}

return new ModelAndView(getSuccessView());
}


}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.