RE: [nhusers] Re: Inserting a Primary Key value into the database

2010-07-30 Thread Frans Bouma
 I'm in the middle of Chapter 5 of the NHibernate 2 Beginner's Guide,
 specifically the end of page 97.  When I try to run the console project, I
 get the following runtime error at the session.Save line:
 could not get or update next value[SQL: ]
 
 The inner exception is Invalid object name 'hibernate_unique_key'.
 That error is encountered when I have the generator class set to 'hilo.'

did you create the hilo sequence table and insert 1 row in it? You
need to do that, as the hilo generator increases an existing row's value.

FB


 I'm currently using a SQL Server 2008 Express database with this project.
 The tables do NOT have an auto-sequenced number at the moment.
 
 When I changed the generator class to increment, I was able to
 successfully save the object to the database table.
 
 Any ideas why 'hilo' isn't good in this situation?  (This was the value
 recommended in the book/associated source code.)
 
 Stephen
 
 
 On Thu, Jul 29, 2010 at 10:40 AM, Jason Dentler jasondent...@gmail.com
 wrote:
 
 
   Frans,
 
   Sorry. I was referring to Identity in terms of SQL Server, as this
is
 the database referred to in the NHibernate beginner's book. This
particular
 POID generator, and it's cousin, Native on SQL server require the data to
be
 inserted in order to generate an ID. This breaks batching, as the
 session.Save, etc. will put data in the database rather than waiting for
 transaction.Commit (or session.Flush, which IMO, should be considered
 deprecated when using flush-on-commit, the default)
 
   Compare that with hilo, which also doesn't allow duplicates when
 transactions are used properly, doesn't break batching, and even better,
 doesn't require a trip to the database for every insert; just one trip to
 flush the session.
 
   As I understand it, on Oracle, native works just fine because it's
 equivalent to sequence. It does require an extra trip to the database for
 every insert, but only to fetch an id value, not to insert data. I'm not
 sure if Identity is available on Oracle, if it has a different meaning
than
 sequence, or if it's just silently converted to sequence. I'm a SQL guy.
 
   In any case, I'd like to know what exception Stephen encountered
 before guessing about the root cause.
 
   Thanks,
   Jason
 
 
   On Thu, Jul 29, 2010 at 10:21 AM, John Davidson
 jwdavid...@gmail.com wrote:
 
 
   Yes, please create a test and try it
 
   John Davidson
 
 
   On Thu, Jul 29, 2010 at 11:18 AM, Frans Bouma fr...@sd.nl
 wrote:
 
 
the issue with identity is that it causes two
trips
 to the database for
every save of a new record and their are
 complications with Flush
 
 
  hmm, are you sure? the new identity value is
 requested by a batched
   SCOPE_IDENTITY() select right after the insert, same
 roundtrip as the
   insert, and it can then immediately be synced with
 related (fk side)
   entities. HiLo requires an extra roundtrip for the
new
 value to obtain and
   insert, as that is required to obtain the new hilo
 using the sql posted by
   jason. Or am I missing something?
 
  FB
 
 
   
John Davidson
   
   
On Thu, Jul 29, 2010 at 10:51 AM, Frans Bouma
 fr...@sd.nl wrote:
   
   
   2 separate clients accessing the same
 database using HiLo will not
grab
   duplicate hi values.
  
   when the next_hi is retrieved by the
session
 factory the following
2
   statements are executed.
   select next_hi from hilo_table (with lock)
 update hilo_table set
next_hi =
   next_hi + 1 where next_hi = @p0 (with
update
 lock)
  
   ...or something like that. between these
 statements and having the
  operation
   within a transaction there is little (if
any)
 chance of 2
   factories
  pulling
   the same next_hi value.
   
   
 thanks Jason :) It's indeed highly
 unlikely that the number
   is
  issued twice, although I fail to see why
this
 is better than
Identity,
  considering that this table row is locked
 _alot_ and many 

[nhusers] Re: SetFirstResult without SetMaxResult

2010-07-30 Thread Nik Govorov
John, sorry, but you are not in a subject.

On Jul 30, 3:11 am, John Davidson jwdavid...@gmail.com wrote:
 Yes, I expect it to get all the Entity items from the database and then
 filter it according to your LINQtoObject filter and skip the first ten
 records and then return the following ten records. If you want different
 behaviour do not use CreateQuery, QueryOver or Query, but use IQueryable.

 See the LINQ tests in the NHibernate trunk for more examples of
 NHibernateLINQ.

         [Category(Paging)]
 [Test(Description = This sample uses a where clause and the Skip and Take
 operators to select  +
 the second, third and fourth pages of products)]
 public void TriplePageSelection()
 {
 IQueryableProduct q = (
                          from p in db.Products
                          where p.ProductId  1
                          orderby p.ProductId
                          select p
 );

                        IQueryableProduct page2 = q.Skip(5).Take(5);
                        IQueryableProduct page3 = q.Skip(10).Take(5);
                        IQueryableProduct page4 = q.Skip(15).Take(5);

 var firstResultOnPage2 = page2.First();
 var firstResultOnPage3 = page3.First();
 var firstResultOnPage4 = page4.First();

 Assert.AreNotEqual(firstResultOnPage2.ProductId,
 firstResultOnPage3.ProductId);
 Assert.AreNotEqual(firstResultOnPage3.ProductId,
 firstResultOnPage4.ProductId);
 Assert.AreNotEqual(firstResultOnPage2.ProductId,
 firstResultOnPage4.ProductId);

 }

 That test will produce output that behaves as you would expect with respect
 to the records returned, but your assumptions as to how it does it are
 incorrect. The SQL generated to create page2, page3 and page4 objects
 follow:

 * NHibernate.Test.Linq.MiscellaneousTextFixture.TriplePageSelection
 NHibernate:
     SELECT
         TOP (@p0) ProductId32_,
         ProductN2_32_,
         SupplierId32_,
         CategoryId32_,
         Quantity5_32_,
         UnitPrice32_,
         UnitsInS7_32_,
         UnitsOnO8_32_,
         ReorderL9_32_,
         Discont10_32_
     FROM
         (select
             product0_.ProductId as ProductId32_,
             product0_.ProductName as ProductN2_32_,
             product0_.SupplierId as SupplierId32_,
             product0_.CategoryId as CategoryId32_,
             product0_.QuantityPerUnit as Quantity5_32_,
             product0_.UnitPrice as UnitPrice32_,
             product0_.UnitsInStock as UnitsInS7_32_,
             product0_.UnitsOnOrder as UnitsOnO8_32_,
             product0_.ReorderLevel as ReorderL9_32_,
             product0_.Discontinued as Discont10_32_,
             ROW_NUMBER() OVER(
         ORDER BY
             product0_.ProductId) as __hibernate_sort_row
         from
             Products product0_
         where
             product0_.ProductId@p2) as query
     WHERE
         query.__hibernate_sort_row  @p1
     ORDER BY
         query.__hibernate_sort_row;
     @p0 = 1 [Type: Int32 (0)],
     @p1 = 5 [Type: Int32 (0)],
     @p2 = 1 [Type: Int32 (0)]
 NHibernate:
     SELECT
         TOP (@p0) ProductId32_,
         ProductN2_32_,
         SupplierId32_,
         CategoryId32_,
         Quantity5_32_,
         UnitPrice32_,
         UnitsInS7_32_,
         UnitsOnO8_32_,
         ReorderL9_32_,
         Discont10_32_
     FROM
         (select
             product0_.ProductId as ProductId32_,
             product0_.ProductName as ProductN2_32_,
             product0_.SupplierId as SupplierId32_,
             product0_.CategoryId as CategoryId32_,
             product0_.QuantityPerUnit as Quantity5_32_,
             product0_.UnitPrice as UnitPrice32_,
             product0_.UnitsInStock as UnitsInS7_32_,
             product0_.UnitsOnOrder as UnitsOnO8_32_,
             product0_.ReorderLevel as ReorderL9_32_,
             product0_.Discontinued as Discont10_32_,
             ROW_NUMBER() OVER(
         ORDER BY
             product0_.ProductId) as __hibernate_sort_row
         from
             Products product0_
         where
             product0_.ProductId@p2) as query
     WHERE
         query.__hibernate_sort_row  @p1
     ORDER BY
         query.__hibernate_sort_row;
     @p0 = 1 [Type: Int32 (0)],
     @p1 = 10 [Type: Int32 (0)],
     @p2 = 1 [Type: Int32 (0)]
 NHibernate:
     SELECT
         TOP (@p0) ProductId32_,
         ProductN2_32_,
         SupplierId32_,
         CategoryId32_,
         Quantity5_32_,
         UnitPrice32_,
         UnitsInS7_32_,
         UnitsOnO8_32_,
         ReorderL9_32_,
         Discont10_32_
     FROM
         (select
             product0_.ProductId as ProductId32_,
             product0_.ProductName as ProductN2_32_,
             product0_.SupplierId as SupplierId32_,
             product0_.CategoryId as CategoryId32_,
             product0_.QuantityPerUnit as Quantity5_32_,
             product0_.UnitPrice as UnitPrice32_,
             product0_.UnitsInStock as UnitsInS7_32_,
             product0_.UnitsOnOrder as UnitsOnO8_32_,

[nhusers] Dynamic query to DTO

2010-07-30 Thread Luka
Hi,
I am using query object pattern to pass query from the UI to the DAL
layer.
Then in the DAL, convert the passed query object to the NHibernate
criteria.
How can I make NHibernate to return DTO object from this type of
query? The problem is that the query isn't known in the design time
but on the runtime.

-- 
You received this message because you are subscribed to the Google Groups 
nhusers group.
To post to this group, send email to nhus...@googlegroups.com.
To unsubscribe from this group, send email to 
nhusers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.



[nhusers] Re: Dynamic query to DTO

2010-07-30 Thread kor
i don't understand very well what you need,

with this
criteria.SetResultTransformer (new
EntityToBeanTransformer(typeof(YourDto))

you can return an object not mapped in the xml, if it's not what you
need can explain better what you want?

-- 
You received this message because you are subscribed to the Google Groups 
nhusers group.
To post to this group, send email to nhus...@googlegroups.com.
To unsubscribe from this group, send email to 
nhusers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.



RE: [nhusers] Re: Inserting a Primary Key value into the database

2010-07-30 Thread Frans Bouma
 I'd like to comment in general terms... because I saw a few
 misunderstantings regarding hilo.
 
 - The strength of HiLo performance is that Hi values are retrieved per
 SessionFactory. If you use the default max_lo, it retrieves a value every
32
 kibirecords, which is essentialy zero for most OLTP purposes
 - As noted, collisions are not possible because access to the hilo table
 uses appropriate locks
 - If that were an issue, seqhilo is the way to go in databases that
support
 sequences
 - Identity breaks both batching and UoW. This is explained here:
 http://fabiomaulo.blogspot.com/2009/02/nh210-generators-behavior-
 explained.html
 http://fabiomaulo.blogspot.com/2009/02/nh210-generators-behavior-
 explained.html - In short, the best generators are hilo/seqhilo and
 guid.comb. That should be in the docs :-)

this list you mean? Absolutely. Looking at the docs of HiLo in march
2010 or so, I concluded that it wasn't really a useful thing to use due to
the misinformation, and I didn't build support for it in our nhibernate
support in llblgen pro. But after reading this thread and your list, I'll
add it today :) Good info all :)

