Skip to content

NH-3575 #317

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
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

Large diffs are not rendered by default.

73 changes: 73 additions & 0 deletions src/NHibernate.Test/MappingByCode/IntegrationTests/NH3667/Model.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NHibernate.Test.MappingByCode.IntegrationTests.NH3667
{
public class Entity
{
public int A { get; set; }
public string B { get; set; }
}

public class Component
{
public int A { get; set; }
public int B { get; set; }
}

public class ClassWithMapEntityElement
{
public int Id { get; set; }
public IDictionary<Entity, string> Map { get; set; }
}

public class ClassWithMapElementComponent
{
public int Id { get; set; }
public IDictionary<string, Component> Map { get; set; }
}

public class ClassWithMapEntityComponent
{
public int Id { get; set; }
public IDictionary<Entity, Component> Map { get; set; }
}

public class ClassWithMapElementEntity
{
public int Id { get; set; }
public IDictionary<string, Entity> Map { get; set; }
}

public class ClassWithMapComponentEntity
{
public int Id { get; set; }
public IDictionary<Component, Entity> Map { get; set; }
}

public class ClassWithMapComponentElement
{
public int Id { get; set; }
public IDictionary<Component, string> Map { get; set; }
}

public class ClassWithMapComponentComponent
{
public int Id { get; set; }
public IDictionary<Component, Component> Map { get; set; }
}

public class ClassWithMapEntityEntity
{
public int Id { get; set; }
public IDictionary<Entity, Entity> Map { get; set; }
}

public class ClassWithMapElementElement
{
public int Id { get; set; }
public IDictionary<string, string> Map { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Linq;
using NHibernate.Criterion;
using NHibernate.Impl;
using NUnit.Framework;
Expand All @@ -7,6 +8,20 @@ namespace NHibernate.Test.NHSpecificTest.Futures
[TestFixture]
public class FutureCriteriaFixture : FutureFixture
{
[Test]
public void DefaultReadOnlyTest()
{
//NH-3575
using (var s = sessions.OpenSession())
{
s.DefaultReadOnly = true;

var persons = s.CreateCriteria(typeof(Person)).Future<Person>();

Assert.IsTrue(persons.All(p => s.IsReadOnly(p)));
}
}

[Test]
public void CanUseFutureCriteria()
{
Expand Down
17 changes: 16 additions & 1 deletion src/NHibernate.Test/NHSpecificTest/Futures/FutureQueryFixture.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NHibernate.Driver;
using System.Linq;
using NHibernate.Driver;
using NHibernate.Impl;
using NUnit.Framework;

Expand All @@ -9,6 +10,20 @@ namespace NHibernate.Test.NHSpecificTest.Futures
[TestFixture]
public class FutureQueryFixture : FutureFixture
{
[Test]
public void DefaultReadOnlyTest()
{
//NH-3575
using (var s = sessions.OpenSession())
{
s.DefaultReadOnly = true;

var persons = s.CreateQuery("from Person").Future<Person>();

Assert.IsTrue(persons.All(p => s.IsReadOnly(p)));
}
}

[Test]
public void CanUseFutureQuery()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Linq;
using NHibernate.Criterion;
using NHibernate.Impl;
using NUnit.Framework;
Expand Down Expand Up @@ -30,6 +31,20 @@ protected override void OnTearDown()
}
}

[Test]
public void DefaultReadOnlyTest()
{
//NH-3575
using (var s = sessions.OpenSession())
{
s.DefaultReadOnly = true;

var persons = s.QueryOver<Person>().Future<Person>();

Assert.IsTrue(persons.All(p => s.IsReadOnly(p)));
}
}

[Test]
public void CanUseFutureCriteria()
{
Expand Down
14 changes: 14 additions & 0 deletions src/NHibernate.Test/NHSpecificTest/Futures/LinqFutureFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@ namespace NHibernate.Test.NHSpecificTest.Futures
[TestFixture]
public class LinqFutureFixture : FutureFixture
{
[Test]
public void DefaultReadOnlyTest()
{
//NH-3575
using (var s = sessions.OpenSession())
{
s.DefaultReadOnly = true;

var persons = s.Query<Person>().ToFuture();

Assert.IsTrue(persons.All(p => s.IsReadOnly(p)));
}
}

[Test]
public void CoalesceShouldWorkForFutures()
{
Expand Down
4 changes: 3 additions & 1 deletion src/NHibernate.Test/NHibernate.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,8 @@
<Compile Include="MappingByCode\IntegrationTests\NH3135\Models.cs" />
<Compile Include="MappingByCode\IntegrationTests\NH3280\Domain.cs" />
<Compile Include="MappingByCode\IntegrationTests\NH3280\OneToOneToInheritedProperty.cs" />
<Compile Include="MappingByCode\IntegrationTests\NH3667\MapFixture.cs" />
<Compile Include="MappingByCode\IntegrationTests\NH3667\Model.cs" />
<Compile Include="MappingByCode\MappersTests\AnyMapperTest.cs" />
<Compile Include="MappingByCode\MappersTests\IdMapperTest.cs" />
<Compile Include="MappingByCode\MappersTests\ManyToOneMapperTest.cs" />
Expand Down Expand Up @@ -3630,4 +3632,4 @@ if exist hibernate.cfg.xml (del hibernate.cfg.xml)
if exist "$(ProjectDir)hibernate.cfg.xml" (copy "$(ProjectDir)hibernate.cfg.xml" "hibernate.cfg.xml")
copy /y "..\..\..\NHibernate.DomainModel\ABC.hbm.xml" "ABC.hbm.xml"</PostBuildEvent>
</PropertyGroup>
</Project>
</Project>
3 changes: 2 additions & 1 deletion src/NHibernate/Impl/MultiCriteriaImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,8 @@ private void GetResultsFromDatabase(IList results)
for (int i = 0; i < loaders.Count; i++)
{
CriteriaLoader loader = loaders[i];
loader.InitializeEntitiesAndCollections(hydratedObjects[i], reader, session, false);
//NH-3575
loader.InitializeEntitiesAndCollections(hydratedObjects[i], reader, session, session.DefaultReadOnly);

if (createSubselects[i])
{
Expand Down
17 changes: 15 additions & 2 deletions src/NHibernate/Mapping/ByCode/ModelMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1280,9 +1280,22 @@ protected virtual ICollectionElementRelationMapper DetermineCollectionElementRel
{
return new OneToManyRelationMapper(propertyPath, ownerType, collectionElementType, modelInspector, customizerHolder, this);
}
if (modelInspector.IsManyToMany(property))
//NH-3667 & NH-3102
//check if property is really a many-to-many: as detected by modelInspector.IsManyToMany and also the collection type is an entity
if (modelInspector.IsManyToMany(property) == true)
{
return new ManyToManyRelationMapper(propertyPath, customizerHolder, this);
if (property.GetPropertyOrFieldType().IsGenericCollection() == true)
{
var args = property.GetPropertyOrFieldType().GetGenericArguments();

if ((args.Length < 2) || (args.Length > 1))
{
if (modelInspector.IsEntity(args[1]) == true)
{
return new ManyToManyRelationMapper(propertyPath, customizerHolder, this);
}
}
}
}
if (modelInspector.IsComponent(collectionElementType))
{
Expand Down