public void Merge()
		{
			using (ISession session = base.OpenSession())
			using (ITransaction transaction = session.BeginTransaction())
			{
				Route route = new Route();
				route.Name = "routeA";
				session.Save(route);
				transaction.Commit();
			}
	
			using (ISession session = base.OpenSession())
			using (ITransaction transaction = session.BeginTransaction())
			{
				Route route = session.Get<Route>(1L);
				route.TransientField = "sfnaouisrbn";
		
				Tour tour = new Tour();
				tour.Name = "tourB";
		
				Node pickupNode = new Node();
				pickupNode.Name = "pickupNodeB";
		
				Node deliveryNode = new Node();
				deliveryNode.Name = "deliveryNodeB";
		
				pickupNode.Route = route;
				pickupNode.Tour = tour;
				pickupNode.TransientField = "pickup node aaaaaaaaaaa";
		
				deliveryNode.Route = route;
				deliveryNode.Tour = tour;
				deliveryNode.TransientField = "delivery node aaaaaaaaa";
		
				tour.Nodes.Add(pickupNode);
				tour.Nodes.Add(deliveryNode);
		
				route.Nodes.Add(pickupNode);
				route.Nodes.Add(deliveryNode);
		
				Route mergedRoute = (Route)session.Merge(route);
	
				transaction.Commit();
			}
		}
		public void MergeEntityWithNonNullableTransientEntity()
		{
			Route route = this.GetUpdatedDetachedEntity();
	
			Node node = route.Nodes.First();
			route.Nodes.Remove(node);
	
			Route routeNew = new Route();
			routeNew.Name = "new route";
			routeNew.Nodes.Add(node);
			node.Route = routeNew;
	
			using (ISession session = base.OpenSession())
			using (ITransaction transaction = session.BeginTransaction())
			{
				try
				{
					session.Merge(node);
					Assert.Fail("should have thrown an exception");
				}
				catch (Exception ex)
				{
					Assert.That(ex, Is.TypeOf(typeof(TransientObjectException)));
					
//					if (((SessionImplementor)session).Factory.Settings.isCheckNullability() ) {
//						assertTrue( ex instanceof TransientObjectException );
//					}
//					else {
//						assertTrue( ex instanceof JDBCException );
//					}
				}
				finally
				{
					transaction.Rollback();
				}
			}
		}
		public void MergeTransientChildBeforeTransientParent()
		{
			Route route = null;
			
			using (ISession session = base.OpenSession())
			using (ITransaction transaction = session.BeginTransaction())
			{
				route = new Route();
				route.Name = "routeA";
				session.Save(route);
				transaction.Commit();
			}
	
			using (ISession session = base.OpenSession())
			using (ITransaction transaction = session.BeginTransaction())
			{
				route = session.Get<Route>(route.RouteId);
				route.TransientField = "sfnaouisrbn";
		
				Tour tour = new Tour();
				tour.Name = "tourB";
		
				Transport transport = new Transport();
				transport.Name = "transportB";
		
				Node pickupNode = new Node();
				pickupNode.Name = "pickupNodeB";
		
				Node deliveryNode = new Node();
				deliveryNode.Name = "deliveryNodeB";
		
				Vehicle vehicle = new Vehicle();
				vehicle.Name = "vehicleB";
		
				pickupNode.Route = route;
				pickupNode.Tour = tour;
				pickupNode.PickupTransports.Add(transport);
				pickupNode.TransientField = "pickup node aaaaaaaaaaa";
		
				deliveryNode.Route = route;
				deliveryNode.Tour = tour;
				deliveryNode.DeliveryTransports.Add(transport);
				deliveryNode.TransientField = "delivery node aaaaaaaaa";
		
				tour.Nodes.Add(pickupNode);
				tour.Nodes.Add(deliveryNode);
		
				route.Nodes.Add(pickupNode);
				route.Nodes.Add(deliveryNode);
				route.Vehicles.Add(vehicle);
		
				transport.PickupNode = pickupNode;
				transport.DeliveryNode = deliveryNode;
				transport.Vehicle = vehicle;
				transport.TransientField = "aaaaaaaaaaaaaa";
		
				vehicle.Transports.Add(transport);
				vehicle.TransientField = "anewvalue";
				vehicle.Route = route;
		
				Route mergedRoute = (Route)session.Merge(route);
		
				transaction.Commit();
			}
		}
		public void MergeData3Nodes()
		{
			Route route = null;
			
			using (ISession session = base.OpenSession())
			using (ITransaction transaction = session.BeginTransaction())
			{
				route = new Route();
				route.Name = "routeA";
				session.Save(route);
				transaction.Commit();
			}
	
			using (ISession session = base.OpenSession())
			using (ITransaction transaction = session.BeginTransaction())
			{
				route = session.Get<Route>(route.RouteId);
				route.TransientField = "sfnaouisrbn";
		
				Tour tour = new Tour();
				tour.Name = "tourB";
		
				Transport transport1 = new Transport();
				transport1.Name = "TRANSPORT1";
		
				Transport transport2 = new Transport();
				transport2.Name = "TRANSPORT2";
		
				Node node1 = new Node();
				node1.Name = "NODE1";
		
				Node node2 = new Node();
				node2.Name = "NODE2";
		
				Node node3 = new Node();
				node3.Name = "NODE3";
		
				Vehicle vehicle = new Vehicle();
				vehicle.Name = "vehicleB";
		
				node1.Route = route;
				node1.Tour = tour;
				node1.PickupTransports.Add(transport1);
				node1.TransientField = "node 1";
		
				node2.Route = route;
				node2.Tour = tour;
				node2.DeliveryTransports.Add(transport1);
				node2.PickupTransports.Add(transport2);
				node2.TransientField = "node 2";
		
				node3.Route = route;
				node3.Tour = tour;
				node3.DeliveryTransports.Add(transport2);
				node3.TransientField = "node 3";
		
				tour.Nodes.Add(node1);
				tour.Nodes.Add(node2);
				tour.Nodes.Add(node3);
		
				route.Nodes.Add(node1);
				route.Nodes.Add(node2);
				route.Nodes.Add(node3);
				route.Vehicles.Add(vehicle);
		
				transport1.PickupNode = node1;
				transport1.DeliveryNode = node2;
				transport1.Vehicle = vehicle;
				transport1.TransientField = "aaaaaaaaaaaaaa";
		
				transport2.PickupNode = node2;
				transport2.DeliveryNode = node3;
				transport2.Vehicle = vehicle;
				transport2.TransientField = "bbbbbbbbbbbbb";
		
				vehicle.Transports.Add(transport1);
				vehicle.Transports.Add(transport2);
				vehicle.TransientField = "anewvalue";
				vehicle.Route = route;
		
				Route mergedRoute = (Route)session.Merge(route);
	
				transaction.Commit();
			}
		}
		private void CheckResults(Route route, bool isRouteUpdated)
		{
			// since merge is not cascaded to route, this method needs to
			// know whether route is expected to be updated
			if (isRouteUpdated)
			{
				Assert.That(route.Name, Is.EqualTo("new routeA"));
			}
			
			Assert.That(route.Nodes.Count, Is.EqualTo(2));
			Node deliveryNode = null;
			Node pickupNode = null;
			
			foreach(Node node in route.Nodes)
			{
				if ("deliveryNodeB".Equals(node.Name))
				{
					deliveryNode = node;
				}
				else if ("pickupNodeB".Equals(node.Name))
				{
					pickupNode = node;
				}
				else
				{
					Assert.Fail("unknown node");
				}
			}

			Assert.That(deliveryNode, Is.Not.Null);
			Assert.That(deliveryNode.Route, Is.SameAs(route));
			Assert.That(deliveryNode.DeliveryTransports.Count, Is.EqualTo(1));
			Assert.That(deliveryNode.PickupTransports.Count, Is.EqualTo(0));
			Assert.That(deliveryNode.Tour, Is.Not.Null);
			Assert.That(deliveryNode.TransientField, Is.EqualTo("node original value"));
	
			Assert.That(pickupNode, Is.Not.Null);
			Assert.That(pickupNode.Route, Is.SameAs(route));
			Assert.That(pickupNode.DeliveryTransports.Count, Is.EqualTo(0));
			Assert.That(pickupNode.PickupTransports.Count, Is.EqualTo(1));
			Assert.That(pickupNode.Tour, Is.Not.Null);
			Assert.That(pickupNode.TransientField, Is.EqualTo("node original value"));
	
			Assert.That(deliveryNode.NodeId.Equals(pickupNode.NodeId), Is.False);
			Assert.That(deliveryNode.Tour, Is.SameAs(pickupNode.Tour));
			Assert.That(deliveryNode.DeliveryTransports.First(), Is.SameAs(pickupNode.PickupTransports.First()));
	
			Tour tour = deliveryNode.Tour;
			Transport transport = deliveryNode.DeliveryTransports.First();
	
			Assert.That(tour.Name, Is.EqualTo("tourB"));
			Assert.That(tour.Nodes.Count, Is.EqualTo(2));
			Assert.That(tour.Nodes.Contains(deliveryNode), Is.True);
			Assert.That(tour.Nodes.Contains(pickupNode), Is.True);
	
			Assert.That(transport.Name, Is.EqualTo("transportB"));
			Assert.That(transport.DeliveryNode, Is.SameAs(deliveryNode));
			Assert.That(transport.PickupNode, Is.SameAs(pickupNode));
			Assert.That(transport.TransientField, Is.EqualTo("transport original value"));
		}
		private Route GetUpdatedDetachedEntity()
		{
			ISession s = OpenSession();
			s.BeginTransaction();
	
			Route route = new Route();
			route.Name = "routeA";
	
			s.Save(route);
			s.Transaction.Commit();
			s.Close();
	
			route.Name = "new routeA";
			route.TransientField = "sfnaouisrbn";
	
			Tour tour = new Tour();
			tour.Name = "tourB";
	
			Transport transport = new Transport();
			transport.Name = "transportB";
	
			Node pickupNode = new Node();
			pickupNode.Name = "pickupNodeB";
	
			Node deliveryNode = new Node();
			deliveryNode.Name = "deliveryNodeB";
	
			pickupNode.Route = route;
			pickupNode.Tour = tour;
			pickupNode.PickupTransports.Add(transport);
			pickupNode.TransientField = "pickup node aaaaaaaaaaa";
	
			deliveryNode.Route = route;
			deliveryNode.Tour = tour;
			deliveryNode.DeliveryTransports.Add(transport);
			deliveryNode.TransientField = "delivery node aaaaaaaaa";
	
			tour.Nodes.Add(pickupNode);
			tour.Nodes.Add(deliveryNode);
	
			route.Nodes.Add(pickupNode);
			route.Nodes.Add(deliveryNode);
	
			transport.PickupNode = pickupNode;
			transport.DeliveryNode = deliveryNode;
			transport.TransientField = "aaaaaaaaaaaaaa";
	
			return route;
		}
        public async Task MergeData3NodesAsync()
        {
            Route route = null;

            using (ISession session = base.OpenSession())
                using (ITransaction transaction = session.BeginTransaction())
                {
                    route      = new Route();
                    route.Name = "routeA";
                    await(session.SaveAsync(route));
                    await(transaction.CommitAsync());
                }

            using (ISession session = base.OpenSession())
                using (ITransaction transaction = session.BeginTransaction())
                {
                    route = await(session.GetAsync <Route>(route.RouteId));
                    route.TransientField = "sfnaouisrbn";

                    Tour tour = new Tour();
                    tour.Name = "tourB";

                    Transport transport1 = new Transport();
                    transport1.Name = "TRANSPORT1";

                    Transport transport2 = new Transport();
                    transport2.Name = "TRANSPORT2";

                    Node node1 = new Node();
                    node1.Name = "NODE1";

                    Node node2 = new Node();
                    node2.Name = "NODE2";

                    Node node3 = new Node();
                    node3.Name = "NODE3";

                    Vehicle vehicle = new Vehicle();
                    vehicle.Name = "vehicleB";

                    node1.Route = route;
                    node1.Tour  = tour;
                    node1.PickupTransports.Add(transport1);
                    node1.TransientField = "node 1";

                    node2.Route = route;
                    node2.Tour  = tour;
                    node2.DeliveryTransports.Add(transport1);
                    node2.PickupTransports.Add(transport2);
                    node2.TransientField = "node 2";

                    node3.Route = route;
                    node3.Tour  = tour;
                    node3.DeliveryTransports.Add(transport2);
                    node3.TransientField = "node 3";

                    tour.Nodes.Add(node1);
                    tour.Nodes.Add(node2);
                    tour.Nodes.Add(node3);

                    route.Nodes.Add(node1);
                    route.Nodes.Add(node2);
                    route.Nodes.Add(node3);
                    route.Vehicles.Add(vehicle);

                    transport1.PickupNode     = node1;
                    transport1.DeliveryNode   = node2;
                    transport1.Vehicle        = vehicle;
                    transport1.TransientField = "aaaaaaaaaaaaaa";

                    transport2.PickupNode     = node2;
                    transport2.DeliveryNode   = node3;
                    transport2.Vehicle        = vehicle;
                    transport2.TransientField = "bbbbbbbbbbbbb";

                    vehicle.Transports.Add(transport1);
                    vehicle.Transports.Add(transport2);
                    vehicle.TransientField = "anewvalue";
                    vehicle.Route          = route;

                    Route mergedRoute = (Route)await(session.MergeAsync(route));

                    await(transaction.CommitAsync());
                }
        }
        public async Task MergeTransientChildBeforeTransientParentAsync()
        {
            Route route = null;

            using (ISession session = base.OpenSession())
                using (ITransaction transaction = session.BeginTransaction())
                {
                    route      = new Route();
                    route.Name = "routeA";
                    await(session.SaveAsync(route));
                    await(transaction.CommitAsync());
                }

            using (ISession session = base.OpenSession())
                using (ITransaction transaction = session.BeginTransaction())
                {
                    route = await(session.GetAsync <Route>(route.RouteId));
                    route.TransientField = "sfnaouisrbn";

                    Tour tour = new Tour();
                    tour.Name = "tourB";

                    Transport transport = new Transport();
                    transport.Name = "transportB";

                    Node pickupNode = new Node();
                    pickupNode.Name = "pickupNodeB";

                    Node deliveryNode = new Node();
                    deliveryNode.Name = "deliveryNodeB";

                    Vehicle vehicle = new Vehicle();
                    vehicle.Name = "vehicleB";

                    pickupNode.Route = route;
                    pickupNode.Tour  = tour;
                    pickupNode.PickupTransports.Add(transport);
                    pickupNode.TransientField = "pickup node aaaaaaaaaaa";

                    deliveryNode.Route = route;
                    deliveryNode.Tour  = tour;
                    deliveryNode.DeliveryTransports.Add(transport);
                    deliveryNode.TransientField = "delivery node aaaaaaaaa";

                    tour.Nodes.Add(pickupNode);
                    tour.Nodes.Add(deliveryNode);

                    route.Nodes.Add(pickupNode);
                    route.Nodes.Add(deliveryNode);
                    route.Vehicles.Add(vehicle);

                    transport.PickupNode     = pickupNode;
                    transport.DeliveryNode   = deliveryNode;
                    transport.Vehicle        = vehicle;
                    transport.TransientField = "aaaaaaaaaaaaaa";

                    vehicle.Transports.Add(transport);
                    vehicle.TransientField = "anewvalue";
                    vehicle.Route          = route;

                    Route mergedRoute = (Route)await(session.MergeAsync(route));

                    await(transaction.CommitAsync());
                }
        }