Frans

 
 Diego
 
 
 On Thu, Jul 29, 2010 at 12:56, Frans Bouma fr...@sd.nl wrote:
 
 
Sorry. I was referring to Identity in terms of SQL Server, as this
 is the
database referred to in the NHibernate beginner's book. This
 particular
   POID
generator, and it's cousin, Native on SQL server require the data
 to be
inserted in order to generate an ID. This breaks batching, as the
session.Save, etc. will put data in the database rather than
 waiting for
transaction.Commit (or session.Flush, which IMO, should be
 considered
deprecated when using flush-on-commit, the default)
   
Compare that with hilo, which also doesn't allow duplicates when
transactions are used properly, doesn't break batching, and even
 better,
doesn't require a trip to the database for every insert; just one
 trip to
flush the session.
 
 
  aha! good point, I totally ignored that, but you're right.
 HiLo
   could execute up front, claim X id's and the session could hand
those
 out
   already, insert everything and that indeed would not require extra
   roundtrips.
 
  So in case of batching: identity fetch makes batching not
 really
   useful if table rows with pending fk field syncs are present as the
 identity
   value as to be obtained before those rows can be saved.
 
  Although one could create extra parameters and still do it in
 a
   single trip, but that would require hairy code I guess on the side
of
 the
   o/r core (read: sql server specific stuff outside the
 dialect/driver), not
   what you want)
 
 
As I understand it, on Oracle, native works just fine because it's
equivalent to sequence. It does require an extra trip to the
 database for
every insert, but only to fetch an id value, not to insert data.
 I'm not
sure if Identity is available on Oracle, if it has a different
 meaning
   than
sequence, or if it's just silently converted to sequence. I'm a
SQL
 guy.
 
 
  yes, for batching, on oracle you have the same problem,
 although one
   could create 1 extra batched query which fetches, say for ever
entity
 to
   save a parameter and a query with a series of batched SELECT :paramX
 =
   seq.NEXTVAL FROM DUAL; etc.
 
  Not ideal as well. Good point! My crappy test I posted
earlier
 is
   indeed showing that in non-batching situations, things aren't that
 happy for
   HiLo, but for batching, John and you are absolutely right.
 
 
In any case, I'd like to know what exception Stephen encountered
 before
guessing about the root cause.
 
 
  indeed. Sorry for the side-track. :)
 
  FB
 
 
   
Thanks,
Jason
   
   
On Thu, Jul 29, 2010 at 10:21 AM, John Davidson
 jwdavid...@gmail.com
wrote:
   
   
  Yes, please create a test and try it
   
  John Davidson
   
   
  On Thu, Jul 29, 2010 at 11:18 AM, Frans Bouma fr...@sd.nl
 wrote:
   
   
   the issue with identity is that it causes two
trips
 to the
database for
   every save of a new record and their are
 complications
   with
Flush
   
   
 hmm, are you sure? the new identity value is
   requested
by a batched
  SCOPE_IDENTITY() select right after the insert, same
   roundtrip
as the
  insert, and it can then immediately be synced with
 related
   (fk
side)
  entities. HiLo requires an extra roundtrip for the
 new value
to 

[nhusers] Re: NotNull and Unique String

2010-07-30 Thread kor
if you need it on the database-side put in the mapping

property name=MyStringPropertyName not-null=true unique=true /

if you need it on the application-side you need to use a custom
validation or an external validation framework (for example see
nhibernate.validator)

-- 
You received this message because you are subscribed to the Google Groups 
nhusers group.
To post to this group, send email to nhus...@googlegroups.com.
To unsubscribe from this group, send email to 
nhusers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.



[nhusers] Re: CreateCriteria Issue

2010-07-30 Thread kor
try to do that query by hand, maybe in the Profile table you have 72
rows with the same values

-- 
You received this message because you are subscribed to the Google Groups 
nhusers group.
To post to this group, send email to nhus...@googlegroups.com.
To unsubscribe from this group, send email to 
nhusers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.



[nhusers] Re: Dynamic query to DTO

2010-07-30 Thread Luka
I read that I need to speccify mappings (projections) in the query
like this:
IList resultWithAliasedBean = s.CreateCriteria(typeof(Enrolment))
  .CreateAlias(Student, st)
  .CreateAlias(Course, co)
  .SetProjection(Projections.ProjectionList()
  .Add(Projections.Property(st.Name), studentName)
  .Add(Projections.Property(co.Description),
courseDescription)
)
.AddOrder(Order.Desc(studentName))
.SetResultTransformer(NHibernate.Transform.Transformers
.AliasToBean(typeof(StudentDTO)))
.List();

In this query is visible that I must SetProjections, and Add
Projectons (Mapping between DTO and DomainClass).
Am I wrong?

