I'm thinking the same way - but dont know how to fix it!
the delete action updates the version number from the previous transaction.
----------
---- | ----- |
| | ---> | | | |
----- | ------ |
----------
client AS server and EJB server code
| ... container based delete action that updates the DB and increments the
version i'ds on the DB . Server code ...
|
| @TransactionAttribute (TransactionAttributeType.REQUIRED)
| public boolean removeLink (Node fromNode, Node remoteNode)
| {
|
| List<Link> qres;
| Logger log = Logger.getLogger("NodeEAOBean");
| log.setLevel(org.apache.log4j.Level.DEBUG);
|
| if (fromNode == null || remoteNode == null)
| {
| log.error("was passed a null reference");
| return false;
| }
|
| fromNode = em.merge(fromNode);
| remoteNode = em.merge(remoteNode);
| Query q = em.createNamedQuery("findLinksBetweenNodes");
| q.setParameter("toNode", remoteNode);
| q.setParameter("fromNode", fromNode);
|
| log.debug("to node details " + remoteNode.getNodeName() + "\n");
|
| qres = (List<Link>)q.getResultList();
| if (qres != null && qres.size () == 1)
| {
| Link link = qres.get(0);
| remoteNode.deleteLinkFrom(link);
| fromNode.deleteLinkTo(link);
| em.remove(link);
| //fix?
| em.flush();
| return true;
| }
| else
| {return false;}
|
| }
|
however despite the merge actions and the end of the transaction completing ( i
even put the flush in and it made no difference). These changes dont get
synced back to the application client (outside the container).
so how are you supposed to get the client back in sync ? I tried a resync
operation from the client like this
| ... client code - calls the remove link then tries to resynch with server
| after the the above code has ompleted...
|
| //local if (removeLink(uNode, zNode))
| if (nodeEAO.removeLink(uNode, zNode))
| {
|
| System.out.println ("deleted link : \n");
| }
|
| //update to latest version number
| yNode = nodeEAO.refresh(uNode);
|
and this errors with the same optimistic lock exception
on the EJB server side the refresh is implemented as
| ... generic EAO class code ...
|
| public T refresh (T entity)
| {
| entity = em.merge(entity);
| em.refresh (entity);
| return entity;
| }
|
I thought this was going to be enough to resync the client local copy to the
extant version on the DB. but the error still occurs.
How is this supposed to work ???
do i have to do a complete new findByID call and get a new reference from the
client ? seems a bit weird - surely there is a way to update a disconnected
client copy with the changes on the EJB server?
should version managment be avoided (doesnt seem right). If not just how the
heck is this supposed to work.
thanks in advance if you can help
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4119468#4119468
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4119468
_______________________________________________
jboss-user mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/jboss-user