Discussion:
[nhusers] Open Stateless session given a session
Felipe Oriani
2017-07-07 14:22:26 UTC
Permalink
Hello guys.

I am developing a process where we need to insert more than 200.000 records
on the database and it can increse. To have a performance, we need to
implement a stateless session to insert all the data.

The problem is that on our Repositories implementations we depend on the
SessionFactory which contains a session on bind and we take it from
SessionFactory.GetCurrentSession() and depending on the context, it already
has an active transaction.

My question is: Is there any way to implement bulk insert operations on the
normal Session instead of Stateless session?

If no, I would like to know, if is there any way to open a Stateless
session to perform the bulk insert operation for the same transaction? Or
should I need to open a stateless session from my sessionFactory?

I've seen that stateless session can take a DbConnection, so I could try
this:

var statelessSession = factory.OpenStatelessSession(session.Connection);

But I am not sure how it is going to work. If it is fine to and I will get
the same transaction.

Thank you.
--
______________________________________
Felipe B Oriani
***@gmail.com
--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nhusers+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.
Gunnar Liljas
2017-07-07 15:24:57 UTC
Permalink
200000 is a lot, even for a stateless session. Are you using MSSQL?

/G
Post by Felipe Oriani
Hello guys.
I am developing a process where we need to insert more than 200.000
records on the database and it can increse. To have a performance, we need
to implement a stateless session to insert all the data.
The problem is that on our Repositories implementations we depend on the
SessionFactory which contains a session on bind and we take it from
SessionFactory.GetCurrentSession() and depending on the context, it
already has an active transaction.
My question is: Is there any way to implement bulk insert operations on
the normal Session instead of Stateless session?
If no, I would like to know, if is there any way to open a Stateless
session to perform the bulk insert operation for the same transaction? Or
should I need to open a stateless session from my sessionFactory?
I've seen that stateless session can take a DbConnection, so I could try
var statelessSession = factory.OpenStatelessSession(session.Connection);
But I am not sure how it is going to work. If it is fine to and I will get
the same transaction.
Thank you.
--
______________________________________
Felipe B Oriani
--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an
Visit this group at https://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nhusers+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.
Felipe Oriani
2017-07-07 17:08:57 UTC
Permalink
Hi Gunnar,

I am using Oracle but it also can run over MsSql.

I am sorry, I express myself wrong. I execute a DataReader on another
database which give a result set of 200k records. I loop on this and
compact 100 records on a json (Clob/text field) and persist one line on the
session. For 200k, it will be 2500 records on insert the stateless session.
To improve the performance, the ID of this entity I am going to persist it
mapped as GUID.

The question is about the *transaction*, on my architecture, the repository
depends of session factory, which contains a session on the bind (take by
GetCurrentSession). I would like to know, if on the method where I need to
process this massive data, if I initilize another session (stateless) by
passing the Connection of the session (Session.Connection) on the
factory.OpenStatelessSession(), will I have the statelesse session on the
same transaction?

Thank you.
Post by Gunnar Liljas
200000 is a lot, even for a stateless session. Are you using MSSQL?
/G
Post by Felipe Oriani
Hello guys.
I am developing a process where we need to insert more than 200.000
records on the database and it can increse. To have a performance, we need
to implement a stateless session to insert all the data.
The problem is that on our Repositories implementations we depend on the
SessionFactory which contains a session on bind and we take it from
SessionFactory.GetCurrentSession() and depending on the context, it
already has an active transaction.
My question is: Is there any way to implement bulk insert operations on
the normal Session instead of Stateless session?
If no, I would like to know, if is there any way to open a Stateless
session to perform the bulk insert operation for the same transaction? Or
should I need to open a stateless session from my sessionFactory?
I've seen that stateless session can take a DbConnection, so I could try
var statelessSession = factory.OpenStatelessSession(session.Connection);
But I am not sure how it is going to work. If it is fine to and I will
get the same transaction.
Thank you.
--
______________________________________
Felipe B Oriani
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an
Visit this group at https://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an
Visit this group at https://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.
--
______________________________________
Felipe B Oriani
***@gmail.com
--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nhusers+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.
Fran Knebels
2017-07-07 17:17:36 UTC
Permalink
A long time ago I tried stateless session to do what your doing and ended
up punting and replacing it with bulk copy.

Oracle, at least the full odp.net, had OracleBulkCopy which I ended up
using instead of NHibernate. I don't know if the bulk copy classes exist
in the managed provider.