On Jul 30, 9:44 am, kor korkl...@yahoo.it wrote:
 i don't understand very well what you need,

 with this
 criteria.SetResultTransformer (new
 EntityToBeanTransformer(typeof(YourDto))

 you can return an object not mapped in the xml, if it's not what you
 need can explain better what you want?

-- 
You received this message because you are subscribed to the Google Groups 
nhusers group.
To post to this group, send email to nhus...@googlegroups.com.
To unsubscribe from this group, send email to 
nhusers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.



[nhusers] NHibernate in Windows Workflow Foundation

2010-07-30 Thread Zhen Lin
I'm looking to use NHibernate as my database access layer inside a WF
workflow. At the moment, I have a singleton workflow extension (one
per workflow service host) which holds the session factory. However, I
ran into a problem trying to implement a CurrentSessionContext
provider - there doesn't seem to be an easy way to obtain the workflow
instance of the current thread. I've resorted to using a thread-local
session context (my own implementation using .NET 4.0's ThreadLocalT
- which is an IDisposable - does the SessionFactory support
IDisposable CurrentSessionContext providers?) for the time being, but
I suspect that's fragile and likely to break for the same reasons as
in ASP.NET.

I've also implemented a CurrentSessionContext provider using the
InstanceContext of the current WCF OperationContext, but that's not
useful in WF since workflows can execute outside the context of a WCF
operation.

-- 
You received this message because you are subscribed to the Google Groups 
nhusers group.
To post to this group, send email to nhus...@googlegroups.com.
To unsubscribe from this group, send email to 
nhusers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.



[nhusers] Where to report bugs about db2hbm? ManyToOneStrategy.WireManyToOnes gives an exception.

2010-07-30 Thread Sebastian Andersson
I've not been able to figure out where to file a bug report for
db2hbm.

I've found a bug in either db2hbm or SQL Server 2005.

The problem is that the SQL code in
MSSQLForeignKeyCrawler.GetForeignKeyColumns doesn't return any rows
for some FKs.

I've got this FK in my DB:

ALTER TABLE [dbo].[verConsecutiveEntityVersion]  WITH CHECK ADD
CONSTRAINT
[FKAUTO_verConsecutiveEntityVersion_verDataSet_UsesDataSetSid_DataSetExists]
FOREIGN KEY([UsesDataSetSid], [IsOfEntityTypeNumber])
REFERENCES [dbo].[verDataSet] ([Sid], [IsForEntityTypeNumber])

When using the INFORMATION_SCHEMA to find it, the
UNIQUE_CONSTRAINT_NAME returns 'UX_verDataSet', which is not present
in INFORMATION_SCHEMA.KEY_COLUMN_USAGE and the inner join for KCU2
does not match anything, later leading to an exception in
ManyToOneStrategy.WireManyToOnes: string referredTable =
keyManyToOne.First().PrimaryKeyTableName;


I changed the SQL to:
SELECT f.name AS 'FK_CONSTRAINT_NAME',
   OBJECT_NAME(f.parent_object_id) AS 'FK_TABLE_NAME',
   @p1 AS 'FK_TABLE_CATALOG',
   OBJECT_SCHEMA_NAME(f.parent_object_id) AS 'FK_TABLE_SCHEMA',
   COL_NAME(fc.parent_object_id, fc.parent_column_id) AS
'FK_COLUMN_NAME',
   fc.constraint_column_id AS 'FK_ORDINAL_POSITION',
   NULL AS 'UQ_CONSTRAINT_NAME',
   OBJECT_NAME(f.referenced_object_id) AS 'UQ_TABLE_NAME',
   @p1 AS 'UQ_TABLE_CATALOG',
   OBJECT_SCHEMA_NAME(f.parent_object_id) AS 'UQ_TABLE_SCHEMA',
   COL_NAME(fc.referenced_object_id, fc.referenced_column_id) AS
'UQ_COLUMN_NAME',
   fc.referenced_column_id AS 'UQ_ORDINAL_POSITION'
FROM sys.foreign_keys AS f
LEFT JOIN sys.foreign_key_columns AS fc
   ON f.OBJECT_ID = fc.constraint_object_id
WHERE f.na...@p0
AND SCHEMA_NAME(f.schema_id) = @p2

and changed the code for the query to change to the correct database.
This seemed to work for me, but I know too little about SQL Server to
know if this is close to correct (and the returned NULL value is
obviously not correct).

-- 
You received this message because you are subscribed to the Google Groups 
nhusers group.
To post to this group, send email to nhus...@googlegroups.com.
To unsubscribe from this group, send email to 
nhusers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.



[nhusers] Re: Inserting a Primary Key value into the database

2010-07-30 Thread Jason Meckley
@Stephen
did you allow NH to generate the db schema for you, or are you trying
to retro fit a legacy database to use hilo? When you select the hilo
PIOD strategy it expects the actual table you are mapping to and a
second table where the HiLo seed is stored by default it's named
hibernate_unique_key with a single column max_lo. you can over ride
the table name and column name if you want. for example I override the
table name for each entity that uses hilo. this way each entity has
it's own set of high low values. otherwise all entities get there
max_lo seed from the same table.

if this isn't enough to help you solve the problem please start
another thread.

On Jul 30, 12:25 am, Stephen Karl skarl...@gmail.com wrote:
 Hi Jason,

 I'm in the middle of Chapter 5 of the NHibernate 2 Beginner's Guide,
 specifically the end of page 97.  When I try to run the console project, I
 get the following runtime error at the session.Save line:
 could not get or update next value[SQL: ]

 The inner exception is Invalid object name 'hibernate_unique_key'.
 That error is encountered when I have the generator class set to 'hilo.'

 I'm currently using a SQL Server 2008 Express database with this project.
 The tables do NOT have an auto-sequenced number at the moment.

 When I changed the generator class to increment, I was able to
 successfully save the object to the database table.

 Any ideas why 'hilo' isn't good in this situation?  (This was the value
 recommended in the book/associated source code.)

 Stephen

 On Thu, Jul 29, 2010 at 10:40 AM, Jason Dentler jasondent...@gmail.comwrote:

  Frans,

  Sorry. I was referring to Identity in terms of SQL Server, as this is the
  database referred to in the NHibernate beginner's book. This particular POID
  generator, and it's cousin, Native on SQL server require the data to be
  inserted in order to generate an ID. This breaks batching, as the
  session.Save, etc. will put data in the database rather than waiting for
  transaction.Commit (or session.Flush, which IMO, should be considered
  deprecated when using flush-on-commit, the default)

  Compare that with hilo, which also doesn't allow duplicates when
  transactions are used properly, doesn't break batching, and even better,
  doesn't require a trip to the database for every insert; just one trip to
  flush the session.

  As I understand it, on Oracle, native works just fine because it's
  equivalent to sequence. It does require an extra trip to the database for
  every insert, but only to fetch an id value, not to insert data. I'm not
  sure if Identity is available on Oracle, if it has a different meaning than
  sequence, or if it's just silently converted to sequence. I'm a SQL guy.

  In any case, I'd like to know what exception Stephen encountered before
  guessing about the root cause.

  Thanks,
  Jason

  On Thu, Jul 29, 2010 at 10:21 AM, John Davidson jwdavid...@gmail.comwrote:

  Yes, please create a test and try it

  John Davidson

  On Thu, Jul 29, 2010 at 11:18 AM, Frans Bouma fr...@sd.nl wrote:

   the issue with identity is that it causes two trips to the database for
   every save of a new record and their are complications with Flush

          hmm, are you sure? the new identity value is requested by a
  batched
  SCOPE_IDENTITY() select right after the insert, same roundtrip as the
  insert, and it can then immediately be synced with related (fk side)
  entities. HiLo requires an extra roundtrip for the new value to obtain
  and
  insert, as that is required to obtain the new hilo using the sql posted
  by
  jason. Or am I missing something?

                 FB

   John Davidson

   On Thu, Jul 29, 2010 at 10:51 AM, Frans Bouma fr...@sd.nl wrote:

          2 separate clients accessing the same database using HiLo will
  not
   grab
          duplicate hi values.

          when the next_hi is retrieved by the session factory the
  following
   2
          statements are executed.
          select next_hi from hilo_table (with lock) update hilo_table
  set
   next_hi =
          next_hi + 1 where next_hi = @p0 (with update lock)

          ...or something like that. between these statements and having
  the
         operation
          within a transaction there is little (if any) chance of 2
  factories
         pulling
          the same next_hi value.

                thanks Jason :) It's indeed highly unlikely that the
  number
  is
         issued twice, although I fail to see why this is better than
   Identity,
         considering that this table row is locked _alot_ and many inserts
   thus will
         have a serious impact on performance here. On Oracle for example,
  you
   can
         achieve the same thing by using the same sequence on all tables,
   without the
         penalty. :)

                        FB

          On Jul 29, 10:15 am, Frans Bouma fr...@sd.nl wrote:
        hilo uses a lock to ensure 2 factories don't pull the same
  hi
   value.

                   a 

Re: [nhusers] Re: Inserting a Primary Key value into the database

2010-07-30 Thread Jason Dentler
Hi Stephen,

Thanks for pointing this out. It is an oversight in the book.

You see, the drafts of the book used Identity. However, for the reasons
pointed out previously, we (the book's technical reviewers) strongly
suggested the author switch to hilo.

Because the book takes the database first approach (I'm not a fan of this
approach, by the way), the schema isn't generated from the model  mappings.
It's built by hand. When the author switched the book from Identity to Hilo,
he failed to add the necessary steps for creating the hilo table.

The fix is simple. You can manually create the table as Frans suggested.
Alternatively, as Jason M suggested, use hbm2ddl to generate your database
schema. The hilo table will be included. Either will accomplish our goal.

Thanks,
Jason

On Fri, Jul 30, 2010 at 5:52 AM, Jason Meckley jasonmeck...@gmail.comwrote:

 @Stephen
 did you allow NH to generate the db schema for you, or are you trying
 to retro fit a legacy database to use hilo? When you select the hilo
 PIOD strategy it expects the actual table you are mapping to and a
 second table where the HiLo seed is stored by default it's named
 hibernate_unique_key with a single column max_lo. you can over ride
 the table name and column name if you want. for example I override the
 table name for each entity that uses hilo. this way each entity has
 it's own set of high low values. otherwise all entities get there
 max_lo seed from the same table.

 if this isn't enough to help you solve the problem please start
 another thread.

 On Jul 30, 12:25 am, Stephen Karl skarl...@gmail.com wrote:
  Hi Jason,
 
  I'm in the middle of Chapter 5 of the NHibernate 2 Beginner's Guide,
  specifically the end of page 97.  When I try to run the console project,
 I
  get the following runtime error at the session.Save line:
  could not get or update next value[SQL: ]
 
  The inner exception is Invalid object name 'hibernate_unique_key'.
  That error is encountered when I have the generator class set to 'hilo.'
 
  I'm currently using a SQL Server 2008 Express database with this project.
  The tables do NOT have an auto-sequenced number at the moment.
 
  When I changed the generator class to increment, I was able to
  successfully save the object to the database table.
 
  Any ideas why 'hilo' isn't good in this situation?  (This was the value
  recommended in the book/associated source code.)
 
  Stephen
 
  On Thu, Jul 29, 2010 at 10:40 AM, Jason Dentler jasondent...@gmail.com
 wrote:
 
   Frans,
 
   Sorry. I was referring to Identity in terms of SQL Server, as this is
 the
   database referred to in the NHibernate beginner's book. This particular
 POID
   generator, and it's cousin, Native on SQL server require the data to be
   inserted in order to generate an ID. This breaks batching, as the
   session.Save, etc. will put data in the database rather than waiting
 for
   transaction.Commit (or session.Flush, which IMO, should be considered
   deprecated when using flush-on-commit, the default)
 
   Compare that with hilo, which also doesn't allow duplicates when
   transactions are used properly, doesn't break batching, and even
 better,
   doesn't require a trip to the database for every insert; just one trip
 to
   flush the session.
 
   As I understand it, on Oracle, native works just fine because it's
   equivalent to sequence. It does require an extra trip to the database
 for
   every insert, but only to fetch an id value, not to insert data. I'm
 not
   sure if Identity is available on Oracle, if it has a different meaning
 than
   sequence, or if it's just silently converted to sequence. I'm a SQL
 guy.
 
   In any case, I'd like to know what exception Stephen encountered before
   guessing about the root cause.
 
   Thanks,
   Jason
 
   On Thu, Jul 29, 2010 at 10:21 AM, John Davidson jwdavid...@gmail.com
 wrote:
 
   Yes, please create a test and try it
 
   John Davidson
 
   On Thu, Jul 29, 2010 at 11:18 AM, Frans Bouma fr...@sd.nl wrote:
 
the issue with identity is that it causes two trips to the database
 for
every save of a new record and their are complications with Flush
 
   hmm, are you sure? the new identity value is requested by a
   batched
   SCOPE_IDENTITY() select right after the insert, same roundtrip as the
   insert, and it can then immediately be synced with related (fk side)
   entities. HiLo requires an extra roundtrip for the new value to
 obtain
   and
   insert, as that is required to obtain the new hilo using the sql
 posted
   by
   jason. Or am I missing something?
 
  FB
 
John Davidson
 
On Thu, Jul 29, 2010 at 10:51 AM, Frans Bouma fr...@sd.nl wrote:
 
   2 separate clients accessing the same database using HiLo
 will
   not
grab
   duplicate hi values.
 
   when the next_hi is retrieved by the session factory the
   following
