5

I have to bulk import data into my database using nhibernate and my mapped model. I set up a guid.comb generator for ids. Is there's a way to import data with yet assigned ids disabling temporary guid.comb id generator?

1 Answer 1

4

You can temporarily change the id generator to assigned. Then, after import is finished switch it back to COMB Guids. Just be sure you explicitly call session.Save() instead of SaveOrUpdate(). Does that solve your problem?

4
  • 4
    If you're going to be doing bulk imports frequently (rather than just a one-time operation), you can modify the Configuration object in memory to change the id to Assigned before building your SessionFactory. This way you don't have to maintain two sets of hbm.xml files. I discussed a similar technique (for temporarily making lookup tables updatable) in this blog post: jameskovacs.com/2007/11/04/… Feb 25, 2011 at 21:21
  • hey James many thanks, your solution seems to be the solution. Just one question: The "Id generator" disabling could be made for cascading entities? thanks a lot. P.s. how can I set your suggestion as the real answer of my question? thanks
    – Hoghweed
    Feb 25, 2011 at 23:38
  • Filip this could be a good idea to change the id, but I was asking how to do that, and to make bulk operation is not suggested to use the standard session, but instead it's needed to use the Stateless Session to do bulk operations for many reasons. Thanks anyway
    – Hoghweed
    Feb 25, 2011 at 23:42
  • 1
    Hoghweed: didn't take the "bulk" part of your question into account. Yes, bulk operations should be processed using stateless session. Feb 26, 2011 at 16:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.