persistence@glassfish.java.net

Re: problem with _at_ManyToMany collection based relationship merge

From: Marina Vatkina <Marina.Vatkina_at_Sun.COM>
Date: Tue, 31 Jul 2007 13:22:35 -0700

makcro,

I'm glad it works.

Can it be that you were hitting issue
https://glassfish.dev.java.net/issues/show_bug.cgi?id=3334?

thanks,
-marina

makcro wrote:
> I fixed the problem!:jumping:
> i moved code from session bean to struts action as follows:
>
> CityFacadeLocal cityFacade = lookupCityFacade();
> //prikupljanje novih podataka o ciljnoj grupi
> String newGender = ctf.getGender();
> String newMaxYears = ctf.getMaxyears();
> String newMinYears = ctf.getMinyears();
> String[] newSelectedCities =
> ctf.getSelectedCities();
>
>
> //niz imena gradova se prevodi u kolekcju objekata
> City
> Collection<City> newCitiesObjCollection = new
> Vector<City>();
> for(int i = 0; i < newSelectedCities.length; i++){
> String tmpCityName = newSelectedCities[i];
> City tmpCityObj = cityFacade.find(tmpCityName);
> newCitiesObjCollection.add(tmpCityObj);
> }
>
> //setovanje novih podataka
> targetgroupForUD.setGender(newGender);
>
> targetgroupForUD.setMinyearold(Integer.parseInt(newMinYears));
>
> targetgroupForUD.setMaxyearold(Integer.parseInt(newMaxYears));
>
> targetgroupForUD.setCityidCollection(newCitiesObjCollection);
>
> //pozivanje update metdoe u session beany
> targetgroupFacade.edit(targetgroupForUD);
>
>
> //korisnik se vraca na stranu sa svim postojecim
> ciljnim grupama
> forward =
> mapping.findForward("backend.targetgroups");
>
> and now it works. I guess the reason was the same transaction context for
> both Targetgroup and City entities. Now when they are separated it works
> fine.
> Thanks!
>
> Marina Vatkina wrote:
>
>>Hi,
>>
>>First of all you need to look into the server.log to see the actual cause
>>of the
>>exception.
>>
>>Second, are the relationships bidirectional or unidirectional? If it's the
>>former, you need to set the other side of the relationship as well.
>>
>>thanks,
>>-marina
>>
>>makcro wrote:
>>
>>>I am using struts 1.2.9 and java ee 5 sdk update 2 for my enterprise
>>>application. Besides others i have these entity neans
>>>http://www.nabble.com/file/p11808789/Targetgroup.java Targetgroup.java
>>>and
>>>http://www.nabble.com/file/p11808789/City.java City.java , with
>>>manytomany
>>>relationship.
>>>when user updates Targetgroup, following code is executed in my stateless
>>>bean:
>>>
>>>public void update(String firmId, String targetgroupId, String newGender,
>>>String newMinYearsOld, String newMaxYearsOld, String[] newCities) {
>>> TargetgroupPK pkForUpdate = new TargetgroupPK(targetgroupId,
>>>firmId);
>>> Targetgroup targetgroupForUpdate = find(pkForUpdate);
>>>
>>> targetgroupForUpdate.setGender(newGender);
>>>
>>>targetgroupForUpdate.setMinyearold(Integer.parseInt(newMinYearsOld));
>>>
>>>targetgroupForUpdate.setMaxyearold(Integer.parseInt(newMaxYearsOld));
>>>
>>> //pronalazenje gradva za koje je vezana ciljna grupa
>>> Collection<City> newCitiesCollection = new ArrayList<City>();
>>>
>>> for(int i = 0; i < newCities.length; i++){
>>> String tmp_city_name = newCities[i];
>>> City city_obj = cityFacade.find(tmp_city_name);
>>> newCitiesCollection.add(city_obj);
>>> }
>>> targetgroupForUpdate.setCityidCollection(newCitiesCollection);
>>>
>>>
>>>
>>> }
>>>
>>>this code throws following exception:
>>>
>>>[#|2007-07-26T12:13:36.993+0200|SEVERE|sun-appserver-pe9.0|javax.enterprise.system.container.web|_ThreadID=16;_ThreadName=httpWorkerThread-8080-0;_RequestID=f79d9c50-86b0-4b6c-96ab-97956dfb39c1;|StandardWrapperValve[action]:
>>>Servlet.service() for servlet action threw exception
>>>javax.ejb.EJBException: Transaction aborted; nested exception is:
>>>javax.transaction.RollbackException: Transaction marked for rollback.
>>>javax.transaction.RollbackException: Transaction marked for rollback.
>>> at
>>>com.sun.enterprise.distributedtx.J2EETransaction.commit(J2EETransaction.java:416)
>>> at
>>>com.sun.enterprise.distributedtx.J2EETransactionManagerOpt.commit(J2EETransactionManagerOpt.java:357)
>>> at
>>>com.sun.ejb.containers.BaseContainer.completeNewTx(BaseContainer.java:3653)
>>> at
>>>com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:3431)
>>> at
>>>com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1247)
>>> at
>>>com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:192)
>>> at
>>>com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:71)
>>> at $Proxy149.update(Unknown Source)
>>> at
>>>audiotel.sms.actions.backoffice.TargetgroupDispatchAction.updateOrDelete(TargetgroupDispatchAction.java:132)
>>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>> at
>>>sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>>> at
>>>sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>>> at java.lang.reflect.Method.invoke(Method.java:597)
>>> at
>>>org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:270)
>>> at
>>>org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:187)
>>> at
>>>org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
>>> at
>>>org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
>>> at
>>>org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
>>> at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
>>> at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
>>> at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
>>> at
>>>org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:397)
>>> at
>>>org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:278)
>>> at
>>>org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)
>>> at
>>>org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:536)
>>> at
>>>org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:240)
>>> at
>>>org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:179)
>>> at
>>>org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)
>>> at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:73)
>>> at
>>>org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:182)
>>> at
>>>org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)
>>> at
>>>com.sun.enterprise.web.VirtualServerPipeline.invoke(VirtualServerPipeline.java:120)
>>> at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:939)
>>> at
>>>org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:137)
>>> at
>>>org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)
>>> at
>>>org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:536)
>>> at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:939)
>>> at
>>>org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:239)
>>> at
>>>com.sun.enterprise.web.connector.grizzly.ProcessorTask.invokeAdapter(ProcessorTask.java:667)
>>> at
>>>com.sun.enterprise.web.connector.grizzly.ProcessorTask.processNonBlocked(ProcessorTask.java:574)
>>> at
>>>com.sun.enterprise.web.connector.grizzly.ProcessorTask.process(ProcessorTask.java:844)
>>> at
>>>com.sun.enterprise.web.connector.grizzly.ReadTask.executeProcessorTask(ReadTask.java:287)
>>> at
>>>com.sun.enterprise.web.connector.grizzly.ReadTask.doTask(ReadTask.java:212)
>>> at
>>>com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:252)
>>> at
>>>com.sun.enterprise.web.connector.grizzly.WorkerThread.run(WorkerThread.java:75)
>>>javax.ejb.EJBException: Transaction aborted; nested exception is:
>>>javax.transaction.RollbackException: Transaction marked for rollback.
>>> at
>>>com.sun.ejb.containers.BaseContainer.completeNewTx(BaseContainer.java:3659)
>>> at
>>>com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:3431)
>>> at
>>>com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1247)
>>> at
>>>com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:192)
>>> at
>>>com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:71)
>>> at $Proxy149.update(Unknown Source)
>>> at
>>>audiotel.sms.actions.backoffice.TargetgroupDispatchAction.updateOrDelete(TargetgroupDispatchAction.java:132)
>>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>> at
>>>sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>>> at
>>>sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>>> at java.lang.reflect.Method.invoke(Method.java:597)
>>> at
>>>org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:270)
>>> at
>>>org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:187)
>>> at
>>>org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
>>> at
>>>org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
>>> at
>>>org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
>>> at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
>>> at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
>>> at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
>>> at
>>>org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:397)
>>> at
>>>org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:278)
>>> at
>>>org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)
>>> at
>>>org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:536)
>>> at
>>>org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:240)
>>> at
>>>org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:179)
>>> at
>>>org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)
>>> at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:73)
>>> at
>>>org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:182)
>>> at
>>>org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)
>>> at
>>>com.sun.enterprise.web.VirtualServerPipeline.invoke(VirtualServerPipeline.java:120)
>>> at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:939)
>>> at
>>>org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:137)
>>> at
>>>org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)
>>> at
>>>org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:536)
>>> at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:939)
>>> at
>>>org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:239)
>>> at
>>>com.sun.enterprise.web.connector.grizzly.ProcessorTask.invokeAdapter(ProcessorTask.java:667)
>>> at
>>>com.sun.enterprise.web.connector.grizzly.ProcessorTask.processNonBlocked(ProcessorTask.java:574)
>>> at
>>>com.sun.enterprise.web.connector.grizzly.ProcessorTask.process(ProcessorTask.java:844)
>>> at
>>>com.sun.enterprise.web.connector.grizzly.ReadTask.executeProcessorTask(ReadTask.java:287)
>>> at
>>>com.sun.enterprise.web.connector.grizzly.ReadTask.doTask(ReadTask.java:212)
>>> at
>>>com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:252)
>>> at
>>>com.sun.enterprise.web.connector.grizzly.WorkerThread.run(WorkerThread.java:75)
>>>|#]
>>>
>>>ONLY when in parameter newCities are city names allready connected to
>>>Targetgroup. when NewCities contains names of
>>>City objects which are not connected to Targetgroup it works fine, but
>>>it's
>>>of no use for me, because user must be able to add or remove certian
>>>cities
>>>from relaionship with Targetgroup.
>>>
>>>Does anyone know what is the problem?
>>>Thanks!
>>>
>>
>>
>