2
   statements are executed.
   select next_hi from hilo_table (with 

[nhusers] Re: CreateCriteria Issue

2010-07-30 Thread William
When the query is run by hand against Oracle - it returns 72 unique
rows.  I am a newby with NHibernate and can't figure out what is wrong
with the statement.  All the examples that I look at seem to be
written the same way.

On Jul 30, 3:52 am, kor korkl...@yahoo.it wrote:
 try to do that query by hand, maybe in the Profile table you have 72
 rows with the same values

-- 
You received this message because you are subscribed to the Google Groups 
nhusers group.
To post to this group, send email to nhus...@googlegroups.com.
To unsubscribe from this group, send email to 
nhusers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.



RE: [nhusers] Re: CreateCriteria Issue

2010-07-30 Thread Richard Wilde
When you run this in Oracle, what do you get back?

SELECT 
this_.USER_ID as USER1_12_0_, 
this_.RIGHTS_ID as RIGHTS2_12_0_, 
this_.FUNCTIONAL_AREA as FUNCTIONAL3_12_0_, 
this_.PERM_RIGHTS_ID as PERM4_12_0_ 
FROM 
PROFILE this_ 
WHERE this_.USER_ID = 7943

Rippo

-Original Message-
From: nhusers@googlegroups.com [mailto:nhus...@googlegroups.com] On Behalf
Of William
Sent: 30 July 2010 13:29
To: nhusers
Subject: [nhusers] Re: CreateCriteria Issue

When the query is run by hand against Oracle - it returns 72 unique
rows.  I am a newby with NHibernate and can't figure out what is wrong
with the statement.  All the examples that I look at seem to be
written the same way.

On Jul 30, 3:52 am, kor korkl...@yahoo.it wrote:
 try to do that query by hand, maybe in the Profile table you have 72
 rows with the same values

-- 
You received this message because you are subscribed to the Google Groups
nhusers group.
To post to this group, send email to nhus...@googlegroups.com.
To unsubscribe from this group, send email to
nhusers+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
nhusers group.
To post to this group, send email to nhus...@googlegroups.com.
To unsubscribe from this group, send email to 
nhusers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.



[nhusers] Re: CreateCriteria Issue

2010-07-30 Thread William
When run in Oracle I get 72 records for User id = 7943.  The
functional areas are all unique.  In the table each user id has 72
entries to cover the areas of the application.  The query returns the
proper records, but for some reason when I run it in the code - I am
only getting the first entry 72 times.

On Jul 30, 9:00 am, Richard Wilde rich...@wildesoft.net wrote:
 When you run this in Oracle, what do you get back?

 SELECT
         this_.USER_ID as USER1_12_0_,
         this_.RIGHTS_ID as RIGHTS2_12_0_,
         this_.FUNCTIONAL_AREA as FUNCTIONAL3_12_0_,
         this_.PERM_RIGHTS_ID as PERM4_12_0_
 FROM
         PROFILE this_
 WHERE this_.USER_ID = 7943

 Rippo



 -Original Message-
 From: nhusers@googlegroups.com [mailto:nhus...@googlegroups.com] On Behalf

 Of William
 Sent: 30 July 2010 13:29
 To: nhusers
 Subject: [nhusers] Re: CreateCriteria Issue

 When the query is run by hand against Oracle - it returns 72 unique
 rows.  I am a newby with NHibernate and can't figure out what is wrong
 with the statement.  All the examples that I look at seem to be
 written the same way.

 On Jul 30, 3:52 am, kor korkl...@yahoo.it wrote:
  try to do that query by hand, maybe in the Profile table you have 72
  rows with the same values

 --
 You received this message because you are subscribed to the Google Groups
 nhusers group.
 To post to this group, send email to nhus...@googlegroups.com.
 To unsubscribe from this group, send email to
 nhusers+unsubscr...@googlegroups.com.
 For more options, visit this group 
 athttp://groups.google.com/group/nhusers?hl=en.- Hide quoted text -

 - Show quoted text -

-- 
You received this message because you are subscribed to the Google Groups 
nhusers group.
To post to this group, send email to nhus...@googlegroups.com.
To unsubscribe from this group, send email to 
nhusers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.



AW: [nhusers] How to map an objectified Many to Many relationship?

2010-07-30 Thread Michael Möhle
Hi Fabio,

would you like to post an example here? I am trying the same thing ;-)

 

Michael

 

Von: nhusers@googlegroups.com [mailto:nhus...@googlegroups.com] Im Auftrag
von Fabio Maulo
Gesendet: Montag, 26. Juli 2010 16:53
An: nhusers@googlegroups.com
Betreff: Re: [nhusers] How to map an objectified Many to Many relationship?

 

Frans.

Can you send me a private mail with classes and scrip to create tables ?

Please simplified

I'll then add the Order.Products readonly collection.

btw have a look to loader

On Mon, Jul 26, 2010 at 11:41 AM, Frans Bouma fr...@sd.nl wrote:

Hi,

Consider Northwind. It has several objectified many to many (m:n)
relationships: Customer m:n Employee (via Order) and Order m:n Product (via
OrderDetails).

'objectified relationship' is a NIAM/ORM (object role modeling) term, see
http://www.orm.net, and it means that a m:n relationship on itself is an
entity with its own attributes (fields).

In the examples above, Order and OrderDetails are normal entities with
non-pk fields. So let's pick Order m:n Product in Northwind. This
relationship is defined on two m:1 relationships:
- OrderDetails m:1 Order
and
- OrderDetails m:1 Product

I can define for each entity a class and map it into their table in
Northwind, define the two m:1 relationships as well and all is well.

But I also want to define the m:n relationship Order m:n Product, so I can
fetch the products of an order without fetching Order Details and without
the necessity of formulating the joins, like:
var products = myOrder.Products;

which, through lazy loading, should create a query like (I use '*' but you
get the idea)
SELECT DISTINCT p.*
FROMProducts p INNER JOIN [Order Details] od ON p.ProductId =
od.ProductId
  INNER JOIN Orders o ON od.OrderId = o.OrderId
WHERE  o.OrderId = @orderId

(yes this can be made more efficient, that's irrelevant now)

My o/r mapper supports this, also in queries with filters etc. and my
designer does as well. I wanted to support these relationships for
NHibernate in my designer as well, but couldn't find any info about how to
map Order.Products in such a way that I get the above query. I only could
find information about mapping a 'pure' m:n relationship, so with an
intermediate table which isn't an entity and doesn't have a class mapped
onto it. Typical example of a pure m:n relationship: User m:n Group, where a
3rd, 'hidden', table is present in the db, UserGroup, which has two m:1
relationships, and only PK fields which are the FK fields to resp. User and
Group.

So, my questions are:
1) is mapping Order.Products supported in NHibernate?
2) if so, how to map Order.Products ?

I know that Order.Products is 'readonly' as adding a product there requires
an OrderDetails instance as well, so this might be the reason it's _not_
supported, but I'd like to know for sure.

TIA,

   Frans


