Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/NHibernate.Test/NHSpecificTest/NH3150/Class.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

using System.Collections.Generic;
namespace NHibernate.Test.NHSpecificTest.NH3150
{
public class Worker
{

public virtual int? id { get; set; }

public virtual string name { get; set; }
public virtual string position { get; set; }

}

public class Worker2
{

public virtual int? id { get; set; }
public virtual IList<Role> roles { get; set; }
}

public class Role
{
public virtual int? id { get; set; }
public virtual string description { get; set; }
}
}
76 changes: 76 additions & 0 deletions src/NHibernate.Test/NHSpecificTest/NH3150/Fixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using NUnit.Framework;
using System.Collections.Generic;

namespace NHibernate.Test.NHSpecificTest.NH3150
{

[TestFixture]
public class Fixture : BugTestCase
{
public override string BugNumber
{
get { return "NH3150"; }
}

protected override void OnTearDown()
{
using (ISession s = OpenSession())
using (ITransaction tx = s.BeginTransaction())
{
s.Delete("from Worker");
s.Delete("from Worker2");
s.Delete("from Role");
tx.Commit();
}
}

[Test]
public void CanHaveNaturalIdWithMoreThanOneProperty()
{
using (ISession s = OpenSession())
using (ITransaction tx = s.BeginTransaction())
{
var worker = new Worker();
worker.name = "Mr Black";
worker.position = "Managing Director";
s.Save(worker);

tx.Commit();
Assert.AreEqual(1, worker.id, "id should be 1");
}
}

[Test]
public void IdBagWithSelectPOID()
{
var worker_id = 0;
var role_id = 0;

using (ISession s = OpenSession())
using (ITransaction tx = s.BeginTransaction())
{
var worker = new Worker2();
var role = new Role() { description = "monkey keeper" };

worker.roles = new List<Role>();
worker.roles.Add(role);

s.Save(worker);
s.Save(role);

tx.Commit();

worker_id = worker.id.Value;
role_id = role.id.Value;
}

using (ISession s = OpenSession())
{
var saved_worker = s.Get<Worker2>(worker_id);
Assert.NotNull(saved_worker.roles, "roles should not be null");
Assert.AreEqual(1, saved_worker.roles.Count, "roles count should be 1");
}

}
}
}
88 changes: 88 additions & 0 deletions src/NHibernate.Test/NHSpecificTest/NH3150/Mappings.hbm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="NHibernate.Test.NHSpecificTest.NH3150"
assembly="NHibernate.Test">
<class name="Worker">
<id name="id">
<generator class="select"/>
</id>

<natural-id >
<property name="name"/>
<property name="position" />
</natural-id>
</class>

<class name="Worker2">
<id name="id">
<generator class="identity"/>
</id>

<idbag name="roles" inverse="false" cascade="all-delete-orphan" table="workerRoles">
<collection-id column="id" type="Int32">
<generator class="select" />
</collection-id>
<key column="worker_id" />
<many-to-many column="role_id" class="Role" fetch="join" />
</idbag>
</class>

<class name="Role" >
<id name="id">
<generator class="identity"/>
</id>
<property name="description"/>
</class>

<database-object>
<create>
CREATE TRIGGER dbo.id_gen_Worker ON dbo.Worker
INSTEAD OF INSERT
AS
BEGIN
SET NOCOUNT ON;

declare @lastval int
set @lastval = (select max(id) from Worker)
if @lastval is null set @lastval = 0

SELECT * INTO #Inserted FROM Inserted
UPDATE #Inserted set id = @lastval+1
SET NOCOUNT OFF;
INSERT INTO Worker SELECT * FROM #Inserted
END
GO
</create>
<drop>
DROP TRIGGER dbo.id_gen_Worker;
</drop>
<dialect-scope name="NHibernate.Dialect.MsSql2008Dialect"/>
</database-object>


<database-object>
<create>
CREATE TRIGGER dbo.id_gen_workerRoles ON dbo.workerRoles
INSTEAD OF INSERT
AS
BEGIN
SET NOCOUNT ON;

declare @lastval int
set @lastval = (select max(id) from workerRoles)
if @lastval is null set @lastval = 0

SELECT * INTO #Inserted FROM Inserted
UPDATE #Inserted set id = @lastval+1
SET NOCOUNT OFF;
INSERT INTO workerRoles SELECT * FROM #Inserted
END
GO
</create>
<drop>
DROP TRIGGER dbo.id_gen_workerRoles;
</drop>
<dialect-scope name="NHibernate.Dialect.MsSql2008Dialect"/>
</database-object>

</hibernate-mapping>
3 changes: 3 additions & 0 deletions src/NHibernate.Test/NHibernate.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,8 @@
<Compile Include="NHSpecificTest\BagWithLazyExtraAndFilter\Domain.cs" />
<Compile Include="NHSpecificTest\BagWithLazyExtraAndFilter\Fixture.cs" />
<Compile Include="Component\Basic\ComponentWithUniqueConstraintTests.cs" />
<Compile Include="NHSpecificTest\NH3150\Class.cs" />
<Compile Include="NHSpecificTest\NH3150\Fixture.cs" />
<Compile Include="NHSpecificTest\NH2347\Entity.cs" />
<Compile Include="NHSpecificTest\NH2347\Fixture.cs" />
<Compile Include="NHSpecificTest\NH2664\Product.cs" />
Expand Down Expand Up @@ -2817,6 +2819,7 @@
<EmbeddedResource Include="NHSpecificTest\NH1291AnonExample\Mappings.hbm.xml" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="NHSpecificTest\NH3150\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH2664\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH2214\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH2960\Mappings.hbm.xml" />
Expand Down
4 changes: 2 additions & 2 deletions src/NHibernate/Id/IPostInsertIdentityPersister.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ public interface IPostInsertIdentityPersister

/// <summary>
/// Get a SQL select string that performs a select based on a unique
/// key determined by the given property name).
/// key determined by the given array of property names).
/// </summary>
/// <param name="propertyName">
/// The name of the property which maps to the
/// column(s) to use in the select statement restriction.
/// </param>
/// <returns> The SQL select string </returns>
SqlString GetSelectByUniqueKeyString(string propertyName);
SqlString GetSelectByUniqueKeyString(string[] propertyNames);

#region NH specific
/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions src/NHibernate/Id/Insert/AbstractSelectingDelegate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public object PerformInsert(SqlCommandInfo insertSQL, ISessionImplementor sessio
IDbCommand idSelect = session.Batcher.PrepareCommand(CommandType.Text, selectSQL, ParametersTypes);
try
{
BindParameters(session, idSelect, binder.Entity);
BindParameters(session, idSelect, binder);
IDataReader rs = session.Batcher.ExecuteReader(idSelect);
try
{
Expand Down Expand Up @@ -97,7 +97,7 @@ public object PerformInsert(SqlCommandInfo insertSQL, ISessionImplementor sessio
/// <param name="session">The session </param>
/// <param name="ps">The prepared <see cref="SelectSQL"/> command </param>
/// <param name="entity">The entity being saved. </param>
protected internal virtual void BindParameters(ISessionImplementor session, IDbCommand ps, object entity) { }
protected internal virtual void BindParameters(ISessionImplementor session, IDbCommand ps, IBinder binder) { }

#region NH Specific

Expand Down
Loading