The bulk copy classes are significantly faster than trying to wrangle this
through NHibernate
Post by Felipe Oriani
Hi Gunnar,
I am using Oracle but it also can run over MsSql.
I am sorry, I express myself wrong. I execute a DataReader on another
database which give a result set of 200k records. I loop on this and
compact 100 records on a json (Clob/text field) and persist one line on the
session. For 200k, it will be 2500 records on insert the stateless session.
To improve the performance, the ID of this entity I am going to persist it
mapped as GUID.
The question is about the *transaction*, on my architecture, the
repository depends of session factory, which contains a session on the bind
(take by GetCurrentSession). I would like to know, if on the method where I
need to process this massive data, if I initilize another session
(stateless) by passing the Connection of the session (Session.Connection)
on the factory.OpenStatelessSession(), will I have the statelesse session
on the same transaction?
Thank you.
Post by Gunnar Liljas
200000 is a lot, even for a stateless session. Are you using MSSQL?
/G
Post by Felipe Oriani
Hello guys.
I am developing a process where we need to insert more than 200.000
records on the database and it can increse. To have a performance, we need
to implement a stateless session to insert all the data.
The problem is that on our Repositories implementations we depend on the
SessionFactory which contains a session on bind and we take it from
SessionFactory.GetCurrentSession() and depending on the context, it
already has an active transaction.
My question is: Is there any way to implement bulk insert operations on
the normal Session instead of Stateless session?
If no, I would like to know, if is there any way to open a Stateless
session to perform the bulk insert operation for the same transaction? Or
should I need to open a stateless session from my sessionFactory?
I've seen that stateless session can take a DbConnection, so I could try
var statelessSession = factory.OpenStatelessSession(session.Connection);
But I am not sure how it is going to work. If it is fine to and I will
get the same transaction.
Thank you.
--
______________________________________
Felipe B Oriani
--
You received this message because you are subscribed to the Google
Groups "nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send
Visit this group at https://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an
Visit this group at https://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.
--
______________________________________
Felipe B Oriani
--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an
Visit this group at https://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nhusers+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.
Felipe Oriani
2017-07-07 18:50:38 UTC
Permalink
Hi Fran,

Thank you for the feedback. And yes, unfortunately there is no
OracleBulkCopy on the Managed Provider. Only in the unmanaged provider. We
use Oracle Managed Provider. I am trying to improve the performance using
ado.net and it looks like get some time improvements and use
Session.Transaciton.enlist(command) to make it part of my main transaction.
It works fine.

I wish to have OracleBulkCopy on it. Maybe, I will try it out.

Thank you.
Post by Fran Knebels
A long time ago I tried stateless session to do what your doing and ended
up punting and replacing it with bulk copy.
Oracle, at least the full odp.net, had OracleBulkCopy which I ended up
using instead of NHibernate. I don't know if the bulk copy classes exist
in the managed provider.
The bulk copy classes are significantly faster than trying to wrangle this
through NHibernate
Post by Felipe Oriani
Hi Gunnar,
I am using Oracle but it also can run over MsSql.
I am sorry, I express myself wrong. I execute a DataReader on another
database which give a result set of 200k records. I loop on this and
compact 100 records on a json (Clob/text field) and persist one line on the
session. For 200k, it will be 2500 records on insert the stateless session.
To improve the performance, the ID of this entity I am going to persist it
mapped as GUID.
The question is about the *transaction*, on my architecture, the
repository depends of session factory, which contains a session on the bind
(take by GetCurrentSession). I would like to know, if on the method where I
need to process this massive data, if I initilize another session
(stateless) by passing the Connection of the session (Session.Connection)
on the factory.OpenStatelessSession(), will I have the statelesse
session on the same transaction?
Thank you.
Post by Gunnar Liljas
200000 is a lot, even for a stateless session. Are you using MSSQL?
/G
Post by Felipe Oriani
Hello guys.
I am developing a process where we need to insert more than 200.000
records on the database and it can increse. To have a performance, we need
to implement a stateless session to insert all the data.
The problem is that on our Repositories implementations we depend on
the SessionFactory which contains a session on bind and we take it from
SessionFactory.GetCurrentSession() and depending on the context, it
already has an active transaction.
My question is: Is there any way to implement bulk insert operations on
the normal Session instead of Stateless session?
If no, I would like to know, if is there any way to open a Stateless
session to perform the bulk insert operation for the same transaction? Or
should I need to open a stateless session from my sessionFactory?
I've seen that stateless session can take a DbConnection, so I could
var statelessSession = factory.OpenStatelessSession(s
ession.Connection);
But I am not sure how it is going to work. If it is fine to and I will
get the same transaction.
Thank you.
--
______________________________________
Felipe B Oriani
--
You received this message because you are subscribed to the Google
Groups "nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send
Visit this group at https://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google
Groups "nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send
Visit this group at https://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.
--
______________________________________
Felipe B Oriani
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an
Visit this group at https://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an
Visit this group at https://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.
--
______________________________________
Felipe B Oriani
***@gmail.com
--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nhusers+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.
Michael Powell
2017-07-08 03:38:21 UTC
Permalink
Post by Felipe Oriani
Hello guys.
I am developing a process where we need to insert more than 200.000
records on the database and it can increse. To have a performance, we need
to implement a stateless session to insert all the data.
Hibernate, or any of its lineage, are not really designed for that, I
think. I wouldn't use that, or any runtime ORM. Rather, I would consider
loading what you can from a command line bulk load.

The problem is that on our Repositories implementations we depend on the
Post by Felipe Oriani
SessionFactory which contains a session on bind and we take it from
SessionFactory.GetCurrentSession() and depending on the context, it already
has an active transaction.
My question is: Is there any way to implement bulk insert operations on
the normal Session instead of Stateless session?
If no, I would like to know, if is there any way to open a Stateless
session to perform the bulk insert operation for the same transaction? Or
should I need to open a stateless session from my sessionFactory?
I've seen that stateless session can take a DbConnection, so I could try
var statelessSession = factory.OpenStatelessSession(session.Connection);
But I am not sure how it is going to work. If it is fine to and I will get
the same transaction.
Thank you.
--
______________________________________
Felipe B Oriani
--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nhusers+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.
Loading...