Lead developer of LLBLGen Pro, .NET's most advanced O/R mapping designer.
LLBLGen Pro website: http://www.llblgen.com
Blog: http://weblogs.asp.net/fbouma
Twitter: http://twitter.com/FransBouma
Microsoft MVP (C#).



--
You received this message because you are subscribed to the Google Groups
nhusers group.
To post to this group, send email to nhus...@googlegroups.com.
To unsubscribe from this group, send email to
nhusers+unsubscr...@googlegroups.com
mailto:nhusers%2bunsubscr...@googlegroups.com .
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en.




-- 
Fabio Maulo

-- 
You received this message because you are subscribed to the Google Groups
nhusers group.
To post to this group, send email to nhus...@googlegroups.com.
To unsubscribe from this group, send email to
nhusers+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
nhusers group.
To post to this group, send email to nhus...@googlegroups.com.
To unsubscribe from this group, send email to 
nhusers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.



[nhusers] Re: CreateCriteria Issue

2010-07-30 Thread kor
when you do the test and call this code

return Session
.CreateCriteriaProfile()
.Add(Restrictions.Eq(UserId, id))
.ListProfile();

this  is the only code that you calls?

i mean that before it you don't work with nhibernate session and that
after you check directly the list that has been returnd by
ListProfile()?

the returned items have the same id or different id but the same
values?

do you use same 2-level cache?

-- 
You received this message because you are subscribed to the Google Groups 
nhusers group.
To post to this group, send email to nhus...@googlegroups.com.
To unsubscribe from this group, send email to 
nhusers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.



[nhusers] Many-to-one relationship do not delete orphan children.

2010-07-30 Thread Jacob Madsen
Hi all,

I can't see why the orphans doesn't get delete, when cascade is set to
all in the many-to-one xml-element.

I have this mapping of an aggregate entity (table test_aggregates) and
child entity (table test_reference_entities):

hibernate-mapping xmlns=urn:nhibernate-mapping-2.2 default-
access=property auto-import=true default-cascade=save-update
default-lazy=false
  class xmlns=urn:nhibernate-mapping-2.2 lazy=false
mutable=true name=TestAggregate, Tests, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null table=test_aggregates
id access=backfield name=Id type=System.Int64, mscorlib,
Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
  column name=id /
  generator class=hilo
param name=max_lo100/param
  /generator
/id
many-to-one cascade=all
class=Namic.Being.Framework.Tests.Database.TestReferenceEntity,
Namic.Being.Framework.Tests, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null name=ReferenceEntity
  column name=ReferenceEntity_id /
/many-to-one
  /class
/hibernate-mapping


hibernate-mapping xmlns=urn:nhibernate-mapping-2.2 default-
access=property auto-import=true default-cascade=save-update
default-lazy=false
  class xmlns=urn:nhibernate-mapping-2.2 lazy=false
mutable=true name=TestReferenceEntity, Tests, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null table=test_reference_entities
id access=backfield name=Id type=System.Int64, mscorlib,
Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
  column name=id /
  generator class=hilo
param name=max_lo100/param
  /generator
/id
  /class
/hibernate-mapping


Cheers!

-- 
You received this message because you are subscribed to the Google Groups 
nhusers group.
To post to this group, send email to nhus...@googlegroups.com.
To unsubscribe from this group, send email to 
nhusers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.



[nhusers] Optimizing too many joins

2010-07-30 Thread marek
[I posted that to old NH Users forum too (https://forum.hibernate.org/
viewtopic.php?f=25t=1006127) - sorry for double post, just realized
you moved here...]

Hello,

I have quite complex database model, an Ad has a collection of
Details, every Detail has reference to Parameter, a Parameter belongs
to a Group and to a Field.
A Field has OptionItems and Units.
OptionItem, Unit and a Group have Translations collection.
There are more relations, but these mentioned above are the most
relevant.

I need to get efficiently full object graph for specific Ad. My
solution gets it in one query, but there are too many joins and I get
a cartesian product.

My query:
[code]
var ad = _session.CreateCriteriaAd(ad)
//Address with Country and Country Translations
.CreateAlias(Address, address,
JoinType.LeftOuterJoin)
.SetFetchMode(address, FetchMode.Eager)
.CreateAlias(address.Country, country,
JoinType.LeftOuterJoin)
.SetFetchMode(country, FetchMode.Eager)
.CreateAlias(country.Translations,
countryTranslations, JoinType.LeftOuterJoin)
.SetFetchMode(countryTranslations, FetchMode.Eager)
//Details
.CreateAlias(Details, details,
JoinType.LeftOuterJoin)
.SetFetchMode(details, FetchMode.Eager)
//Parameter
.CreateAlias(details.Parameter, parameter,
JoinType.LeftOuterJoin)
.SetFetchMode(parameter, FetchMode.Eager)
//Group with Translations
.CreateAlias(parameter.Group, group,
JoinType.LeftOuterJoin)
.SetFetchMode(group, FetchMode.Eager)
.CreateAlias(group.Translations,
groupTranslations, JoinType.LeftOuterJoin)
.SetFetchMode(groupTranslations, FetchMode.Eager)
//Field
.CreateAlias(parameter.Field, field,
JoinType.LeftOuterJoin)
.SetFetchMode(field, FetchMode.Eager)
.CreateAlias(field.Translations,
fieldTranslations, JoinType.LeftOuterJoin)
.SetFetchMode(fieldTranslations, FetchMode.Eager)
//OptionItems with translations
.CreateAlias(field.OptionItems, optionItems,
JoinType.LeftOuterJoin)
.SetFetchMode(optionItems, FetchMode.Eager)
.CreateAlias(optionItems.Translations,
optionItemTranslations, JoinType.LeftOuterJoin)
.SetFetchMode(optionItemTranslations,
FetchMode.Eager)
//Units with translations
.CreateAlias(field.Units, unit,
JoinType.LeftOuterJoin)
.SetFetchMode(unit, FetchMode.Eager)
.CreateAlias(unit.Translations, unitTranslations,
JoinType.LeftOuterJoin)
.SetFetchMode(unitTranslations, FetchMode.Eager)
.CreateAlias(Images, images,
JoinType.LeftOuterJoin)
.SetFetchMode(images, FetchMode.Eager)
.CreateAlias(Make, make, JoinType.LeftOuterJoin)
.SetFetchMode(make, FetchMode.Eager)
.CreateAlias(make.Models, model,
JoinType.LeftOuterJoin)
.SetFetchMode(model, FetchMode.Eager)
.SetResultTransformer(new
DistinctRootEntityResultTransformer())
.Add(Restrictions.Eq(Id, id))
.UniqueResultAd();
[/code]

As you can see it gets huge... And not really efficient.
Any ideas how to optimize it using NHibernate?

Thanks in advance.
Marek

-- 
You received this message because you are subscribed to the Google Groups 
nhusers group.
To post to this group, send email to nhus...@googlegroups.com.
To unsubscribe from this group, send email to 
nhusers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.



[nhusers] Re: Optimizing too many joins

2010-07-30 Thread fknebels
Have you seen this post

http://ayende.com/Blog/archive/2010/01/16/eagerly-loading-entity-associations-efficiently-with-nhibernate.aspx

I used this technique with pretty good success.

On Jul 30, 10:21 am, marek marek.stach...@googlemail.com wrote:
 [I posted that to old NH Users forum too (https://forum.hibernate.org/
 viewtopic.php?f=25t=1006127) - sorry for double post, just realized
 you moved here...]

 Hello,

 I have quite complex database model, an Ad has a collection of
 Details, every Detail has reference to Parameter, a Parameter belongs
 to a Group and to a Field.
 A Field has OptionItems and Units.
 OptionItem, Unit and a Group have Translations collection.
 There are more relations, but these mentioned above are the most
 relevant.

 I need to get efficiently full object graph for specific Ad. My
 solution gets it in one query, but there are too many joins and I get
 a cartesian product.

 My query:
 [code]
 var ad = _session.CreateCriteriaAd(ad)
                 //Address with Country and Country Translations
                 .CreateAlias(Address, address,
 JoinType.LeftOuterJoin)
                 .SetFetchMode(address, FetchMode.Eager)
                 .CreateAlias(address.Country, country,
 JoinType.LeftOuterJoin)
                 .SetFetchMode(country, FetchMode.Eager)
                 .CreateAlias(country.Translations,
 countryTranslations, JoinType.LeftOuterJoin)
                 .SetFetchMode(countryTranslations, FetchMode.Eager)
                 //Details
                 .CreateAlias(Details, details,
 JoinType.LeftOuterJoin)
                 .SetFetchMode(details, FetchMode.Eager)
                 //Parameter
                 .CreateAlias(details.Parameter, parameter,
 JoinType.LeftOuterJoin)
                 .SetFetchMode(parameter, FetchMode.Eager)
                 //Group with Translations
                 .CreateAlias(parameter.Group, group,
 JoinType.LeftOuterJoin)
                 .SetFetchMode(group, FetchMode.Eager)
                 .CreateAlias(group.Translations,
 groupTranslations, JoinType.LeftOuterJoin)
                 .SetFetchMode(groupTranslations, FetchMode.Eager)
                 //Field
                 .CreateAlias(parameter.Field, field,
 JoinType.LeftOuterJoin)
                 .SetFetchMode(field, FetchMode.Eager)
                 .CreateAlias(field.Translations,
 fieldTranslations, JoinType.LeftOuterJoin)
                 .SetFetchMode(fieldTranslations, FetchMode.Eager)
                 //OptionItems with translations
                 .CreateAlias(field.OptionItems, optionItems,
 JoinType.LeftOuterJoin)
                 .SetFetchMode(optionItems, FetchMode.Eager)
                 .CreateAlias(optionItems.Translations,
 optionItemTranslations, JoinType.LeftOuterJoin)
                 .SetFetchMode(optionItemTranslations,
 FetchMode.Eager)
                 //Units with translations
                 .CreateAlias(field.Units, unit,
 JoinType.LeftOuterJoin)
                 .SetFetchMode(unit, FetchMode.Eager)
                 .CreateAlias(unit.Translations, unitTranslations,
 JoinType.LeftOuterJoin)
                 .SetFetchMode(unitTranslations, FetchMode.Eager)
                 .CreateAlias(Images, images,
 JoinType.LeftOuterJoin)
                 .SetFetchMode(images, FetchMode.Eager)
                 .CreateAlias(Make, make, JoinType.LeftOuterJoin)
                 .SetFetchMode(make, FetchMode.Eager)
                 .CreateAlias(make.Models, model,
 JoinType.LeftOuterJoin)
                 .SetFetchMode(model, FetchMode.Eager)
                 .SetResultTransformer(new
 DistinctRootEntityResultTransformer())
                 .Add(Restrictions.Eq(Id, id))
                 .UniqueResultAd();
 [/code]

 As you can see it gets huge... And not really efficient.
 Any ideas how to optimize it using NHibernate?

 Thanks in advance.
 Marek

-- 
You received this message because you are subscribed to the Google Groups 
nhusers group.
To post to this group, send email to nhus...@googlegroups.com.
To unsubscribe from this group, send email to 
nhusers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.



Re: [nhusers] Re: Dynamic query to DTO

2010-07-30 Thread Fabio Maulo
Luka,
are you using Criteria even for static queries ?

On Fri, Jul 30, 2010 at 7:32 AM, Luka cluk...@gmail.com wrote:

 I read that I need to speccify mappings (projections) in the query
 like this:
 IList resultWithAliasedBean = s.CreateCriteria(typeof(Enrolment))
  .CreateAlias(Student, st)
  .CreateAlias(Course, co)
  .SetProjection(Projections.ProjectionList()
  .Add(Projections.Property(st.Name), studentName)
  .Add(Projections.Property(co.Description),
 courseDescription)
 )
 .AddOrder(Order.Desc(studentName))
 .SetResultTransformer(NHibernate.Transform.Transformers
 .AliasToBean(typeof(StudentDTO)))
 .List();

 In this query is visible that I must SetProjections, and Add
 Projectons (Mapping between DTO and DomainClass).
 Am I wrong?

 On Jul 30, 9:44 am, kor korkl...@yahoo.it wrote:
  i don't understand very well what you need,
 
  with this
  criteria.SetResultTransformer (new
  EntityToBeanTransformer(typeof(YourDto))
 
  you can return an object not mapped in the xml, if it's not what you
  need can explain better what you want?

 --
 You received this message because you are subscribed to the Google Groups
 nhusers group.
 To post to this group, send email to nhus...@googlegroups.com.
 To unsubscribe from this group, send email to
 nhusers+unsubscr...@googlegroups.comnhusers%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/nhusers?hl=en.




-- 
Fabio Maulo

-- 
You received this message because you are subscribed to the Google Groups 
nhusers group.
To post to this group, send email to nhus...@googlegroups.com.
To unsubscribe from this group, send email to 
nhusers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.



Re: [nhusers] CreateCriteria Issue

2010-07-30 Thread Fabio Maulo
Class impl, please.

On Thu, Jul 29, 2010 at 12:01 PM, William wlangb...@paychex.com wrote:

 I am having an issue with query below:
return Session
.CreateCriteriaProfile()
.Add(Restrictions.Eq(UserId, id))
.ListProfile();

 This should return 72 records from a table based on the User Id.  What
 is being returned to the c# is 72 copies of the first record.  Here is
 the query that NUnit is indicating is being run:
 SELECT this_.USER_ID as USER1_12_0_, this_.RIGHTS_ID as RIGHTS2_12_0_,
 this_.FUNCTIONAL_AREA as FUNCTIONAL3_12_0_, this_.PERM_RIGHTS_ID as
 PERM4_12_0_ FROM PROFILE this_ WHERE this_.USER_ID = :p0;:p0 = 7943

 --
 You received this message because you are subscribed to the Google Groups
 nhusers group.
 To post to this group, send email to nhus...@googlegroups.com.
 To unsubscribe from this group, send email to
 nhusers+unsubscr...@googlegroups.comnhusers%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/nhusers?hl=en.




-- 
Fabio Maulo

-- 
You received this message because you are subscribed to the Google Groups 
nhusers group.
To post to this group, send email to nhus...@googlegroups.com.
To unsubscribe from this group, send email to 
nhusers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.



[nhusers] Re: Possible to map some properties on entity from json column

2010-07-30 Thread mcintyre321
bumpety-bump!

On Jul 26, 10:49 am, mcintyre321 mcintyre...@gmail.com wrote:
 I want to be able to add new properties to an entity without having to
 define schema for them, and have them all persist to a single db
 column.

 Unless I'm mistaken about their capabilities, I'm not sure an
 IUserType is what I'm after - I previously wrote an XML serialized
 generic UserType before, but what that did was map 1 property - 1 db
 column. I want to map n properties to 1 column.

 On Jul 23, 6:30 pm, Fabio Maulo fabioma...@gmail.com wrote:



  No Jason... it is very easy... IUserType
  Note: He said map some properties of an entity

  On Fri, Jul 23, 2010 at 1:23 PM, Jason Dentler 
  jasondent...@gmail.comwrote:

   I'm sure you can do this with some seriously heavy lifting, like writing a
   custom persister, but it would be easier to map this to some field in your
   entity and then parse it.

   On Fri, Jul 23, 2010 at 11:15 AM,mcintyre321mcintyre...@gmail.comwrote:

   I've been wondering if its possible to have NH map some properties on
   an entity from a schema-free json (or xml) column

   e.g. map a db table like
   Id, Name, Json
   1, Marmaduke, {address1: Windsor Castle, address2: London }

   to a class like

   class Person{
      int Id{get;set;}
      string Name {get;set;}
      string Address1 {get;set;}
      string Address2 {get;set;}
   }

   Is there a way to do this, or an extension point I could use to enable
   this?

   --
   You received this message because you are subscribed to the Google Groups
   nhusers group.
   To post to this group, send email to nhus...@googlegroups.com.
   To unsubscribe from this group, send email to
   nhusers+unsubscr...@googlegroups.comnhusers%2bunsubscr...@googlegroups.com

   .
   For more options, visit this group at
  http://groups.google.com/group/nhusers?hl=en.

    --
   You received this message because you are subscribed to the Google Groups
   nhusers group.
   To post to this group, send email to nhus...@googlegroups.com.
   To unsubscribe from this group, send email to
   nhusers+unsubscr...@googlegroups.comnhusers%2bunsubscr...@googlegroups.com

   .
   For more options, visit this group at
  http://groups.google.com/group/nhusers?hl=en.

  --
  Fabio Maulo

-- 
You received this message because you are subscribed to the Google Groups 
nhusers group.
To post to this group, send email to nhus...@googlegroups.com.
To unsubscribe from this group, send email to 
nhusers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.



Re: [nhusers] Re: Possible to map some properties on entity from json column

2010-07-30 Thread Fabio Maulo
Can you send a simple class and its persistent representation ?
thanks.

On Mon, Jul 26, 2010 at 6:49 AM, mcintyre321 mcintyre...@gmail.com wrote:

 I want to be able to add new properties to an entity without having to
 define schema for them, and have them all persist to a single db
 column.

 Unless I'm mistaken about their capabilities, I'm not sure an
 IUserType is what I'm after - I previously wrote an XML serialized
 generic UserType before, but what that did was map 1 property - 1 db
 column. I want to map n properties to 1 column.

 On Jul 23, 6:30 pm, Fabio Maulo fabioma...@gmail.com wrote:
  No Jason... it is very easy... IUserType
  Note: He said map some properties of an entity
 
  On Fri, Jul 23, 2010 at 1:23 PM, Jason Dentler jasondent...@gmail.com
 wrote:
 
 
 
 
 
   I'm sure you can do this with some seriously heavy lifting, like
 writing a
   custom persister, but it would be easier to map this to some field in
 your
   entity and then parse it.
 
   On Fri, Jul 23, 2010 at 11:15 AM, mcintyre321 mcintyre...@gmail.com
 wrote:
 
   I've been wondering if its possible to have NH map some properties on
   an entity from a schema-free json (or xml) column
 
   e.g. map a db table like
   Id, Name, Json
   1, Marmaduke, {address1: Windsor Castle, address2: London }
 
   to a class like
 
   class Person{
  int Id{get;set;}
  string Name {get;set;}
  string Address1 {get;set;}
  string Address2 {get;set;}
   }
 
   Is there a way to do this, or an extension point I could use to enable
   this?
 
   --
   You received this message because you are subscribed to the Google
 Groups
   nhusers group.
   To post to this group, send email to nhus...@googlegroups.com.
   To unsubscribe from this group, send email to
   nhusers+unsubscr...@googlegroups.comnhusers%2bunsubscr...@googlegroups.com
 nhusers%2bunsubscr...@googlegroups.comnhusers%252bunsubscr...@googlegroups.com
   .
   For more options, visit this group at
  http://groups.google.com/group/nhusers?hl=en.
 
--
   You received this message because you are subscribed to the Google
 Groups
   nhusers group.
   To post to this group, send email to nhus...@googlegroups.com.
   To unsubscribe from this group, send email to
   nhusers+unsubscr...@googlegroups.comnhusers%2bunsubscr...@googlegroups.com
 nhusers%2bunsubscr...@googlegroups.comnhusers%252bunsubscr...@googlegroups.com
   .
   For more options, visit this group at
  http://groups.google.com/group/nhusers?hl=en.
 
  --
  Fabio Maulo

 --
 You received this message because you are subscribed to the Google Groups
 nhusers group.
 To post to this group, send email to nhus...@googlegroups.com.
 To unsubscribe from this group, send email to
 nhusers+unsubscr...@googlegroups.comnhusers%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/nhusers?hl=en.




-- 
Fabio Maulo

-- 
You received this message because you are subscribed to the Google Groups 
nhusers group.
To post to this group, send email to nhus...@googlegroups.com.
To unsubscribe from this group, send email to 
nhusers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.



Re: [nhusers] How to map an objectified Many to Many relationship?

2010-07-30 Thread Fabio Maulo
What you are trying to do exactly ?

On Fri, Jul 30, 2010 at 10:24 AM, Michael Möhle moehl...@googlemail.comwrote:

  Hi Fabio,

 would you like to post an example here? I am trying the same thing ;-)



 Michael



 *Von:* nhusers@googlegroups.com [mailto:nhus...@googlegroups.com] *Im
 Auftrag von *Fabio Maulo
 *Gesendet:* Montag, 26. Juli 2010 16:53
 *An:* nhusers@googlegroups.com
 *Betreff:* Re: [nhusers] How to map an objectified Many to Many
 relationship?



 Frans.

 Can you send me a private mail with classes and scrip to create tables ?

 Please simplified

 I'll then add the Order.Products readonly collection.

 btw have a look to loader

 On Mon, Jul 26, 2010 at 11:41 AM, Frans Bouma fr...@sd.nl wrote:

 Hi,

 Consider Northwind. It has several objectified many to many (m:n)
 relationships: Customer m:n Employee (via Order) and Order m:n Product (via
 OrderDetails).

 'objectified relationship' is a NIAM/ORM (object role modeling) term, see
 http://www.orm.net, and it means that a m:n relationship on itself is an
 entity with its own attributes (fields).

 In the examples above, Order and OrderDetails are normal entities with
 non-pk fields. So let's pick Order m:n Product in Northwind. This
 relationship is defined on two m:1 relationships:
 - OrderDetails m:1 Order
 and
 - OrderDetails m:1 Product

 I can define for each entity a class and map it into their table in
 Northwind, define the two m:1 relationships as well and all is well.

 But I also want to define the m:n relationship Order m:n Product, so I can
 fetch the products of an order without fetching Order Details and without
 the necessity of formulating the joins, like:
 var products = myOrder.Products;

 which, through lazy loading, should create a query like (I use '*' but you
 get the idea)
 SELECT DISTINCT p.*
 FROMProducts p INNER JOIN [Order Details] od ON p.ProductId =
 od.ProductId
   INNER JOIN Orders o ON od.OrderId = o.OrderId
 WHERE  o.OrderId = @orderId

 (yes this can be made more efficient, that's irrelevant now)

 My o/r mapper supports this, also in queries with filters etc. and my
 designer does as well. I wanted to support these relationships for
 NHibernate in my designer as well, but couldn't find any info about how to
 map Order.Products in such a way that I get the above query. I only could
 find information about mapping a 'pure' m:n relationship, so with an
 intermediate table which isn't an entity and doesn't have a class mapped
 onto it. Typical example of a pure m:n relationship: User m:n Group, where
 a
 3rd, 'hidden', table is present in the db, UserGroup, which has two m:1
 relationships, and only PK fields which are the FK fields to resp. User and
 Group.

 So, my questions are:
 1) is mapping Order.Products supported in NHibernate?
 2) if so, how to map Order.Products ?

 I know that Order.Products is 'readonly' as adding a product there requires
 an OrderDetails instance as well, so this might be the reason it's _not_
 supported, but I'd like to know for sure.

 TIA,

