[EJB 3.0] - Confusion over em.refresh()?
by lowecg2004
Hello All,
I'm working on a Seam/EJB3 app where I have a persisted object that I am editing. The object has a many-to-one set, to which the user can add newly created objects via the UI. If the user adds an object and chooses "ok" to persist their changes then all is well, the new object gets persisted just fine. The problem I am having is when the user chooses "Cancel". Rather than unpicking their changes, I wanted to simply call em.refresh(obj) to reset the object back to the previous state, however I get the following exception when I try this:
No row with the given identifier exists: [com.example.model.Address#0]
| at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:614)
| at org.hibernate.ejb.AbstractEntityManagerImpl.refresh(AbstractEntityManagerImpl.java:269)
| at org.jboss.ejb3.entity.ExtendedEntityManager.refresh(ExtendedEntityManager.java:154)
| at org.jboss.seam.persistence.EntityManagerProxy.refresh(EntityManagerProxy.java:133)
So, it looks like the EM has tried to refresh one of the newly created child objects rather simply restoring the object's many-to-one set.
If I call obj.getAddresses().clear() prior to calling refresh() then it succeeds. I get my object with the previous state.
My (simplistic?) expectation of refresh was that I could call it regardless of the state I manage to get the object into and it will revert it back to the state of the database. Should this be the case?
Cheers,
Chris.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4045994#4045994
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4045994
19 years, 1 month
[EJB 3.0] - merge() behavior - is that correct?
by tarcio
Hi there,
I'm new to EJB3 and not sure if the behavior is correct or not.
I have a stateless session bean that searches for an Entity bean and returns the found object to the client:
FIRST SESSION BEAN
|
| public DestructionBin findDestructionBin(long id) {
| return manager.find(DestructionBin.class, id);
| }
|
The client is a struts application. The returned entity is assigned to an ActionForm and is then changed on a webpage. Once the form is submitted I get this modified entity and call an update method on another stateless session bean.
STRUTS ACTION PROCESSING...
|
| public ActionForward saveData(ActionMapping mapping, ActionForm form,
| HttpServletRequest request, HttpServletResponse response) {
| EditBinForm formObj = (EditBinForm) form;
|
| try {
| ManageDestructionBin mngBins = (ManageDestructionBin) GeneralWebUtil.getJNDIObject(ManageDestructionBinBean.JNDILocal, ManageDestructionBin.class);
|
| if (formObj.getId() > 0)
| mngBins.updateDestructionBin(formObj.getBin(), formObj
| .getWarehouse());
| ...
|
| SECOND SESSION BEAN
|
| public boolean updateDestructionBin(DestructionBin bin, long warehouse)
| throws WarehouseException {
| try {
| Warehouse wh = mngWarehouse.findWarehouse(warehouse);
| bin.setWarehouse(wh);
| manager.merge(bin);
| } catch (Exception e) {
| throw new WarehouseException(e.getMessage());
| }
|
| return true;
| }
|
However, when the merge is called.. this is the stacktrace I get from EJB server:
| 09:43:51,941 WARN [JDBCExceptionReporter] SQL Error: 0, SQLState: null
| 09:43:51,941 ERROR [JDBCExceptionReporter] Batch entry 0 update TBL_DESTRUCTION_BIN set LASTUPDATE_=2007-05-16 09:43:51.809000 +1000, STATUS_=NULL, CLIENTREF_=VIC71234560, ACCESSCOUNT_=0, CREATEDBY_=NULL, BARCODE_=NULL, CREATEDATE_=NULL, LASTACCESSED_=NULL, PRINTED_=0, TYPE_=ST, SIZE_=1L, WAREHOUSE_=2, DEPARTMENT_=NULL, BUSINESSDAY_=0, COLLECTIONDATE_=NULL, DELIVERYDATE_=NULL, ROTATIONSCHEDULE_=NULL where ID_=4 was aborted. Call getNextException to see the cause.
| 09:43:51,942 WARN [JDBCExceptionReporter] SQL Error: 0, SQLState: 23502
| 09:43:51,942 ERROR [JDBCExceptionReporter] ERROR: null value in column "status_" violates not-null constraint
| 09:43:51,942 ERROR [AbstractFlushingEventListener] Could not synchronize database state with session
| org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
|
Could anyone please tell me if this is the correct behavior? It's quite annoying to find the object again and just change the updated fields.. and I also don't think this is the solution for it ehehehehe
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4045992#4045992
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4045992
19 years, 1 month
[JBoss Seam] - Re: Breadcrumbs
by gzoller
I wasn't using nested conversations. I'm 100% in xhtml (not touching any Java code at this point in my app) so I changed my pages.xml to look like this:
| <pages>
| <page view-id="/home.xhtml">Home
| <begin-conversation nested="true"/>
| </page>
| <page view-id="/Timezones.xhtml">World Time
| <begin-conversation nested="true"/>
| </page>
| <page view-id="/Foo.xhtml">FooBar
| <begin-conversation nested="true"/>
| </page>
| </pages>
|
Different things are happening, but still getting non-working behavior. For example World Time page now just has 1 breadcrumb: World Time. FooBar now has 3--Two say World Time and one says FooBar, but all 3 point to Foo.xhml. ???
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4045990#4045990
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4045990
19 years, 1 month