nhibernate

Nhibernate CreateSQLQuery Stored Procedure result to non mapped class

青春壹個敷衍的年華 提交于 2019-12-23 19:18:32
问题 In my application I want to get data from a stored procedured where the table is not mapped in the application. In this stored procedure I added aliases to the column names which respond to the properties in my class. HQL: return Session.CreateSQLQuery("exec PER_PrikklokSaldi :IDPers :jaar :maand") .AddScalar("Description", NHibernateUtil.String) .AddScalar("StartSaldo", NHibernateUtil.Int32) .AddScalar("Plus", NHibernateUtil.Int32) .AddScalar("Minus", NHibernateUtil.Int32) .AddScalar(

What is the Object Identity Problem in NHibernate?

倖福魔咒の 提交于 2019-12-23 19:14:52
问题 What is the meaning of Object Identity Problem in NHibernate? 回答1: The object identity problem is that there is no perfect (aka 100% exact) way to make sure that an object identity for a plain CLR object has a 1:1 mapping to an object identity in NHibernate. The reason is that object identity in the one case (CLR) is defined by the object pointer, object identity in the other case by a database ID value. So it might not be possible to fully reliably map a CLR object to a NHibernate object.

Loading multi-level collections without duplicates in NHibernate

心不动则不痛 提交于 2019-12-23 19:13:22
问题 My question is very similar to this one (that wasn't really answered): Nhibernate: distinct results in second level Collection I have this object model: class EntityA { ... IList<EntityB> BList { get; protected set; } ... } class EntityB { ... does NOT reference its parent EntityA... IList<EntityC> CList { get; protected set; } } They are One-to-Many relations. EntityB and C do not have an object reference to its parent object. I'd like to fully load the collections by performing something

NHibernate Named Query Parameter Numbering @p1 @p2 etc

允我心安 提交于 2019-12-23 18:59:04
问题 A colleague recently ran into a problem where he was passing in a single date parameter to a named query. In the query, the parameter was being used twice, once in an expression and once in a GROUP BY clause. Much to our surprise, we discovered that NHibernate used two variables and sent the single named parameter in twice, as @p1 and @p2. This behaviour caused SQL to fail the query, with the usual "a column in the select clause is not in the group by clause" (I paraphrase ofcourse). Is this

Confusion over one-to-one mapping in NHibernate

强颜欢笑 提交于 2019-12-23 18:50:38
问题 Can someone suggest to me the appropriate Mapping to be used in the following situation: Parent Table - AllTransactions Child Table - TranCategory1, TranCategory2 and TranCategory3 and 8 more. All twelve tables share the same composite keys. Now count in AllTransactions is the sum of transactions in all the child tables. The child tables contain only unique values from the parent table. The mapping that I am using is shown below. I am using constrained="true" in the Parent table only to avoid

NHibernate - Could not execute query - Input string was not in a correct format

梦想与她 提交于 2019-12-23 18:49:51
问题 I've been scratching my head with this one for a while now and I'm clueless as to what's wrong. Overview: I have two tables in a MySQL database. Both map correctly to the database (I can load data in) and I am able to query to one table, but not the other. Solutions I've looked into: Type conversion issues between the table and the C# code, mapping issues, SQL format issues. The code that fails is as follows: Configuration config = new Configuration(); config.Configure(); ISessionFactory

nhibernate joinqueryover unrelated tables (same foreign key)

怎甘沉沦 提交于 2019-12-23 18:45:59
问题 Basically what i am trying to do is join two tables on foreign keys. I have this query: var result = _session.QueryOver(() => contentReferenceAlias) .Inner.JoinAlias(() => contentReferenceAlias.ContentReference, () => contentLibrarySearchAlias.ContentReference) .Where(() => contentReferenceAlias.ToLanguage.Id == languageId && contentReferenceAlias.ContentReference.Id == contentLibrarySearchAlias.ContentReference.Id) .SelectList(list => list .Select(() => contentReferenceAlias.ContentReference

How should NHibernate update properties mapped as Version

感情迁移 提交于 2019-12-23 18:34:25
问题 Using fluent NHibernate I have a property on a class mapped using Version Version(x => x.Version); When I save the object, the Version property gets incremented in the database as I would expect, but the value of the property on the object only seems to change sometimes. using (var tx = session.BeginTransaction()) { session.Merge(item); tx.Commit(); item.Version; // Sometimes this is still 1, when I expect it to be 2. } The problem is then that if it remains as 1 and I make more changes and

NHibernate property mapping: columns and formula

若如初见. 提交于 2019-12-23 18:34:09
问题 When i map columns from the inspected table, i do this: <property name="InstanceName" type="MyNameUserType, MyApp.MyNamespace"> <column name="Name"/> <column name="Name2"/> </property> How can I make property mapping initialize a UserType with data retrieved by the formula's sql query? <property name="InstanceName" type="MyNameUserType, MyApp.MyNamespace" formula="(...)"/> fails with an exception "wrong number of columns". Thanks in advance! 回答1: MyUserNameType should be a class level mapping

How to use hibernate sessions?

眉间皱痕 提交于 2019-12-23 18:32:23
问题 The structure of my program is as follows: Inside my main java class: for () // this will execute for say 5000 times ---- LINE 1 { // do select on Database1 (this will select say 10000 rows) ---- LINE 2 // do some computations (mainly string operations) ---- LINE 3 call function1() // this will do some update on Database1 ---- LINE 4 } Now, I am trying to access Database1 using Hibernate. My question is how should I use hibernate session to access it. I am when should I start the session and