|
From: <fab...@us...> - 2008-08-15 05:37:39
|
Revision: 3704
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=3704&view=rev
Author: fabiomaulo
Date: 2008-08-15 05:37:47 +0000 (Fri, 15 Aug 2008)
Log Message:
-----------
- Ported test for composite-id from H3.2
- Aligned constraint for "join fetch", using <bag>, between HQL and Criteria (removed NH different behavior in BasicLoader)
- Changed NH846 according the "new" behavior (the type of the collection was not the matter of the test)
Possible Breaking change:
- The alignment of constraint should break some Criteria
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Hql/Classic/QueryTranslator.cs
trunk/nhibernate/src/NHibernate/Loader/BasicLoader.cs
trunk/nhibernate/src/NHibernate.Test/MultipleCollectionFetchTest/MultipleBagFetchFixture.cs
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH826/Entities.cs
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH826/Fixture.cs
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH826/Mappings.hbm.xml
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test-2.0.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate.Test/CompositeId/CompositeIdFixture.cs
trunk/nhibernate/src/NHibernate.Test/CompositeId/Customer.cs
trunk/nhibernate/src/NHibernate.Test/CompositeId/Customer.hbm.xml
trunk/nhibernate/src/NHibernate.Test/CompositeId/LineItem.cs
trunk/nhibernate/src/NHibernate.Test/CompositeId/LineItem.hbm.xml
trunk/nhibernate/src/NHibernate.Test/CompositeId/Order.cs
trunk/nhibernate/src/NHibernate.Test/CompositeId/Order.hbm.xml
trunk/nhibernate/src/NHibernate.Test/CompositeId/Product.cs
trunk/nhibernate/src/NHibernate.Test/CompositeId/Product.hbm.xml
Modified: trunk/nhibernate/src/NHibernate/Hql/Classic/QueryTranslator.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Hql/Classic/QueryTranslator.cs 2008-08-14 17:33:32 UTC (rev 3703)
+++ trunk/nhibernate/src/NHibernate/Hql/Classic/QueryTranslator.cs 2008-08-15 05:37:47 UTC (rev 3704)
@@ -117,11 +117,14 @@
hasUnsafeCollection = hasUnsafeCollection || IsUnsafe(collectionPersister);
- if (count > 1 && hasUnsafeCollection)
- {
- // The comment only mentions a bag since I don't want to confuse users.
- throw new QueryException("Cannot fetch multiple collections in a single query if one of them is a bag");
- }
+ // NH : This constraint is present in BasicLoader.PostInstantiate
+ // The constraint here break some tests ported from H3.2
+ // where is possible the use of "left join fetch"
+ //if (count > 1 && hasUnsafeCollection)
+ //{
+ // // The comment only mentions a bag since I don't want to confuse users.
+ // throw new QueryException("Cannot fetch multiple collections in a single query if one of them is a bag");
+ //}
names.Add(name);
persisters.Add(collectionPersister);
Modified: trunk/nhibernate/src/NHibernate/Loader/BasicLoader.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Loader/BasicLoader.cs 2008-08-14 17:33:32 UTC (rev 3703)
+++ trunk/nhibernate/src/NHibernate/Loader/BasicLoader.cs 2008-08-15 05:37:47 UTC (rev 3704)
@@ -57,11 +57,13 @@
{
collectionDescriptors = null;
}
- // NH Different behavior
- //if (bagCount > 1)
- //{
- // throw new HibernateException("cannot simultaneously fetch multiple bags");
- //}
+ // H3.2 : 14.3. Associations and joins
+ // Join fetching multiple collection roles also sometimes gives unexpected results for bag mappings,
+ // so be careful about how you formulate your queries in this case
+ if (bagCount > 1)
+ {
+ throw new QueryException("Cannot simultaneously fetch multiple bags.");
+ }
}
private static bool IsBag(ICollectionPersister collectionPersister)
Added: trunk/nhibernate/src/NHibernate.Test/CompositeId/CompositeIdFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/CompositeId/CompositeIdFixture.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/CompositeId/CompositeIdFixture.cs 2008-08-15 05:37:47 UTC (rev 3704)
@@ -0,0 +1,283 @@
+using System;
+using System.Collections;
+using NUnit.Framework;
+
+namespace NHibernate.Test.CompositeId
+{
+ [TestFixture]
+ public class CompositeIdFixture : TestCase
+ {
+ protected override string MappingsAssembly
+ {
+ get { return "NHibernate.Test"; }
+ }
+
+ protected override IList Mappings
+ {
+ get
+ {
+ return new string[]
+ {
+ "CompositeId.Customer.hbm.xml", "CompositeId.Order.hbm.xml", "CompositeId.LineItem.hbm.xml",
+ "CompositeId.Product.hbm.xml"
+ };
+ }
+ }
+
+ protected override string CacheConcurrencyStrategy
+ {
+ get { return null; }
+ }
+
+ [Test]
+ public void CompositeIds()
+ {
+ ISession s;
+ ITransaction t;
+ Product p2;
+ using (s = OpenSession())
+ {
+ t = s.BeginTransaction();
+
+ Product p = new Product();
+ p.ProductId = "A123";
+ p.Description = "nipple ring";
+ p.Price = 1.0m;
+ p.NumberAvailable = 1004;
+ s.Persist(p);
+
+ p2 = new Product();
+ p2.ProductId = "X525";
+ p2.Description = "nose stud";
+ p2.Price = 3.0m;
+ p2.NumberAvailable = 105;
+ s.Persist(p2);
+
+ Customer c = new Customer();
+ c.Address = "St Kilda Rd, MEL, 3000";
+ c.Name = "Virginia";
+ c.CustomerId = "C111";
+ s.Persist(c);
+
+ Order o = new Order(c);
+ o.OrderDate = DateTime.Today;
+ LineItem li = new LineItem(o, p);
+ li.Quantity = 2;
+
+ t.Commit();
+ }
+
+ using (s = OpenSession())
+ {
+ t = s.BeginTransaction();
+ Order o = s.Get<Order>(new Order.ID("C111", 0));
+ Assert.That(o.Total == 2m);
+ t.Commit();
+ }
+
+ using(s = OpenSession())
+ {
+ t = s.BeginTransaction();
+ s.CreateQuery(
+ "from Customer c left join fetch c.Orders o left join fetch o.LineItems li left join fetch li.Product p").List();
+ t.Commit();
+ }
+
+ using(s = OpenSession())
+ {
+ t = s.BeginTransaction();
+ s.CreateQuery("from Order o left join fetch o.LineItems li left join fetch li.Product p").List();
+ t.Commit();
+ }
+
+ using(s = OpenSession())
+ {
+ t = s.BeginTransaction();
+ IEnumerable iter = s.CreateQuery("select o.id, li.id from Order o join o.LineItems li").List();
+ foreach (object[] stuff in iter)
+ {
+ Assert.AreEqual(2, stuff.Length);
+ }
+ iter = s.CreateQuery("from Order o join o.LineItems li").Enumerable();
+ foreach (object[] stuff in iter)
+ {
+ Assert.AreEqual(2, stuff.Length);
+ }
+ t.Commit();
+ }
+
+ using(s = OpenSession())
+ {
+ t = s.BeginTransaction();
+ Customer c = s.Get<Customer>("C111");
+ Order o2 = new Order(c);
+ o2.OrderDate = DateTime.Today;
+ s.Flush();
+ LineItem li2 = new LineItem(o2, p2);
+ li2.Quantity = 5;
+ IList bigOrders = s.CreateQuery("from Order o where o.Total>10.0").List();
+ Assert.AreEqual(1, bigOrders.Count);
+ t.Commit();
+ }
+
+
+ using (s = OpenSession())
+ {
+ t = s.BeginTransaction();
+ s.Delete("from LineItem");
+ s.Delete("from Order");
+ s.Delete("from Customer");
+ s.Delete("from Product");
+ t.Commit();
+ }
+ }
+
+ [Test]
+ public void MultipleCollectionFetch()
+ {
+ ISession s = OpenSession();
+ ITransaction t = s.BeginTransaction();
+ Product p = new Product();
+ p.ProductId = "A123";
+ p.Description = "nipple ring";
+ p.Price = 1.0m;
+ p.NumberAvailable = 1004;
+ s.Persist(p);
+
+ Product p2 = new Product();
+ p2.ProductId = "X525";
+ p2.Description = "nose stud";
+ p2.Price = 3.0m;
+ p2.NumberAvailable = 105;
+ s.Persist(p2);
+
+ Customer c = new Customer();
+ c.Address = "St Kilda Rd, MEL, 3000";
+ c.Name = "Virginia";
+ c.CustomerId = "C111";
+ s.Persist(c);
+
+ Order o = new Order(c);
+ o.OrderDate = DateTime.Today;
+ LineItem li = new LineItem(o, p);
+ li.Quantity = 2;
+ LineItem li2 = new LineItem(o, p2);
+ li2.Quantity = 3;
+
+ Order o2 = new Order(c);
+ o2.OrderDate = DateTime.Today;
+ LineItem li3 = new LineItem(o2, p);
+ li3.Quantity = 1;
+ LineItem li4 = new LineItem(o2, p2);
+ li4.Quantity = 1;
+
+ t.Commit();
+ s.Close();
+
+ s = OpenSession();
+ t = s.BeginTransaction();
+ c =
+ (Customer)
+ s.CreateQuery(
+ "from Customer c left join fetch c.Orders o left join fetch o.LineItems li left join fetch li.Product p").
+ UniqueResult();
+ Assert.IsTrue(NHibernateUtil.IsInitialized(c.Orders));
+ Assert.AreEqual(2, c.Orders.Count);
+ Assert.IsTrue(NHibernateUtil.IsInitialized(((Order) c.Orders[0]).LineItems));
+ Assert.IsTrue(NHibernateUtil.IsInitialized(((Order) c.Orders[1]).LineItems));
+ Assert.AreEqual(((Order) c.Orders[0]).LineItems.Count, 2);
+ Assert.AreEqual(((Order) c.Orders[1]).LineItems.Count, 2);
+ t.Commit();
+ s.Close();
+
+ s = OpenSession();
+ t = s.BeginTransaction();
+ s.Delete("from LineItem");
+ s.Delete("from Order");
+ s.Delete("from Customer");
+ s.Delete("from Product");
+ t.Commit();
+ s.Close();
+ }
+
+ [Test]
+ public void NonLazyFetch()
+ {
+ ISession s = OpenSession();
+ ITransaction t = s.BeginTransaction();
+ Product p = new Product();
+ p.ProductId = "A123";
+ p.Description = "nipple ring";
+ p.Price = 1.0m;
+ p.NumberAvailable = 1004;
+ s.Persist(p);
+
+ Product p2 = new Product();
+ p2.ProductId = "X525";
+ p2.Description = "nose stud";
+ p2.Price = 3.0m;
+ p2.NumberAvailable = 105;
+ s.Persist(p2);
+
+ Customer c = new Customer();
+ c.Address = "St Kilda Rd, MEL, 3000";
+ c.Name = "Virginia";
+ c.CustomerId = "C111";
+ s.Persist(c);
+
+ Order o = new Order(c);
+ o.OrderDate = DateTime.Today;
+ LineItem li = new LineItem(o, p);
+ li.Quantity = 2;
+
+ t.Commit();
+ s.Close();
+
+ s = OpenSession();
+ t = s.BeginTransaction();
+ o = s.Get<Order>(new Order.ID("C111", 0));
+ Assert.AreEqual(2m, o.Total);
+ t.Commit();
+ s.Close();
+
+ s = OpenSession();
+ t = s.BeginTransaction();
+ o = (Order) s.CreateQuery("from Order o left join fetch o.LineItems li left join fetch li.Product p").UniqueResult();
+ Assert.IsTrue(NHibernateUtil.IsInitialized(o.LineItems));
+ li = (LineItem) o.LineItems[0];
+ Assert.IsTrue(NHibernateUtil.IsInitialized(li));
+ Assert.IsTrue(NHibernateUtil.IsInitialized(li.Product));
+ t.Commit();
+ s.Close();
+
+ s = OpenSession();
+ t = s.BeginTransaction();
+ o = (Order) s.CreateQuery("from Order o").UniqueResult();
+ Assert.IsTrue(NHibernateUtil.IsInitialized(o.LineItems));
+ li = (LineItem) o.LineItems[0];
+ Assert.IsTrue(NHibernateUtil.IsInitialized(li));
+ Assert.IsFalse(NHibernateUtil.IsInitialized(li.Product));
+ t.Commit();
+ s.Close();
+
+ s = OpenSession();
+ t = s.BeginTransaction();
+ s.Delete("from LineItem");
+ s.Delete("from Order");
+ s.Delete("from Customer");
+ s.Delete("from Product");
+ t.Commit();
+ s.Close();
+ }
+
+ [Test]
+ public void Query()
+ {
+ ISession s = OpenSession();
+ ITransaction t = s.BeginTransaction();
+ s.CreateQuery("from LineItem ol where ol.Order.Id.CustomerId = 'C111'").List();
+ t.Commit();
+ s.Close();
+ }
+ }
+}
\ No newline at end of file
Added: trunk/nhibernate/src/NHibernate.Test/CompositeId/Customer.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/CompositeId/Customer.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/CompositeId/Customer.cs 2008-08-15 05:37:47 UTC (rev 3704)
@@ -0,0 +1,46 @@
+using System.Collections;
+using System;
+
+namespace NHibernate.Test.CompositeId
+{
+ public class Customer
+ {
+ private string customerId;
+ private string name;
+ private string address;
+ private IList orders = new ArrayList();
+
+ public virtual string CustomerId
+ {
+ get { return customerId; }
+ set { customerId = value; }
+ }
+
+ public virtual string Name
+ {
+ get { return name; }
+ set { name = value; }
+ }
+
+ public virtual string Address
+ {
+ get { return address; }
+ set { address = value; }
+ }
+
+ public virtual IList Orders
+ {
+ get { return orders; }
+ set { orders = value; }
+ }
+
+ public virtual Order GenerateNewOrder(decimal total)
+ {
+ Order order = new Order(this);
+ order.OrderDate = DateTime.Today;
+ order.Total=total;
+
+ return order;
+ }
+ }
+}
\ No newline at end of file
Added: trunk/nhibernate/src/NHibernate.Test/CompositeId/Customer.hbm.xml
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/CompositeId/Customer.hbm.xml (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/CompositeId/Customer.hbm.xml 2008-08-15 05:37:47 UTC (rev 3704)
@@ -0,0 +1,33 @@
+<?xml version="1.0"?>
+<!--
+
+ This mapping demonstrates how to map a collection
+ <key> to one of the primary key columns of an
+ associated child class with a composite key. This
+ is very useful for legacy data!
+
+-->
+
+<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
+ namespace="NHibernate.Test.CompositeId"
+ assembly="NHibernate.Test"
+ default-access="field.camelcase">
+
+ <class name="Customer">
+
+ <id name="CustomerId"
+ length="10">
+ <generator class="assigned"/>
+ </id>
+
+ <property name="Name" not-null="true" length="100"/>
+ <property name="Address" not-null="true" length="200"/>
+
+ <list name="Orders" inverse="true" cascade="save-update">
+ <key column="customerId"/>
+ <index column="orderNumber"/>
+ <one-to-many class="Order"/>
+ </list>
+ </class>
+
+</hibernate-mapping>
Added: trunk/nhibernate/src/NHibernate.Test/CompositeId/LineItem.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/CompositeId/LineItem.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/CompositeId/LineItem.cs 2008-08-15 05:37:47 UTC (rev 3704)
@@ -0,0 +1,92 @@
+namespace NHibernate.Test.CompositeId
+{
+ public class LineItem
+ {
+ public class ID
+ {
+ private string customerId;
+ private int orderNumber;
+ private string productId;
+ public ID() {}
+ public ID(string customerId, int orderNumber, string productId)
+ {
+ this.customerId = customerId;
+ this.orderNumber = orderNumber;
+ this.productId = productId;
+ }
+
+ public string CustomerId
+ {
+ get { return customerId; }
+ set { customerId = value; }
+ }
+
+ public int OrderNumber
+ {
+ get { return orderNumber; }
+ set { orderNumber = value; }
+ }
+
+ public string ProductId
+ {
+ get { return productId; }
+ set { productId = value; }
+ }
+
+ public override bool Equals(object obj)
+ {
+ ID that = obj as ID;
+ if (that == null)
+ return false;
+
+ return customerId == that.customerId && productId == that.productId && orderNumber == that.orderNumber;
+ }
+
+ public override int GetHashCode()
+ {
+ return (customerId != null ? customerId.GetHashCode() : 37) ^
+ (productId != null ? productId.GetHashCode() : 31) ^
+ orderNumber.GetHashCode();
+ }
+ }
+ private ID id = new ID();
+ private int quantity;
+ private Order order;
+ private Product product;
+
+ public LineItem() {}
+ public LineItem(Order order, Product product)
+ {
+ this.order = order;
+ this.product = product;
+ id.OrderNumber = order.Id.OrderNumber;
+ id.CustomerId = order.Id.CustomerId;
+ id.ProductId = product.ProductId;
+ order.LineItems.Add(this);
+ }
+
+ public virtual ID Id
+ {
+ get { return id; }
+ set { id = value; }
+ }
+
+ public virtual int Quantity
+ {
+ get { return quantity; }
+ set { quantity = value; }
+ }
+
+ public virtual Order Order
+ {
+ get { return order; }
+ set { order = value; }
+ }
+
+ public virtual Product Product
+ {
+ get { return product; }
+ set { product = value; }
+ }
+ }
+}
\ No newline at end of file
Added: trunk/nhibernate/src/NHibernate.Test/CompositeId/LineItem.hbm.xml
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/CompositeId/LineItem.hbm.xml (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/CompositeId/LineItem.hbm.xml 2008-08-15 05:37:47 UTC (rev 3704)
@@ -0,0 +1,39 @@
+<?xml version="1.0"?>
+<!--
+
+ This mapping demonstrates
+
+ (1) composite keys and many-to-one associations on
+ composite keys
+
+ (2) use of insert="false" update="false" on an
+ association mapping, when the foreign key is
+ also part of the primary key
+
+-->
+
+<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
+ namespace="NHibernate.Test.CompositeId"
+ assembly="NHibernate.Test"
+ default-access="field.camelcase">
+
+ <class name="LineItem">
+
+ <composite-id name="Id" class="LineItem+ID">
+ <key-property name="CustomerId" length="10"/>
+ <key-property name="OrderNumber"/>
+ <key-property name="ProductId" length="10"/>
+ </composite-id>
+
+ <property name="Quantity"/>
+
+ <many-to-one name="Order" insert="false" update="false" not-null="true">
+ <column name="customerId"/>
+ <column name="orderNumber"/>
+ </many-to-one>
+
+ <many-to-one name="Product" insert="false" update="false" not-null="true" column="productId"/>
+ </class>
+
+
+</hibernate-mapping>
Added: trunk/nhibernate/src/NHibernate.Test/CompositeId/Order.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/CompositeId/Order.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/CompositeId/Order.cs 2008-08-15 05:37:47 UTC (rev 3704)
@@ -0,0 +1,99 @@
+using System;
+using System.Collections;
+
+namespace NHibernate.Test.CompositeId
+{
+ public class Order
+ {
+ public class ID
+ {
+ private string customerId;
+ private int orderNumber;
+ public ID() {}
+
+ public ID(string customerId, int orderNumber)
+ {
+ this.customerId = customerId;
+ this.orderNumber = orderNumber;
+ }
+
+ public string CustomerId
+ {
+ get { return customerId; }
+ set { customerId = value; }
+ }
+
+ public int OrderNumber
+ {
+ get { return orderNumber; }
+ set { orderNumber = value; }
+ }
+
+ public override bool Equals(object obj)
+ {
+ ID that = obj as ID;
+ if (that == null)
+ return false;
+ return customerId == that.customerId && orderNumber == that.orderNumber;
+ }
+
+ public override int GetHashCode()
+ {
+ return (customerId != null ? customerId.GetHashCode() : 37) ^ orderNumber.GetHashCode();
+ }
+ }
+
+ private ID id = new ID();
+ private DateTime orderDate;
+ private Customer customer;
+ private IList lineItems = new ArrayList();
+ private decimal total;
+
+ public Order() {}
+ public Order(Customer customer)
+ {
+ this.customer = customer;
+ id.CustomerId = customer.CustomerId;
+ id.OrderNumber = customer.Orders.Count;
+ customer.Orders.Add(this);
+ }
+
+ public virtual ID Id
+ {
+ get { return id; }
+ set { id = value; }
+ }
+
+ public virtual DateTime OrderDate
+ {
+ get { return orderDate; }
+ set { orderDate = value; }
+ }
+
+ public virtual Customer Customer
+ {
+ get { return customer; }
+ set { customer = value; }
+ }
+
+ public virtual IList LineItems
+ {
+ get { return lineItems; }
+ set { lineItems = value; }
+ }
+
+ public virtual decimal Total
+ {
+ get { return total; }
+ set { total = value; }
+ }
+
+ public virtual LineItem GenerateLineItem(Product product, int quantity)
+ {
+ LineItem li = new LineItem(this, product);
+ li.Quantity= quantity;
+ lineItems.Add(li);
+ return li;
+ }
+ }
+}
\ No newline at end of file
Added: trunk/nhibernate/src/NHibernate.Test/CompositeId/Order.hbm.xml
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/CompositeId/Order.hbm.xml (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/CompositeId/Order.hbm.xml 2008-08-15 05:37:47 UTC (rev 3704)
@@ -0,0 +1,61 @@
+<?xml version="1.0"?>
+<!--
+
+ This mapping demonstrates
+
+ (1) composite keys and one-to-many associations on
+ composite keys
+
+ (2) use of insert="false" update="false" on an
+ association mapping, when the foreign key is
+ also part of the primary key
+
+ (3) use of a derived property which performs a
+ subselect against associated tables
+
+ (4) use of <synchronize/> to ensure that auto-flush
+ works correctly for an entity with a property
+ derived from other tables
+
+
+-->
+<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
+ namespace="NHibernate.Test.CompositeId"
+ assembly="NHibernate.Test"
+ default-access="field.camelcase">
+
+ <class name="Order" table="CustomerOrder">
+ <synchronize table="LineItem"/>
+ <synchronize table="Product"/>
+
+ <composite-id name="Id" class="Order+ID">
+ <key-property name="CustomerId" length="10"/>
+ <key-property name="OrderNumber"/>
+ </composite-id>
+
+ <property name="OrderDate" not-null="true"/>
+
+ <property name="Total"
+ formula="( select sum(li.quantity*p.cost) from LineItem li, Product p where li.productId = p.productId and li.customerId = customerId and li.orderNumber = orderNumber )"/>
+
+ <many-to-one name="Customer"
+ column="customerId"
+ insert="false"
+ update="false"
+ not-null="true"/>
+
+ <bag name="LineItems"
+ fetch="join"
+ lazy="false"
+ inverse="true"
+ cascade="save-update">
+ <key>
+ <column name="customerId"/>
+ <column name="orderNumber"/>
+ </key>
+ <one-to-many class="LineItem"/>
+ </bag>
+
+ </class>
+
+</hibernate-mapping>
Added: trunk/nhibernate/src/NHibernate.Test/CompositeId/Product.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/CompositeId/Product.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/CompositeId/Product.cs 2008-08-15 05:37:47 UTC (rev 3704)
@@ -0,0 +1,41 @@
+namespace NHibernate.Test.CompositeId
+{
+ public class Product
+ {
+ private string productId;
+ private string description;
+ private decimal price;
+ private int numberAvailable;
+ private int numberOrdered;
+
+ public virtual string ProductId
+ {
+ get { return productId; }
+ set { productId = value; }
+ }
+
+ public virtual string Description
+ {
+ get { return description; }
+ set { description = value; }
+ }
+
+ public virtual decimal Price
+ {
+ get { return price; }
+ set { price = value; }
+ }
+
+ public virtual int NumberAvailable
+ {
+ get { return numberAvailable; }
+ set { numberAvailable = value; }
+ }
+
+ public virtual int NumberOrdered
+ {
+ get { return numberOrdered; }
+ set { numberOrdered = value; }
+ }
+ }
+}
\ No newline at end of file
Added: trunk/nhibernate/src/NHibernate.Test/CompositeId/Product.hbm.xml
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/CompositeId/Product.hbm.xml (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/CompositeId/Product.hbm.xml 2008-08-15 05:37:47 UTC (rev 3704)
@@ -0,0 +1,35 @@
+<?xml version="1.0"?>
+<!--
+
+ This mapping demonstrates
+
+ (1) use of a derived property which performs a
+ subselect against an associated table
+
+ (2) use of <synchronize/> to ensure that auto-flush
+ works correctly for an entity with a property
+ derived from another table
+
+-->
+
+<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
+ namespace="NHibernate.Test.CompositeId"
+ assembly="NHibernate.Test"
+ default-access="field.camelcase">
+
+ <class name="Product">
+ <synchronize table="LineItem"/>
+
+ <id name="ProductId" length="10">
+ <generator class="assigned"/>
+ </id>
+
+ <property name="Description" not-null="true" length="200"/>
+ <property name="Price" length="3" column="cost"/>
+ <property name="NumberAvailable"/>
+
+ <property name="NumberOrdered"
+ formula="( select sum(li.quantity) from LineItem li where li.productId = productId )"/>
+ </class>
+
+</hibernate-mapping>
Modified: trunk/nhibernate/src/NHibernate.Test/MultipleCollectionFetchTest/MultipleBagFetchFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/MultipleCollectionFetchTest/MultipleBagFetchFixture.cs 2008-08-14 17:33:32 UTC (rev 3703)
+++ trunk/nhibernate/src/NHibernate.Test/MultipleCollectionFetchTest/MultipleBagFetchFixture.cs 2008-08-15 05:37:47 UTC (rev 3704)
@@ -32,7 +32,7 @@
}
catch (QueryException e)
{
- Assert.IsTrue(e.Message.IndexOf("multiple collections") >= 0);
+ Assert.IsTrue(e.Message.IndexOf("Cannot simultaneously fetch multiple bags") >= 0);
}
}
@@ -45,7 +45,7 @@
}
catch (QueryException e)
{
- Assert.IsTrue(e.Message.IndexOf("multiple collections") >= 0);
+ Assert.IsTrue(e.Message.IndexOf("Cannot simultaneously fetch multiple bags") >= 0);
}
}
}
Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH826/Entities.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH826/Entities.cs 2008-08-14 17:33:32 UTC (rev 3703)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH826/Entities.cs 2008-08-15 05:37:47 UTC (rev 3704)
@@ -1,5 +1,6 @@
using System;
using System.Collections;
+using Iesi.Collections;
namespace NHibernate.Test.NHSpecificTest.NH826
{
@@ -12,13 +13,26 @@
get { return _id; }
set { _id = value; }
}
+
+ public override bool Equals(object obj)
+ {
+ Entity that = obj as Entity;
+ if(that == null)
+ return false;
+ return _id == that.Id;
+ }
+
+ public override int GetHashCode()
+ {
+ return _id.GetHashCode();
+ }
}
public class ActivitySet : Entity
{
- private IList _activities = new ArrayList();
+ private ISet _activities = new HashedSet();
- public IList Activities
+ public ISet Activities
{
get { return _activities; }
set { _activities = value; }
@@ -31,9 +45,9 @@
public class EvaluationActivity : Activity
{
- private IList _questions;
+ private ISet _questions;
- public IList Questions
+ public ISet Questions
{
get { return _questions; }
set { _questions = value; }
Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH826/Fixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH826/Fixture.cs 2008-08-14 17:33:32 UTC (rev 3703)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH826/Fixture.cs 2008-08-15 05:37:47 UTC (rev 3704)
@@ -38,7 +38,10 @@
session.Flush();
- session.Delete(loadedActivitySet.Activities[0]);
+ foreach (object o in loadedActivitySet.Activities)
+ {
+ session.Delete(o);
+ }
session.Delete(loadedActivitySet);
transaction.Commit();
Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH826/Mappings.hbm.xml
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH826/Mappings.hbm.xml 2008-08-14 17:33:32 UTC (rev 3703)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH826/Mappings.hbm.xml 2008-08-15 05:37:47 UTC (rev 3704)
@@ -6,10 +6,10 @@
<generator class="native" />
</id>
- <bag name="Activities" lazy="true" table="co_activity_set_membership" cascade="save-update" outer-join="true" inverse="false">
+ <set name="Activities" lazy="true" table="co_activity_set_membership" cascade="save-update" outer-join="true" inverse="false">
<key column="ActivitySetId" />
<many-to-many column="ActivityId" class="Activity" />
- </bag>
+ </set>
</class>
<class name="Activity" table="co_activity" discriminator-value="0">
@@ -21,10 +21,10 @@
<discriminator column="ActivityType" type="String" />
<subclass name="EvaluationActivity" discriminator-value="3">
- <bag name="Questions" lazy="true" table="" cascade="all-delete-orphan" outer-join="true" inverse="false">
+ <set name="Questions" lazy="true" table="" cascade="all-delete-orphan" outer-join="true" inverse="false">
<key column="EvaluationActivityId" />
<one-to-many class="Question" />
- </bag>
+ </set>
</subclass>
</class>
Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test-2.0.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test-2.0.csproj 2008-08-14 17:33:32 UTC (rev 3703)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test-2.0.csproj 2008-08-15 05:37:47 UTC (rev 3704)
@@ -99,7 +99,12 @@
<Compile Include="CompositeCollection\CompositeCollection.cs" />
<Compile Include="CompositeId\ClassWithCompositeId.cs" />
<Compile Include="CompositeId\ClassWithCompositeIdFixture.cs" />
+ <Compile Include="CompositeId\CompositeIdFixture.cs" />
+ <Compile Include="CompositeId\Customer.cs" />
<Compile Include="CompositeId\Id.cs" />
+ <Compile Include="CompositeId\LineItem.cs" />
+ <Compile Include="CompositeId\Order.cs" />
+ <Compile Include="CompositeId\Product.cs" />
<Compile Include="ConnectionStringTest\NamedConnectionStringFixture.cs" />
<Compile Include="ConnectionTest\AggressiveReleaseTest.cs" />
<Compile Include="ConnectionTest\ConnectionManagementTestCase.cs" />
@@ -1395,6 +1400,10 @@
<EmbeddedResource Include="DynamicEntity\Interceptor\Customer.hbm.xml" />
<EmbeddedResource Include="Any\Person.hbm.xml" />
<EmbeddedResource Include="Any\Properties.hbm.xml" />
+ <EmbeddedResource Include="CompositeId\Customer.hbm.xml" />
+ <EmbeddedResource Include="CompositeId\LineItem.hbm.xml" />
+ <EmbeddedResource Include="CompositeId\Order.hbm.xml" />
+ <EmbeddedResource Include="CompositeId\Product.hbm.xml" />
<Content Include="DynamicEntity\package.html" />
<EmbeddedResource Include="NHSpecificTest\NH1419\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH1413\Mappings.hbm.xml" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|