On 11.01.2011 16:12, Boris Drajer wrote:
Hi,
I'm still testing if everything works OK, but for me the move was
actually surprisingly painless... The only change I had to do is to
rename Session.Linq<>() calls to Session.Query<>() (which, if you
have a lot of them, you can fix by re-introducing your own Linq<>()
extension method). I encountered none of the HQL query syntax / XML
schema namespace or similar changes that were present in earlier
versions.
Best regards!
Hi,
Not only, additionally, there was a problem with
Transformers.AliasToBean on Session.CreateSQLQuery which now returns
result set aliases into upper case.
Session.CreateSQLQuery(@"SELECT DISCR as Discriminator, ID as Id
FROM entities WHERE entities.ARCHIVE = :archiveEntityFlag and
entities.ID IN (:entitiesIds)")
.SetResultTransformer(Transformers.AliasToBean(typeof(EntityDescription)))
...
Find roperty setter for name "DISCRIMINATOR" and "ID" instead of
"Discriminator" and "Id" which leads to the exception.
I create custom transformer class - FuzzyAliasToBeanResultTransformer -
which wrap calls to native Transformers.AliasToBean<T>() and transforms
(uppercased) aliases to properties names.
And I write code like this:
Session.CreateSQLQuery(
@"SELECT DISCR, ID FROM entities WHERE entities.ARCHIVE =
:archiveEntityFlag and entities.ID IN (:entitiesIds)")
.SetResultTransformer(
new FuzzyAliasToBeanResultTransformer<EntityDescription>()
.AddBeanProp("ID", "Id")
.AddBeanProp("DISCRIMNATOR", "Discriminator")) ...
Best regards,
E.Vinogradniy aka ssdi.
P.S.
See also:
https://forum.hibernate.org/viewtopic.php?f=1&t=986599&view=previous ;
http://swik.net/Hibernate/Hibernate+GroupBlog/Hibernate+3.2:+Transformers+for+HQL+and+SQL/cmxs
.
[Serializable]
public class FuzzyAliasToBeanResultTransformer<T> : IResultTransformer
{
#region Ctor
public FuzzyAliasToBeanResultTransformer()
{
transformer = Transformers.AliasToBean<T>();
beanProps = new Dictionary<string, string>();
}
#endregion
#region Field
private readonly IResultTransformer transformer;
private readonly Dictionary<string, string> beanProps;
#endregion
#region Methods
public FuzzyAliasToBeanResultTransformer<T> AddBeanProp(string
resultSetPropertyName, string beanPropertyName)
{
if (string.IsNullOrEmpty(resultSetPropertyName))
throw new ArgumentException("Must be not null or empty.",
"resultSetPropertyName");
if (string.IsNullOrEmpty(beanPropertyName))
throw new ArgumentException("Must be not null or empty.",
"beanPropertyName");
beanProps[resultSetPropertyName] = beanPropertyName;
return this;
}
#endregion
#region Implementation of IResultTransformer
public object TransformTuple(object[] tuple, string[] aliases)
{
return transformer.TransformTuple(tuple, aliases.Select(s =>
beanProps[s]).ToArray());
}
public IList TransformList(IList collection)
{
return transformer.TransformList(collection);
}
#endregion
}
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en.