[jboss-user] [EJB 3.0] - Aarg - more guideance required

wiggy do-not-reply at jboss.com
Mon Jan 14 18:41:11 EST 2008


okay so heres the latest 

1.  if a enable the @Version tag on the entity model - it gives me the optimistic lock error - even on the local resynch operation.

2.  if  disable the optimistic lock - the error disppears - however the database behavior is not as expected.

hers the local client code - the NodeEAO ejb runs the server.  The rest as is in the client.


  | 
  | public class EAOtest {
  | 
  | 	/**
  | 	 * @param args
  | 	 */
  | 	public static void main(String[] args) throws Exception
  | 	{
  | 		InitialContext ctx;
  | 		DataSource ds;
  | 		Connection conn;
  | 		MessageEAO myMess;
  | 		NodeEAO nodeEAO;
  | 		LinkEAO linkEAO;
  | 	
  | 		Node aNode, bNode, cNode, uNode, zNode, yNode;
  | 		
  | 
  | 			ctx = getInitialContext();
  | 			nodeEAO = (NodeEAO) ctx.lookup ("NeilsAppEar/NodeEAOBean/remote");
  | 			linkEAO = (LinkEAO) ctx.lookup ("NeilsAppEar/LinkEAOBean/remote");
  | 			
  | 			aNode = new Node();
  | 			bNode = new Node ();
  | 			cNode = new Node ();
  | 			uNode = new Node (); // empty
  | 			zNode = new Node (); // empty
  | 			yNode = new Node();
  | 			
  | 
  | 			aNode.setNodeName("William");
  | 			bNode.setNodeName("10 South Close");
  | 			cNode.setNodeName("G01 B32");
  | 
  | 			try
  | 			{
  | 			UserTransaction ut = (UserTransaction)ctx.lookup("UserTransaction");
  | 			ut.begin();
  | 			//now works!
  | 			Link aLink = aNode.addLinkTo(bNode);
  | 			aNode.addLinkTo(cNode);
  | 			//update uNode to persisted value 
  | 			uNode = nodeEAO.save(aNode);
  | 
  | 			ut.commit();
  | 			} catch (Exception e)
  | 			{e.printStackTrace();
  | 			System.exit(0);} 
  | 			
  | 			System.out.println ("done/n");
  | 			
  | 
  | 			Long pk = Long.valueOf(3);
  | 			zNode = nodeEAO.findById(pk);
  | 
  | 		
  | 			//local if (removeLink(uNode, zNode))
  | 			if (nodeEAO.removeLink(uNode, zNode))			{
  | 
  | 				System.out.println ("deleted link  : \n");
  | 			}
  | 
  | 			yNode = resynch (uNode);			
  | 			//update to latest version number
  | 			yNode = nodeEAO.refresh(uNode);			
  | 			List<Node> nodeList2 = nodeEAO.getConnectedToNodes(uNode);
  | 			if (nodeList2 != null)
  | 			{
  | 				for (Node n : nodeList2 )
  | 				{
  | 					System.out.println ("got connected node : " + n.getNodeName() + "/n");
  | 				}
  | 			}
  | 			else
  | 				System.out.println ("got empty connection : /n");
  | 	
  | 	}
  | 
  | 	public static boolean removeLink (Node fromNode, Node remoteNode)
  | 	{
  | 		EntityManager em;
  | 		EntityManagerFactory emf ;
  | 		List<Link> res;
  | 		boolean result = false;
  | 
  | 		emf = Persistence.createEntityManagerFactory("embedDS");
  | 
  | 		em = emf.createEntityManager();
  | 
  | 		try
  | 		{
  | 		EntityTransaction t = em.getTransaction(); 
  | 
  | 		t.begin();
  | 		fromNode = em.merge(fromNode);
  | 		remoteNode = em.merge(remoteNode);
  | 		Query q = em.createNamedQuery("findLinksBetweenNodes");
  | 		q.setParameter("toNode", remoteNode);
  | 		q.setParameter("fromNode", fromNode);
  | 				
  | 		res = (List<Link>)q.getResultList();
  | 		if (res != null && res.size () == 1)
  | 		{
  | 			Link link =  res.get(0);
  | 			remoteNode.deleteLinkFrom(link);
  | 			fromNode.deleteLinkTo(link);
  | 			em.remove(link);
  | 			result = true;
  | 		}
  | 		else
  | 			{result = false;}
  | 
  | 		t.commit();
  | 		return result;
  | 		} 
  | 		finally 
  | 		{
  | 			em.close();
  | 			emf.close();
  | 		}
  | 
  | 	}
  | 
  | 	public static Node resynch (Node fromNode)
  | 	{
  | 		EntityManager em;
  | 		EntityManagerFactory emf ;
  | 		List<Link> res;
  | 		boolean result = false;
  | 
  | 		emf = Persistence.createEntityManagerFactory("embedDS");
  | 
  | 		em = emf.createEntityManager();
  | 
  | 		try
  | 		{
  | 		EntityTransaction t = em.getTransaction(); 
  | 
  | 		t.begin();
  | 		fromNode = em.merge(fromNode);
  | 		em.refresh(fromNode);
  | 	
  | 		t.commit();
  | 		return fromNode;
  | 		} 
  | 		finally 
  | 		{
  | 			em.close();
  | 			emf.close();
  | 		}
  | 
  | 	}
  | 
  | 	public static InitialContext getInitialContext() throws Exception
  | 	{
  | 	   Hashtable<String,String> props = getInitialContextProperties();
  | 	   return new InitialContext(props);
  | 	}
  | 
  | 	private static Hashtable<String,String> getInitialContextProperties()
  | 	{
  | 	   Hashtable<String,String> props = new Hashtable<String,String>();
  | 	   // fails corrected version below : props.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
  | 	   props.put("java.naming.factory.initial", "org.jboss.naming.NamingContextFactory");
  | 	   props.put("java.naming.provider.url", "jnp://localhost:1099");
  | 	   props.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
  | 	   return props;
  | 	}
  | }
  |  

