I'm having a problem in nHibernate where when I use CreateCriteria to get data from my db nHibernate is putting in 13 implicit Left Outer Joins. I have read that to solve this problem I can use FetchMode.Select for tables that I don't want nHibernate to do a join on. When I do this I get tens of thousands of select statements generated (one for each row for each table where I have set the FetchMode to "Select"). I finally figured out (after about 6 hours of working on this) that if I set my Projections manually and exclude fields from the tables that are being joined unnecessarily that these Selects go away. I then am using LINQ to create a List<MyEntity> and map the List<IList> response from nHibernate.List() to it where "MyEntity" is the class that my mapping files reference in nHibernate. It was at this point that I though I had solved my 13 joins problem. Now I am down to 7 joins all of which are required for the data I am pulling and the data is coming back quickly.
I was wrong ... :( I now realize that the way I am pulling my data from my database is creating nHibernate entities that aren't really compatible with saves and commits. For instance, I have a field in my main (non-joined) table that isn't being populated when I pull from the database, but it is a field I want to provide a value for and save back to the SessionManager. When I do this I don't get an error, but nothing is updated. At this point I don't really know what to do. I feel like I have a couple of possible options, but I can't find any information on nHibernate to know if what I am thinking is possible. I appreciate any help. 1. Find some alternative for pulling the data that prevents nHibernate from doing 13 implicit outer joins but allows me to omit my Projections. This I expect will give me usable objects when I am ready to update in the database again. 2. Find some way to include all fields in my master table in my projects. Something akin to SELECT *. This might work because it will cause nHibernate to populate all relevant fields from the master table. 3. Find some way to attach an nHibernate entity with just a few pieces of data that match the actual row in the database so that I can associate my entity in an nHibernate-compatible way. I am thinking of something almost like GetByExample but that doesn't give me a new object instance, instead it takes my existing instance and populates the missing fields where necessary. I have tried using Update, Lock and Load, but none of these methods do what I need. Here is my mapping file for the main table. I think including all of the associated mapping files would be undesireable. Please note I have lazy loading turned on for all of my relationships in this left outer join problem. <?xml version="1.0" encoding="utf-8"?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"> <!--Build: with [email protected] Nhibernate template--> <class name="CGW.Shared.Entities.CollectionAr,CGW.Shared" table="CollectionAR" lazy="true"> <id name="TransactionId" column="TransactionID" type="int"> <generator class="native" /> </id> <property name="PaymentId" column="PaymentID" type="long" not- null="true" /> <many-to-one name="SourceSystem" column="SystemID" cascade="none" not-null="true" /> <many-to-one name="Status" column="StatusID" cascade="none" not- null="true" /> <property name="CreatedDate" column="CreatedDate" type="DateTime" not-null="true" /> <property name="LastUpdatedDate" column="LastUpdatedDate" type="DateTime" not-null="true" /> <property name="EnteredBy" column="EnteredBy" type="int" not- null="true" /> <property name="OrderId" column="OrderID" type="long" /> <property name="DistributorId" column="DistributorID" type="long" / > <property name="PaymentDate" column="PaymentDate" type="DateTime" / > <property name="CurrencyCode" column="CurrencyCode" type="string" / > <property name="CountryCode" column="CountryCode" type="string" /> <many-to-one name="TransactionType" column="TransactionTypeCode" cascade="none" /> <property name="CreatedBy" column="CreatedBy" type="string" /> <many-to-one name="ExportBatch" column="ExportBatchID" cascade="none" /> <property name="IsPaymentRetry" column="IsPaymentRetry" type="Boolean" /> <many-to-one name="Source" column="SourceID" cascade="none" not- null="true" /> <one-to-one name="Address" cascade="all" /> <one-to-one name="BankTransfer" cascade="all" /> <one-to-one name="CcPayment" cascade="all" /> <one-to-one name="Cod" cascade="all" /> <one-to-one name="DanskeCollection" cascade="all" /> <one-to-one name="DirectDebit" cascade="all" /> <one-to-one name="GermanyBankTransfer" cascade="all" /> <one-to-one name="GermanyDebit" cascade="all" /> <one-to-one name="HsbcCollection" cascade="all" /> <one-to-one name="Redirect" cascade="all" /> <one-to-one name="Note" cascade="all" /> <one-to-one name="EWallet" cascade="all" /> <bag name="TransactionAudit" inverse="true" lazy="true" cascade="delete" order-by="CreatedDate asc"> <key column="TransactionID" /> <one-to-many class="CGW.Shared.Entities.TransactionAudit,CGW.Shared" /> </bag> <many-to-one name="MessageProcessor" column="MessageProcessorID" cascade="none" not-null="false" /> </class> </hibernate-mapping> --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