Frans

 
 Lead developer of LLBLGen Pro, .NET's most advanced O/R mapping designer.
 LLBLGen Pro website: http://www.llblgen.com
 Blog: http://weblogs.asp.net/fbouma
 Twitter: http://twitter.com/FransBouma
 Microsoft MVP (C#).
 


 --
 You received this message because you are subscribed to the Google Groups
 nhusers group.
 To post to this group, send email to nhus...@googlegroups.com.
 To unsubscribe from this group, send email to
 nhusers+unsubscr...@googlegroups.comnhusers%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/nhusers?hl=en.




 --
 Fabio Maulo

 --
 You received this message because you are subscribed to the Google Groups
 nhusers group.
 To post to this group, send email to nhus...@googlegroups.com.
 To unsubscribe from this group, send email to
 nhusers+unsubscr...@googlegroups.comnhusers%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/nhusers?hl=en.

   --
 You received this message because you are subscribed to the Google Groups
 nhusers group.
 To post to this group, send email to nhus...@googlegroups.com.
 To unsubscribe from this group, send email to
 nhusers+unsubscr...@googlegroups.comnhusers%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/nhusers?hl=en.




-- 
Fabio Maulo

-- 
You received this message because you are subscribed to the Google Groups 
nhusers group.
To post to this group, send email to nhus...@googlegroups.com.
To unsubscribe from this group, send email to 
nhusers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.



[nhusers] Re: CreateCriteria Issue

2010-07-30 Thread William
The more research that I am doing into this is leading me to believe
that my mapping file is the problem.  Here is what I have:

public class ProfileMap : ClassMapProfile
{
public ProfileMap()
{
Id(x = x.UserId)
.Column(USER_ID)
.Not.Nullable();
Map(x = x.RightsId)
.Column(RIGHTS_ID)
.Not.Nullable();
Map(x = x.FunctionalArea)
.Column(FUNCTIONAL_AREA)
.Not.Nullable();
Map(x = x.PermanentRightsId)
.Column(PERM_RIGHTS_ID)
.Nullable();
}
}

Here is the entity:
   public class Profile
{
public virtual long UserId { get; set; }
public virtual int RightsId { get; set; }
public virtual string FunctionalArea { get; set; }
public virtual int PermanentRightsId { get; set; }
}


When I run my query using HQL the results are the same.  That is why I
am now thinking the issue is with the mapping, but I haven't yet found
any mapping examples that differ all that much.


On Jul 30, 11:48 am, Fabio Maulo fabioma...@gmail.com wrote:
 Class impl, please.





 On Thu, Jul 29, 2010 at 12:01 PM, William wlangb...@paychex.com wrote:
  I am having an issue with query below:
                 return Session
                     .CreateCriteriaProfile()
                     .Add(Restrictions.Eq(UserId, id))
                     .ListProfile();

  This should return 72 records from a table based on the User Id.  What
  is being returned to the c# is 72 copies of the first record.  Here is
  the query that NUnit is indicating is being run:
  SELECT this_.USER_ID as USER1_12_0_, this_.RIGHTS_ID as RIGHTS2_12_0_,
  this_.FUNCTIONAL_AREA as FUNCTIONAL3_12_0_, this_.PERM_RIGHTS_ID as
  PERM4_12_0_ FROM PROFILE this_ WHERE this_.USER_ID = :p0;:p0 = 7943

  --
  You received this message because you are subscribed to the Google Groups
  nhusers group.
  To post to this group, send email to nhus...@googlegroups.com.
  To unsubscribe from this group, send email to
  nhusers+unsubscr...@googlegroups.comnhusers%2bunsubscr...@googlegroups.com­
  .
  For more options, visit this group at
 http://groups.google.com/group/nhusers?hl=en.

 --
 Fabio Maulo- Hide quoted text -

 - Show quoted text -

-- 
You received this message because you are subscribed to the Google Groups 
nhusers group.
To post to this group, send email to nhus...@googlegroups.com.
To unsubscribe from this group, send email to 
nhusers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.



Re: [nhusers] Understanding Proxy Objects

2010-07-30 Thread Diego Mijelshon
http://ayende.com/Blog/archive/2009/09/03/answer-the-lazy-loaded-inheritance-many-to-one-association-orm.aspx

Diego


On Wed, Jul 28, 2010 at 10:14, alexey_baranov mias...@gmail.com wrote:

 Hi!

 I have simple class hierarchy. One superclass Obj and few subclasses

 class Obj{
public virtual string TypeName=Object;
 }

 class Person: Obj{
public override string TypeName=Person;
 }
 class Request:Obj{
   public override string TypeName=Servise request
   public virtual Obj Initier{get;set;} //Initier can be any Obj
 subclass like Person, Client, ...
 }

 In my code I have persisted Request inctance
 request= new Request{ Initier= new Person() };
 sess.Save(request);

 After loading this object back I have strange things:
 request.Initier.GetType().FullName == ObjProxyae6
 request.Initier.GetType().IsSubclassOf(typeof(Obj)) == true // so it
 is subclass of Obj
 request.Initier.GetType().IsSubclassOf(typeof(Person)) == false // it
 is not subclass of Person

 request.Initier.TypeName==Person  // !!!  I suppost it should be
 Object

 The question is: if ObjProxyae6. is not subclass of Person, why
 does it return TypeName==Person not Object?

 Thanks!

 --
 You received this message because you are subscribed to the Google Groups
 nhusers group.
 To post to this group, send email to nhus...@googlegroups.com.
 To unsubscribe from this group, send email to
 nhusers+unsubscr...@googlegroups.comnhusers%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/nhusers?hl=en.



-- 
You received this message because you are subscribed to the Google Groups 
nhusers group.
To post to this group, send email to nhus...@googlegroups.com.
To unsubscribe from this group, send email to 
nhusers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.



[nhusers] Re: NotNull and Unique String

2010-07-30 Thread Kminoru
I´m using NotNull:= false and Unique:=true. The problem occur when i
save an object that has empty string.

On 30 jul, 04:48, kor korkl...@yahoo.it wrote:
 if you need it on the database-side put in the mapping

 property name=MyStringPropertyName not-null=true unique=true /

 if you need it on the application-side you need to use a custom
 validation or an external validation framework (for example see
 nhibernate.validator)

-- 
You received this message because you are subscribed to the Google Groups 
nhusers group.
To post to this group, send email to nhus...@googlegroups.com.
To unsubscribe from this group, send email to 
nhusers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.



[nhusers] Re: Many-to-one relationship do not delete orphan children.

2010-07-30 Thread Aaron Fischer
cascade=all-delete-orphan

-- 
You received this message because you are subscribed to the Google Groups 
nhusers group.
To post to this group, send email to nhus...@googlegroups.com.
To unsubscribe from this group, send email to 
nhusers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.



[nhusers] linq child filtering

2010-07-30 Thread Aaron Fischer
I am using the nhibernate 3 alpha and have this basics query

var query = from record in session.QueryRecord()
   from brwSet in session.QueryBorrowerSet()
   from brw in session.QueryBorrower()
   where
   brw.PrintOrder == 1  brwSet.PrintOrder ==
0
   
record.Package.BorrowerSet.Contains( brwSet )
brwSet.Borrower.Contains( brw )
   select new Summary()
   {
   BorrowerFirstName =
brw.Contact.FirstName,
   BorrowerLastName =
brw.Contact.LastName,
   LoanPackageID = record.Id
   };

I would like to find a way to remove the two contains calls any
suggestions?

-- 
You received this message because you are subscribed to the Google Groups 
nhusers group.
To post to this group, send email to nhus...@googlegroups.com.
To unsubscribe from this group, send email to 
nhusers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.



Re: [nhusers] Re: Many-to-one relationship do not delete orphan children.

2010-07-30 Thread Sergej Koščejev

 On 30.7.2010 22:09, Aaron Fischer wrote:

cascade=all-delete-orphan


As far as I remember, orphan delete is only supported for collections.

Sergej

--
You received this message because you are subscribed to the Google Groups 
nhusers group.
To post to this group, send email to nhus...@googlegroups.com.
To unsubscribe from this group, send email to 
nhusers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.



RE: [nhusers] linq child filtering

2010-07-30 Thread Frans Bouma
 I am using the nhibernate 3 alpha and have this basics query
 
 var query = from record in session.QueryRecord()
from brwSet in session.QueryBorrowerSet()
from brw in session.QueryBorrower()
where
brw.PrintOrder == 1  brwSet.PrintOrder ==
 0

 record.Package.BorrowerSet.Contains( brwSet )
 brwSet.Borrower.Contains( brw )
select new Summary()
{
BorrowerFirstName = brw.Contact.FirstName,
BorrowerLastName = brw.Contact.LastName,
LoanPackageID = record.Id
};
 
 I would like to find a way to remove the two contains calls any
suggestions?

IMHO it would require joins, which are IMHO less efficient, as
Contains should generate an EXISTS(correlated subquery) query which is
easier to optimize (and doesn't runs the risk of creating a larger temp set
due to joins). 

Is there a reason why you'd want to remove the contains?

FB

-- 
You received this message because you are subscribed to the Google Groups 
nhusers group.
To post to this group, send email to nhus...@googlegroups.com.
To unsubscribe from this group, send email to 
nhusers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.



[nhusers] Re: How to map an objectified Many to Many relationship?

2010-07-30 Thread mbd-team
Sorry, for my stupidy, but im following this discussion in my mail
client. And it seems, that i did not get got all answers here. Please
forget my question at all. With the hints from you and Frans i could
solve my Problem!

Michael

On Jul 30, 9:32 pm, Michael Möhle moehl...@googlemail.com wrote:
 I have an entity Artikel:

 class name=Artikel table=artikel

     id name=Nr column =nr type=int access
 =nosetter.pascalcase-m-underscore

       generator class =sequence

         param name=sequenceartikel_nr_seq/param

       /generator

     /id

     property type=int name=ArtikelNr column=artikelnr access
 =nosetter.pascalcase-m-underscore not-null=true/

     property type=string length=16 name=BarcodeString
 column=barcode access =nosetter.pascalcase-m-underscore/

     property type=string length=80 name=NameEnglisch1
 column=nameenglisch1 access =nosetter.pascalcase-m-underscore/

     property type=string length=60 name =NameEnglisch2
 column=nameenglisch2 access =nosetter.pascalcase-m-underscore/

 .

 .

 .

     bag name=Auftraege inverse=true lazy=true access
 =nosetter.pascalcase-m-underscore

       key/

       many-to-many class =Auftrag/

       loader query-ref =ArtikelAuftrag/

     /bag

   /class

 An entity Auftrag:

 class name=Auftrag table=auftrag1 lazy=true

     id name=Nr column =nr type=int access
 =nosetter.pascalcase-m-underscore

       generator class =sequence

         param name=sequenceauftrag1_seq/param

       /generator

     /id

     property type=int name=AuftragNr column=nr2 access
 =nosetter.pascalcase-m-underscore not-null=true/

     property type=int name=Jahr column=jahr access
 =nosetter.pascalcase-m-underscore not-null=true/

     property type=date name=Datum column=datum access
 =nosetter.pascalcase-m-underscore/

 .

 .

 .

     bag name=AuftragDetails inverse=true lazy=true cascade=all
 access =nosetter.pascalcase-m-underscore order-by =artikelnrzusatz asc

       key column=nrhaupt /

       one-to-many class=AuftragDetails  /

     /bag

   /class

 An entity Auftragdetails:

 class name=AuftragDetails table=auftrag2 lazy=true

     id name=Nr column=nr type=int access
 =nosetter.pascalcase-m-underscore

       generator class=sequence

         param name=sequenceauftrag2_seq/param

       /generator

     /id

     property type=int name=Jahr column=jahr access
 =nosetter.pascalcase-m-underscore/

     property type=int name=ZeilenNr column=zeilennr access
 =nosetter.pascalcase-m-underscore/

     many-to-one name=Auftrag cascade=none class=Auftrag
 column=nrhaupt access =nosetter.pascalcase-m-underscore /

     many-to-one name=Artikel cascade=none class=Artikel
 column=artikelnr access =nosetter.pascalcase-m-underscore /

     property type=int name=ArtikelNr column=artikelnrzusatz access
 =nosetter.pascalcase-m-underscore /

 .

 .

 .

   /class

 And my problem is the Bag in Artikel (Auftraege). I want all “Auftraege”
 where the “Artikel” is on. (Maybe reduced to Offene Auftraege(open orders),
 but this is the next step ;-)

 Here is the the loading sql:

   sql-query  name =ArtikelAuftrag read-only =true

     return alias =at1 class =Auftrag lock-mode =read/

     select at1.*

     from auftrag1 at1

     inner join auftrag2 at2 ON at1.nr=at2.nrhaupt and (at2.artikelnr=?)

   /sql-query

 The error message is:

 Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt. (null
 reference?)

 StackTrace =    bei NHibernate.Collection.PersistentBag.get_Count()

    bei NHibernate.DebugHelpers.CollectionProxy`1.get_Items()

 Any hints are welcome!

 Von: nhusers@googlegroups.com [mailto:nhus...@googlegroups.com] Im Auftrag
 von Fabio Maulo
 Gesendet: Freitag, 30. Juli 2010 20:23
 An: nhusers@googlegroups.com
 Betreff: Re: [nhusers] How to map an objectified Many to Many relationship?

 What you are trying to do exactly ?

 On Fri, Jul 30, 2010 at 10:24 AM, Michael Möhle moehl...@googlemail.com
 wrote:

 Hi Fabio,

 would you like to post an example here? I am trying the same thing ;-)

 Michael

 Von: nhusers@googlegroups.com [mailto:nhus...@googlegroups.com] Im Auftrag
 von Fabio Maulo
 Gesendet: Montag, 26. Juli 2010 16:53
 An: nhusers@googlegroups.com
 Betreff: Re: [nhusers] How to map an objectified Many to Many relationship?

 Frans.

 Can you send me a private mail with classes and scrip to create tables ?

 Please simplified

 I'll then add the Order.Products readonly collection.

 btw have a look to loader

 On Mon, Jul 26, 2010 at 11:41 AM, Frans Bouma fr...@sd.nl wrote:

 Hi,

 Consider Northwind. It has several objectified many to many (m:n)
 relationships: Customer m:n Employee (via Order) and Order m:n Product (via
 OrderDetails).

 'objectified relationship' is a NIAM/ORM (object role modeling) term, 
 seehttp://www.orm.net, and it means that a m:n relationship on itself is an
 entity with its own attributes (fields).

 In the examples above, Order and OrderDetails are normal entities with
 non-pk fields. So let's pick 

Re: [nhusers] Re: Inserting a Primary Key value into the database

2010-07-30 Thread Stephen Karl
@Jason Meckley

I am not sure how to allow NHibernate to generate the database schema at
this point.  I created the database and tables first and then built the
program.

Also, I had no clue that a separate HiLo table was needed.  Do you link the
HiLo table to a particular table or do you just need one HiLo table period
for a database?

Stephen

On Fri, Jul 30, 2010 at 5:52 AM, Jason Meckley jasonmeck...@gmail.comwrote:

 @Stephen
 did you allow NH to generate the db schema for you, or are you trying
 to retro fit a legacy database to use hilo? When you select the hilo
 PIOD strategy it expects the actual table you are mapping to and a
 second table where the HiLo seed is stored by default it's named
 hibernate_unique_key with a single column max_lo. you can over ride
 the table name and column name if you want. for example I override the
 table name for each entity that uses hilo. this way each entity has
 it's own set of high low values. otherwise all entities get there
 max_lo seed from the same table.

 if this isn't enough to help you solve the problem please start
 another thread.

 On Jul 30, 12:25 am, Stephen Karl skarl...@gmail.com wrote:
  Hi Jason,
 
  I'm in the middle of Chapter 5 of the NHibernate 2 Beginner's Guide,
  specifically the end of page 97.  When I try to run the console project,
 I
  get the following runtime error at the session.Save line:
  could not get or update next value[SQL: ]
 
  The inner exception is Invalid object name 'hibernate_unique_key'.
  That error is encountered when I have the generator class set to 'hilo.'
 
  I'm currently using a SQL Server 2008 Express database with this project.
  The tables do NOT have an auto-sequenced number at the moment.
 
  When I changed the generator class to increment, I was able to
  successfully save the object to the database table.
 
  Any ideas why 'hilo' isn't good in this situation?  (This was the value
  recommended in the book/associated source code.)
 
  Stephen
 
  On Thu, Jul 29, 2010 at 10:40 AM, Jason Dentler jasondent...@gmail.com
 wrote:
 
   Frans,
 
   Sorry. I was referring to Identity in terms of SQL Server, as this is
 the
   database referred to in the NHibernate beginner's book. This particular
 POID
   generator, and it's cousin, Native on SQL server require the data to be
   inserted in order to generate an ID. This breaks batching, as the
   session.Save, etc. will put data in the database rather than waiting
 for
   transaction.Commit (or session.Flush, which IMO, should be considered
   deprecated when using flush-on-commit, the default)
 
   Compare that with hilo, which also doesn't allow duplicates when
   transactions are used properly, doesn't break batching, and even
 better,
   doesn't require a trip to the database for every insert; just one trip
 to
   flush the session.
 
   As I understand it, on Oracle, native works just fine because it's
   equivalent to sequence. It does require an extra trip to the database
 for
   every insert, but only to fetch an id value, not to insert data. I'm
 not
   sure if Identity is available on Oracle, if it has a different meaning
 than
   sequence, or if it's just silently converted to sequence. I'm a SQL
 guy.
 
   In any case, I'd like to know what exception Stephen encountered before
   guessing about the root cause.
 
   Thanks,
   Jason
 
   On Thu, Jul 29, 2010 at 10:21 AM, John Davidson jwdavid...@gmail.com
 wrote:
 
   Yes, please create a test and try it
 
   John Davidson
 
   On Thu, Jul 29, 2010 at 11:18 AM, Frans Bouma fr...@sd.nl wrote:
 
the issue with identity is that it causes two trips to the database
 for
every save of a new record and their are complications with Flush
 
   hmm, are you sure? the new identity value is requested by a
   batched
   SCOPE_IDENTITY() select right after the insert, same roundtrip as the
   insert, and it can then immediately be synced with related (fk side)
   entities. HiLo requires an extra roundtrip for the new value to
 obtain
   and
   insert, as that is required to obtain the new hilo using the sql
 posted
   by
   jason. Or am I missing something?
 
  FB
 
John Davidson
 
On Thu, Jul 29, 2010 at 10:51 AM, Frans Bouma fr...@sd.nl wrote:
 
   2 separate clients accessing the same database using HiLo
 will
   not
grab
   duplicate hi values.
 
   when the next_hi is retrieved by the session factory the
   following
2
   statements are executed.
   select next_hi from hilo_table (with lock) update
 hilo_table
   set
next_hi =
   next_hi + 1 where next_hi = @p0 (with update lock)
 
   ...or something like that. between these statements and
 having
   the
  operation
   within a transaction there is little (if any) chance of 2
   factories
  pulling
   the same next_hi value.
 
 thanks Jason :) It's indeed highly unlikely that the
   number
   is