so what happens 

1) first i create an A Node, and two remote nodes, b and c.
I connect the a end to the b and c ends - this creates the link entities that joins the start and end node.

in the entity model i have transitive persistence set for PERSIST and MERGE, therefore the nodeEAO.save (aNode) - persists the whole network - this goes across from app client to ejb server.  
hold the returned object into uNode.

This works okay and the DB has three nodes and 2 link records.

2) I then read zNode by a nodeEAO.find method (again to ejb server).  This returns the 3rd node - however its been lazy loaded it appears and the Set attributes (toLinks and fromLinks) are null - and therefore cant be walked from the client. 

heres the query from the server side.

  | 23:03:29,639 INFO  [STDOUT] Hibernate: select node0_.nodeID as nodeID73_0_, node0_.version as version73_0_, node0_.lastUpdated as lastUpda4_73_0_, node0_.nodeName as nodeName73_0_, node0_.aliasName as aliasName73_0_, node0_.weight as weight73_0_, node0_.importance as importance73_0_, node0_.firstName as firstName73_0_, node0_.middleName as middleName73_0_, node0_.lastName as lastName73_0_, node0_.nickName as nickName73_0_, node0_.dateOfBirth as dateOfB13_73_0_, node0_.dateOfDeath as dateOfD14_73_0_, node0_.sex as sex73_0_, node0_.nodeType as nodeType73_0_ from Node node0_ where node0_.nodeID=?
  | 
  | 
  | I think this is as the book says - if i want the Set attributes i have to force a non lazy load.  Still okay i think.
  | 
  | 3) i call the nodeEAO.removeLink (on the server).  This seems to work okay - and the DB now has 3 nodes and 1 link left.
  | 
  | heres the sql coming out of the server this action to update A and C nodes and delete the link from A-C nodes in the DB.
  | 
  |   | 23:05:36,121 INFO  [STDOUT] Hibernate: select node0_.nodeID as nodeID73_2_, node0_.version as version73_2_, node0_.lastUpdated as lastUpda4_73_2_, node0_.nodeName as nodeName73_2_, node0_.aliasName as aliasName73_2_, node0_.weight as weight73_2_, node0_.importance as importance73_2_, node0_.firstName as firstName73_2_, node0_.middleName as middleName73_2_, node0_.lastName as lastName73_2_, node0_.nickName as nickName73_2_, node0_.dateOfBirth as dateOfB13_73_2_, node0_.dateOfDeath as dateOfD14_73_2_, node0_.sex as sex73_2_, node0_.nodeType as nodeType73_2_, fromlinks1_.fromNode_nodeID as fromNode5_4_, fromlinks1_.linkID as linkID4_, fromlinks1_.linkID as linkID70_0_, fromlinks1_.version as version70_0_, fromlinks1_.toNode_nodeID as toNode6_70_0_, fromlinks1_.fromNode_nodeID as fromNode5_70_0_, fromlinks1_.name as name70_0_, fromlinks1_.description as descript4_70_0_, node2_.nodeID as nodeID73_1_, node2_.version as version73_1_, node2_.lastUpdated as lastUpda4_73_1_, node2_.nodeName as nodeName73_1_, node2_.aliasName as aliasName73_1_, node2_.weight as weight73_1_, node2_.importance as importance73_1_, node2_.firstName as firstName73_1_, node2_.middleName as middleName73_1_, node2_.lastName as lastName73_1_, node2_.nickName as nickName73_1_, node2_.dateOfBirth as dateOfB13_73_1_, node2_.dateOfDeath as dateOfD14_73_1_, node2_.sex as sex73_1_, node2_.nodeType as nodeType73_1_ from Node node0_ left outer join Link fromlinks1_ on node0_.nodeID=fromlinks1_.fromNode_nodeID left outer join Node node2_ on fromlinks1_.toNode_nodeID=node2_.nodeID where node0_.nodeID=?
  |   | 23:05:36,131 INFO  [STDOUT] Hibernate: select fromlinks0_.fromNode_nodeID as fromNode5_2_, fromlinks0_.linkID as linkID2_, fromlinks0_.linkID as linkID70_1_, fromlinks0_.version as version70_1_, fromlinks0_.toNode_nodeID as toNode6_70_1_, fromlinks0_.fromNode_nodeID as fromNode5_70_1_, fromlinks0_.name as name70_1_, fromlinks0_.description as descript4_70_1_, node1_.nodeID as nodeID73_0_, node1_.version as version73_0_, node1_.lastUpdated as lastUpda4_73_0_, node1_.nodeName as nodeName73_0_, node1_.aliasName as aliasName73_0_, node1_.weight as weight73_0_, node1_.importance as importance73_0_, node1_.firstName as firstName73_0_, node1_.middleName as middleName73_0_, node1_.lastName as lastName73_0_, node1_.nickName as nickName73_0_, node1_.dateOfBirth as dateOfB13_73_0_, node1_.dateOfDeath as dateOfD14_73_0_, node1_.sex as sex73_0_, node1_.nodeType as nodeType73_0_ from Link fromlinks0_ left outer join Node node1_ on fromlinks0_.toNode_nodeID=node1_.nodeID where fromlinks0_.fromNode_nodeID=?
  |   | 23:05:36,131 INFO  [STDOUT] Hibernate: select fromlinks0_.fromNode_nodeID as fromNode5_2_, fromlinks0_.linkID as linkID2_, fromlinks0_.linkID as linkID70_1_, fromlinks0_.version as version70_1_, fromlinks0_.toNode_nodeID as toNode6_70_1_, fromlinks0_.fromNode_nodeID as fromNode5_70_1_, fromlinks0_.name as name70_1_, fromlinks0_.description as descript4_70_1_, node1_.nodeID as nodeID73_0_, node1_.version as version73_0_, node1_.lastUpdated as lastUpda4_73_0_, node1_.nodeName as nodeName73_0_, node1_.aliasName as aliasName73_0_, node1_.weight as weight73_0_, node1_.importance as importance73_0_, node1_.firstName as firstName73_0_, node1_.middleName as middleName73_0_, node1_.lastName as lastName73_0_, node1_.nickName as nickName73_0_, node1_.dateOfBirth as dateOfB13_73_0_, node1_.dateOfDeath as dateOfD14_73_0_, node1_.sex as sex73_0_, node1_.nodeType as nodeType73_0_ from Link fromlinks0_ left outer join Node node1_ on fromlinks0_.toNode_nodeID=node1_.nodeID where fromlinks0_.fromNode_nodeID=?
  |   | 23:05:36,131 INFO  [STDOUT] Hibernate: select tolinks0_.toNode_nodeID as toNode6_2_, tolinks0_.linkID as linkID2_, tolinks0_.linkID as linkID70_1_, tolinks0_.version as version70_1_, tolinks0_.toNode_nodeID as toNode6_70_1_, tolinks0_.fromNode_nodeID as fromNode5_70_1_, tolinks0_.name as name70_1_, tolinks0_.description as descript4_70_1_, node1_.nodeID as nodeID73_0_, node1_.version as version73_0_, node1_.lastUpdated as lastUpda4_73_0_, node1_.nodeName as nodeName73_0_, node1_.aliasName as aliasName73_0_, node1_.weight as weight73_0_, node1_.importance as importance73_0_, node1_.firstName as firstName73_0_, node1_.middleName as middleName73_0_, node1_.lastName as lastName73_0_, node1_.nickName as nickName73_0_, node1_.dateOfBirth as dateOfB13_73_0_, node1_.dateOfDeath as dateOfD14_73_0_, node1_.sex as sex73_0_, node1_.nodeType as nodeType73_0_ from Link tolinks0_ left outer join Node node1_ on tolinks0_.fromNode_nodeID=node1_.nodeID where tolinks0_.toNode_nodeID=?
  |   | 23:05:36,141 INFO  [STDOUT] Hibernate: select link0_.linkID as linkID70_, link0_.version as version70_, link0_.toNode_nodeID as toNode6_70_, link0_.fromNode_nodeID as fromNode5_70_, link0_.name as name70_, link0_.description as descript4_70_ from Link link0_ where link0_.fromNode_nodeID=? and link0_.toNode_nodeID=?
  |   | 23:05:36,151 INFO  [STDOUT] Hibernate: delete from Link where linkID=?
  |   | 
  | 
  | however the entity updates are not returned as objects via serialisation to the client (think this probably the first problem here as uNode still shows two links to original bNode and cNode.  Therefore now out of date relative to DB.
  | 
  | 4.  I then call the local resync method - thinking to reset the uNode back to the DB 
  | 
  | however the initial merge action - actually calls a new create - so i get two links back and three nodes still.
  | 
  |   | Hibernate: select node0_.nodeID as nodeID0_2_, node0_.version as version0_2_, node0_.lastUpdated as lastUpda4_0_2_, node0_.nodeName as nodeName0_2_, node0_.aliasName as aliasName0_2_, node0_.weight as weight0_2_, node0_.importance as importance0_2_, fromlinks1_.fromNode_nodeID as fromNode6_4_, fromlinks1_.linkID as linkID4_, fromlinks1_.linkID as linkID1_0_, fromlinks1_.version as version1_0_, fromlinks1_.toNode_nodeID as toNode5_1_0_, fromlinks1_.fromNode_nodeID as fromNode6_1_0_, fromlinks1_.name as name1_0_, fromlinks1_.description as descript4_1_0_, node2_.nodeID as nodeID0_1_, node2_.version as version0_1_, node2_.lastUpdated as lastUpda4_0_1_, node2_.nodeName as nodeName0_1_, node2_.aliasName as aliasName0_1_, node2_.weight as weight0_1_, node2_.importance as importance0_1_ from Node node0_ left outer join Link fromlinks1_ on node0_.nodeID=fromlinks1_.fromNode_nodeID left outer join Node node2_ on fromlinks1_.toNode_nodeID=node2_.nodeID where node0_.nodeID=?
  |   | Hibernate: select link0_.linkID as linkID1_2_, link0_.version as version1_2_, link0_.toNode_nodeID as toNode5_1_2_, link0_.fromNode_nodeID as fromNode6_1_2_, link0_.name as name1_2_, link0_.description as descript4_1_2_, node1_.nodeID as nodeID0_0_, node1_.version as version0_0_, node1_.lastUpdated as lastUpda4_0_0_, node1_.nodeName as nodeName0_0_, node1_.aliasName as aliasName0_0_, node1_.weight as weight0_0_, node1_.importance as importance0_0_, fromlinks2_.fromNode_nodeID as fromNode6_4_, fromlinks2_.linkID as linkID4_, fromlinks2_.linkID as linkID1_1_, fromlinks2_.version as version1_1_, fromlinks2_.toNode_nodeID as toNode5_1_1_, fromlinks2_.fromNode_nodeID as fromNode6_1_1_, fromlinks2_.name as name1_1_, fromlinks2_.description as descript4_1_1_ from Link link0_ left outer join Node node1_ on link0_.toNode_nodeID=node1_.nodeID left outer join Link fromlinks2_ on node1_.nodeID=fromlinks2_.fromNode_nodeID where link0_.linkID=?
  |   | Hibernate: select node0_.nodeID as nodeID0_2_, node0_.version as version0_2_, node0_.lastUpdated as lastUpda4_0_2_, node0_.nodeName as nodeName0_2_, node0_.aliasName as aliasName0_2_, node0_.weight as weight0_2_, node0_.importance as importance0_2_, fromlinks1_.fromNode_nodeID as fromNode6_4_, fromlinks1_.linkID as linkID4_, fromlinks1_.linkID as linkID1_0_, fromlinks1_.version as version1_0_, fromlinks1_.toNode_nodeID as toNode5_1_0_, fromlinks1_.fromNode_nodeID as fromNode6_1_0_, fromlinks1_.name as name1_0_, fromlinks1_.description as descript4_1_0_, node2_.nodeID as nodeID0_1_, node2_.version as version0_1_, node2_.lastUpdated as lastUpda4_0_1_, node2_.nodeName as nodeName0_1_, node2_.aliasName as aliasName0_1_, node2_.weight as weight0_1_, node2_.importance as importance0_1_ from Node node0_ left outer join Link fromlinks1_ on node0_.nodeID=fromlinks1_.fromNode_nodeID left outer join Node node2_ on fromlinks1_.toNode_nodeID=node2_.nodeID where node0_.nodeID=?
  |   | Hibernate: insert into Link (version, toNode_nodeID, fromNode_nodeID, name, description) values (?, ?, ?, ?, ?)
  |   | Hibernate: select fromlinks0_.fromNode_nodeID as fromNode6_2_, fromlinks0_.linkID as linkID2_, fromlinks0_.linkID as linkID1_1_, fromlinks0_.version as version1_1_, fromlinks0_.toNode_nodeID as toNode5_1_1_, fromlinks0_.fromNode_nodeID as fromNode6_1_1_, fromlinks0_.name as name1_1_, fromlinks0_.description as descript4_1_1_, node1_.nodeID as nodeID0_0_, node1_.version as version0_0_, node1_.lastUpdated as lastUpda4_0_0_, node1_.nodeName as nodeName0_0_, node1_.aliasName as aliasName0_0_, node1_.weight as weight0_0_, node1_.importance as importance0_0_ from Link fromlinks0_ left outer join Node node1_ on fromlinks0_.toNode_nodeID=node1_.nodeID where fromlinks0_.fromNode_nodeID=?
  |   | Hibernate: select tolinks0_.toNode_nodeID as toNode5_2_, tolinks0_.linkID as linkID2_, tolinks0_.linkID as linkID1_1_, tolinks0_.version as version1_1_, tolinks0_.toNode_nodeID as toNode5_1_1_, tolinks0_.fromNode_nodeID as fromNode6_1_1_, tolinks0_.name as name1_1_, tolinks0_.description as descript4_1_1_, node1_.nodeID as nodeID0_0_, node1_.version as version0_0_, node1_.lastUpdated as lastUpda4_0_0_, node1_.nodeName as nodeName0_0_, node1_.aliasName as aliasName0_0_, node1_.weight as weight0_0_, node1_.importance as importance0_0_ from Link tolinks0_ left outer join Node node1_ on tolinks0_.fromNode_nodeID=node1_.nodeID where tolinks0_.toNode_nodeID=?
  |   | 
  | 
  | the em.refresh call just causes the following query 
  | 
  | 
  |   | Hibernate: select node0_.nodeID as nodeID0_0_, node0_.version as version0_0_, node0_.lastUpdated as lastUpda4_0_0_, node0_.nodeName as nodeName0_0_, node0_.aliasName as aliasName0_0_, node0_.weight as weight0_0_, node0_.importance as importance0_0_ from Node node0_ where node0_.nodeID=?
  |   | 
  | 
  | thus the 'refresh' has just reinserted the link i just deleted remotely vian the nodeEAO.removeLink previously called.  Presumably because the uNode passed in to resynch was a pointer to the network originally peristed in step 1!
  | 
  | worse the yNode returned to main has no toLinks/fromLink Set attributes set at all - they come back null - i expected this to come back with a proxy set - though as its loaded lazily it would have errored with lazy initialisation fail.  However - this would fail with null pointer.  
  | 
  | Is this the expected behaviour for the code?  doesnt feel right.
  | 
  | 
  | 
  | 5  i then call the same function on my server (essentially a merge and refresh call) and get the following trace on the server 
  | 
  | 
  |   | 
  |   | 23:22:23,500 INFO  [STDOUT] Hibernate: select node0_.nodeID as nodeID73_2_, node0_.version as version73_2_, node0_.lastUpdated as lastUpda4_73_2_, node0_.nodeName as nodeName73_2_, node0_.aliasName as aliasName73_2_, node0_.weight as weight73_2_, node0_.importance as importance73_2_, node0_.firstName as firstName73_2_, node0_.middleName as middleName73_2_, node0_.lastName as lastName73_2_, node0_.nickName as nickName73_2_, node0_.dateOfBirth as dateOfB13_73_2_, node0_.dateOfDeath as dateOfD14_73_2_, node0_.sex as sex73_2_, node0_.nodeType as nodeType73_2_, fromlinks1_.fromNode_nodeID as fromNode5_4_, fromlinks1_.linkID as linkID4_, fromlinks1_.linkID as linkID70_0_, fromlinks1_.version as version70_0_, fromlinks1_.toNode_nodeID as toNode6_70_0_, fromlinks1_.fromNode_nodeID as fromNode5_70_0_, fromlinks1_.name as name70_0_, fromlinks1_.description as descript4_70_0_, node2_.nodeID as nodeID73_1_, node2_.version as version73_1_, node2_.lastUpdated as lastUpda4_73_1_, node2_.nodeName as nodeName73_1_, node2_.aliasName as aliasName73_1_, node2_.weight as weight73_1_, node2_.importance as importance73_1_, node2_.firstName as firstName73_1_, node2_.middleName as middleName73_1_, node2_.lastName as lastName73_1_, node2_.nickName as nickName73_1_, node2_.dateOfBirth as dateOfB13_73_1_, node2_.dateOfDeath as dateOfD14_73_1_, node2_.sex as sex73_1_, node2_.nodeType as nodeType73_1_ from Node node0_ left outer join Link fromlinks1_ on node0_.nodeID=fromlinks1_.fromNode_nodeID left outer join Node node2_ on fromlinks1_.toNode_nodeID=node2_.nodeID where node0_.nodeID=?
  |   | 23:22:23,530 INFO  [STDOUT] Hibernate: select link0_.linkID as linkID70_2_, link0_.version as version70_2_, link0_.toNode_nodeID as toNode6_70_2_, link0_.fromNode_nodeID as fromNode5_70_2_, link0_.name as name70_2_, link0_.description as descript4_70_2_, node1_.nodeID as nodeID73_0_, node1_.version as version73_0_, node1_.lastUpdated as lastUpda4_73_0_, node1_.nodeName as nodeName73_0_, node1_.aliasName as aliasName73_0_, node1_.weight as weight73_0_, node1_.importance as importance73_0_, node1_.firstName as firstName73_0_, node1_.middleName as middleName73_0_, node1_.lastName as lastName73_0_, node1_.nickName as nickName73_0_, node1_.dateOfBirth as dateOfB13_73_0_, node1_.dateOfDeath as dateOfD14_73_0_, node1_.sex as sex73_0_, node1_.nodeType as nodeType73_0_, fromlinks2_.fromNode_nodeID as fromNode5_4_, fromlinks2_.linkID as linkID4_, fromlinks2_.linkID as linkID70_1_, fromlinks2_.version as version70_1_, fromlinks2_.toNode_nodeID as toNode6_70_1_, fromlinks2_.fromNode_nodeID as fromNode5_70_1_, fromlinks2_.name as name70_1_, fromlinks2_.description as descript4_70_1_ from Link link0_ left outer join Node node1_ on link0_.toNode_nodeID=node1_.nodeID left outer join Link fromlinks2_ on node1_.nodeID=fromlinks2_.fromNode_nodeID where link0_.linkID=?
  |   | 23:22:23,530 INFO  [STDOUT] Hibernate: select fromlinks0_.fromNode_nodeID as fromNode5_2_, fromlinks0_.linkID as linkID2_, fromlinks0_.linkID as linkID70_1_, fromlinks0_.version as version70_1_, fromlinks0_.toNode_nodeID as toNode6_70_1_, fromlinks0_.fromNode_nodeID as fromNode5_70_1_, fromlinks0_.name as name70_1_, fromlinks0_.description as descript4_70_1_, node1_.nodeID as nodeID73_0_, node1_.version as version73_0_, node1_.lastUpdated as lastUpda4_73_0_, node1_.nodeName as nodeName73_0_, node1_.aliasName as aliasName73_0_, node1_.weight as weight73_0_, node1_.importance as importance73_0_, node1_.firstName as firstName73_0_, node1_.middleName as middleName73_0_, node1_.lastName as lastName73_0_, node1_.nickName as nickName73_0_, node1_.dateOfBirth as dateOfB13_73_0_, node1_.dateOfDeath as dateOfD14_73_0_, node1_.sex as sex73_0_, node1_.nodeType as nodeType73_0_ from Link fromlinks0_ left outer join Node node1_ on fromlinks0_.toNode_nodeID=node1_.nodeID where fromlinks0_.fromNode_nodeID=?
  |   | 23:22:23,530 INFO  [STDOUT] Hibernate: insert into Link (version, toNode_nodeID, fromNode_nodeID, name, description) values (?, ?, ?, ?, ?)
  |   | 23:22:23,540 INFO  [STDOUT] Hibernate: select fromlinks0_.fromNode_nodeID as fromNode5_2_, fromlinks0_.linkID as linkID2_, fromlinks0_.linkID as linkID70_1_, fromlinks0_.version as version70_1_, fromlinks0_.toNode_nodeID as toNode6_70_1_, fromlinks0_.fromNode_nodeID as fromNode5_70_1_, fromlinks0_.name as name70_1_, fromlinks0_.description as descript4_70_1_, node1_.nodeID as nodeID73_0_, node1_.version as version73_0_, node1_.lastUpdated as lastUpda4_73_0_, node1_.nodeName as nodeName73_0_, node1_.aliasName as aliasName73_0_, node1_.weight as weight73_0_, node1_.importance as importance73_0_, node1_.firstName as firstName73_0_, node1_.middleName as middleName73_0_, node1_.lastName as lastName73_0_, node1_.nickName as nickName73_0_, node1_.dateOfBirth as dateOfB13_73_0_, node1_.dateOfDeath as dateOfD14_73_0_, node1_.sex as sex73_0_, node1_.nodeType as nodeType73_0_ from Link fromlinks0_ left outer join Node node1_ on fromlinks0_.toNode_nodeID=node1_.nodeID where fromlinks0_.fromNode_nodeID=?
  |   | 23:22:23,540 INFO  [STDOUT] Hibernate: select tolinks0_.toNode_nodeID as toNode6_2_, tolinks0_.linkID as linkID2_, tolinks0_.linkID as linkID70_1_, tolinks0_.version as version70_1_, tolinks0_.toNode_nodeID as toNode6_70_1_, tolinks0_.fromNode_nodeID as fromNode5_70_1_, tolinks0_.name as name70_1_, tolinks0_.description as descript4_70_1_, node1_.nodeID as nodeID73_0_, node1_.version as version73_0_, node1_.lastUpdated as lastUpda4_73_0_, node1_.nodeName as nodeName73_0_, node1_.aliasName as aliasName73_0_, node1_.weight as weight73_0_, node1_.importance as importance73_0_, node1_.firstName as firstName73_0_, node1_.middleName as middleName73_0_, node1_.lastName as lastName73_0_, node1_.nickName as nickName73_0_, node1_.dateOfBirth as dateOfB13_73_0_, node1_.dateOfDeath as dateOfD14_73_0_, node1_.sex as sex73_0_, node1_.nodeType as nodeType73_0_ from Link tolinks0_ left outer join Node node1_ on tolinks0_.fromNode_nodeID=node1_.nodeID where tolinks0_.toNode_nodeID=?
  |   | 23:22:23,540 INFO  [STDOUT] Hibernate: select node0_.nodeID as nodeID73_0_, node0_.version as version73_0_, node0_.lastUpdated as lastUpda4_73_0_, node0_.nodeName as nodeName73_0_, node0_.aliasName as aliasName73_0_, node0_.weight as weight73_0_, node0_.importance as importance73_0_, node0_.firstName as firstName73_0_, node0_.middleName as middleName73_0_, node0_.lastName as lastName73_0_, node0_.nickName as nickName73_0_, node0_.dateOfBirth as dateOfB13_73_0_, node0_.dateOfDeath as dateOfD14_73_0_, node0_.sex as sex73_0_, node0_.nodeType as nodeType73_0_ from Node node0_ where node0_.nodeID=?
  |   | 23:22:23,800 WARN  [LoadContexts] fail-safe cleanup (collections) : org.hibernate.engine.loading.CollectionLoadContext at 137695c<rs=com.mysql.jdbc.ResultSet at 3d0d64>
  |   | 
  | 
  | this action inserts yet one more link into the links table - i now have three links and 3 nodes - the last two links appear to be the same i.e they both link node A to node C.
  | 
  | 7.  Lastly i call a query on the server to reuturn the number of nodes connected to my uNode (still pointing to original graph returned from the first persist action.
  | 
  | This query - forces a new Link to be created - god knows how.  I know have 4 links  the last three of which are the same and link A to C!
  | 
  | heres the trace.
  | 
  | 
  |   | 
  |   | 23:29:06,099 INFO  [STDOUT] Hibernate: select node0_.nodeID as nodeID73_2_, node0_.version as version73_2_, node0_.lastUpdated as lastUpda4_73_2_, node0_.nodeName as nodeName73_2_, node0_.aliasName as aliasName73_2_, node0_.weight as weight73_2_, node0_.importance as importance73_2_, node0_.firstName as firstName73_2_, node0_.middleName as middleName73_2_, node0_.lastName as lastName73_2_, node0_.nickName as nickName73_2_, node0_.dateOfBirth as dateOfB13_73_2_, node0_.dateOfDeath as dateOfD14_73_2_, node0_.sex as sex73_2_, node0_.nodeType as nodeType73_2_, fromlinks1_.fromNode_nodeID as fromNode5_4_, fromlinks1_.linkID as linkID4_, fromlinks1_.linkID as linkID70_0_, fromlinks1_.version as version70_0_, fromlinks1_.toNode_nodeID as toNode6_70_0_, fromlinks1_.fromNode_nodeID as fromNode5_70_0_, fromlinks1_.name as name70_0_, fromlinks1_.description as descript4_70_0_, node2_.nodeID as nodeID73_1_, node2_.version as version73_1_, node2_.lastUpdated as lastUpda4_73_1_, node2_.nodeName as nodeName73_1_, node2_.aliasName as aliasName73_1_, node2_.weight as weight73_1_, node2_.importance as importance73_1_, node2_.firstName as firstName73_1_, node2_.middleName as middleName73_1_, node2_.lastName as lastName73_1_, node2_.nickName as nickName73_1_, node2_.dateOfBirth as dateOfB13_73_1_, node2_.dateOfDeath as dateOfD14_73_1_, node2_.sex as sex73_1_, node2_.nodeType as nodeType73_1_ from Node node0_ left outer join Link fromlinks1_ on node0_.nodeID=fromlinks1_.fromNode_nodeID left outer join Node node2_ on fromlinks1_.toNode_nodeID=node2_.nodeID where node0_.nodeID=?
  |   | 23:29:06,129 INFO  [STDOUT] Hibernate: select link0_.linkID as linkID70_2_, link0_.version as version70_2_, link0_.toNode_nodeID as toNode6_70_2_, link0_.fromNode_nodeID as fromNode5_70_2_, link0_.name as name70_2_, link0_.description as descript4_70_2_, node1_.nodeID as nodeID73_0_, node1_.version as version73_0_, node1_.lastUpdated as lastUpda4_73_0_, node1_.nodeName as nodeName73_0_, node1_.aliasName as aliasName73_0_, node1_.weight as weight73_0_, node1_.importance as importance73_0_, node1_.firstName as firstName73_0_, node1_.middleName as middleName73_0_, node1_.lastName as lastName73_0_, node1_.nickName as nickName73_0_, node1_.dateOfBirth as dateOfB13_73_0_, node1_.dateOfDeath as dateOfD14_73_0_, node1_.sex as sex73_0_, node1_.nodeType as nodeType73_0_, fromlinks2_.fromNode_nodeID as fromNode5_4_, fromlinks2_.linkID as linkID4_, fromlinks2_.linkID as linkID70_1_, fromlinks2_.version as version70_1_, fromlinks2_.toNode_nodeID as toNode6_70_1_, fromlinks2_.fromNode_nodeID as fromNode5_70_1_, fromlinks2_.name as name70_1_, fromlinks2_.description as descript4_70_1_ from Link link0_ left outer join Node node1_ on link0_.toNode_nodeID=node1_.nodeID left outer join Link fromlinks2_ on node1_.nodeID=fromlinks2_.fromNode_nodeID where link0_.linkID=?
  |   | 23:29:06,129 INFO  [STDOUT] Hibernate: select fromlinks0_.fromNode_nodeID as fromNode5_2_, fromlinks0_.linkID as linkID2_, fromlinks0_.linkID as linkID70_1_, fromlinks0_.version as version70_1_, fromlinks0_.toNode_nodeID as toNode6_70_1_, fromlinks0_.fromNode_nodeID as fromNode5_70_1_, fromlinks0_.name as name70_1_, fromlinks0_.description as descript4_70_1_, node1_.nodeID as nodeID73_0_, node1_.version as version73_0_, node1_.lastUpdated as lastUpda4_73_0_, node1_.nodeName as nodeName73_0_, node1_.aliasName as aliasName73_0_, node1_.weight as weight73_0_, node1_.importance as importance73_0_, node1_.firstName as firstName73_0_, node1_.middleName as middleName73_0_, node1_.lastName as lastName73_0_, node1_.nickName as nickName73_0_, node1_.dateOfBirth as dateOfB13_73_0_, node1_.dateOfDeath as dateOfD14_73_0_, node1_.sex as sex73_0_, node1_.nodeType as nodeType73_0_ from Link fromlinks0_ left outer join Node node1_ on fromlinks0_.toNode_nodeID=node1_.nodeID where fromlinks0_.fromNode_nodeID=?
  |   | 23:29:06,139 INFO  [STDOUT] Hibernate: insert into Link (version, toNode_nodeID, fromNode_nodeID, name, description) values (?, ?, ?, ?, ?)
  |   | 23:29:06,139 INFO  [STDOUT] Hibernate: select fromlinks0_.fromNode_nodeID as fromNode5_2_, fromlinks0_.linkID as linkID2_, fromlinks0_.linkID as linkID70_1_, fromlinks0_.version as version70_1_, fromlinks0_.toNode_nodeID as toNode6_70_1_, fromlinks0_.fromNode_nodeID as fromNode5_70_1_, fromlinks0_.name as name70_1_, fromlinks0_.description as descript4_70_1_, node1_.nodeID as nodeID73_0_, node1_.version as version73_0_, node1_.lastUpdated as lastUpda4_73_0_, node1_.nodeName as nodeName73_0_, node1_.aliasName as aliasName73_0_, node1_.weight as weight73_0_, node1_.importance as importance73_0_, node1_.firstName as firstName73_0_, node1_.middleName as middleName73_0_, node1_.lastName as lastName73_0_, node1_.nickName as nickName73_0_, node1_.dateOfBirth as dateOfB13_73_0_, node1_.dateOfDeath as dateOfD14_73_0_, node1_.sex as sex73_0_, node1_.nodeType as nodeType73_0_ from Link fromlinks0_ left outer join Node node1_ on fromlinks0_.toNode_nodeID=node1_.nodeID where fromlinks0_.fromNode_nodeID=?
  |   | 23:29:06,139 INFO  [STDOUT] Hibernate: select tolinks0_.toNode_nodeID as toNode6_2_, tolinks0_.linkID as linkID2_, tolinks0_.linkID as linkID70_1_, tolinks0_.version as version70_1_, tolinks0_.toNode_nodeID as toNode6_70_1_, tolinks0_.fromNode_nodeID as fromNode5_70_1_, tolinks0_.name as name70_1_, tolinks0_.description as descript4_70_1_, node1_.nodeID as nodeID73_0_, node1_.version as version73_0_, node1_.lastUpdated as lastUpda4_73_0_, node1_.nodeName as nodeName73_0_, node1_.aliasName as aliasName73_0_, node1_.weight as weight73_0_, node1_.importance as importance73_0_, node1_.firstName as firstName73_0_, node1_.middleName as middleName73_0_, node1_.lastName as lastName73_0_, node1_.nickName as nickName73_0_, node1_.dateOfBirth as dateOfB13_73_0_, node1_.dateOfDeath as dateOfD14_73_0_, node1_.sex as sex73_0_, node1_.nodeType as nodeType73_0_ from Link tolinks0_ left outer join Node node1_ on tolinks0_.fromNode_nodeID=node1_.nodeID where tolinks0_.toNode_nodeID=?
  |   | 23:29:06,149 INFO  [STDOUT] Hibernate: select node0_.nodeID as nodeID73_0_, node0_.version as version73_0_, node0_.lastUpdated as lastUpda4_73_0_, node0_.nodeName as nodeName73_0_, node0_.aliasName as aliasName73_0_, node0_.weight as weight73_0_, node0_.importance as importance73_0_, node0_.firstName as firstName73_0_, node0_.middleName as middleName73_0_, node0_.lastName as lastName73_0_, node0_.nickName as nickName73_0_, node0_.dateOfBirth as dateOfB13_73_0_, node0_.dateOfDeath as dateOfD14_73_0_, node0_.sex as sex73_0_, node0_.nodeType as nodeType73_0_ from Node node0_ where node0_.nodeID=?
  |   | 23:29:06,149 INFO  [STDOUT] Hibernate: select node1_.nodeID as nodeID73_, node1_.version as version73_, node1_.lastUpdated as lastUpda4_73_, node1_.nodeName as nodeName73_, node1_.aliasName as aliasName73_, node1_.weight as weight73_, node1_.importance as importance73_, node1_.firstName as firstName73_, node1_.middleName as middleName73_, node1_.lastName as lastName73_, node1_.nickName as nickName73_, node1_.dateOfBirth as dateOfB13_73_, node1_.dateOfDeath as dateOfD14_73_, node1_.sex as sex73_, node1_.nodeType as nodeType73_ from Link link0_ inner join Node node1_ on link0_.toNode_nodeID=node1_.nodeID where link0_.fromNode_nodeID=?
  |   | 23:29:06,189 WARN  [LoadContexts] fail-safe cleanup (collections) : org.hibernate.engine.loading.CollectionLoadContext at acca00<rs=com.mysql.jdbc.ResultSet at 5babce>
  |   | 
  | 
  | heres the server based method that calls the query 
  | 
  | 
  |   | 	@TransactionAttribute (TransactionAttributeType.REQUIRED)
  |   | 	public List<Node> getConnectedToNodes (Node fromNode)
  |   | 	{
  |   | 		Logger log = Logger.getLogger("NodeEAOBean");
  |   | 		log.setLevel(org.apache.log4j.Level.DEBUG);
  |   | 
  |   | 		if (fromNode == null )
  |   | 		{
  |   | 			log.error("was passed a null reference");
  |   | 			return null;
  |   | 		}
  |   | 
  |   | 		fromNode = this.refresh(fromNode);
  |   | 		Query q = em.createNamedQuery("getLinkedNodes");
  |   | 		q.setParameter("fromNode", fromNode);
  |   | 		
  |   | 		return (List<Node>)q.getResultList();
  |   | 
  |   | 	}
  |   | 
  | 
  | the this.refresh - calls a merge and fresh on the EM - presumably this somehow triggered the new insert.
  | 
  | So there you have it - I am somewhat confused and lost here.
  | 
  | - turning on versioning gets the optimistic  lock exception as the version seen from the server is not aligned and passed back to the client.
  | 
  | if i turn versioing off - it doesnt error just does weird things and creates two many links in the db when i try to resyn locally (or remotely).
  | 
  | Can you help me unravel what I am doing wrong in my thinking and get myself back on track!   
  | 
  | I'd swear so far that the overhead in getting my head round this has cost me more than the hack out a bit of sql you'd have written in olden days ..
  | 
  | Aaarg.
  | 
  | 
  |  

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4119855#4119855

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4119855




More information about the jboss-user mailing list