2

I would like to be able to transparently store a byte array or stream in an entity to disc (or S3 or what not) instead of to the DB (and of course read it back when the property is requested), but I can't find any documentation or examples that does anything similar. Is it possible? Any hint to how this could be implemeted? IUserType? IEntityPersister?

Carl Hörberg
  • 5,973
  • 5
  • 41
  • 47

2 Answers2

2

Check another thread.

IUserType and/or IEntityPersister define how to handle part of the entity and/or the entity whole when loading/inserting/updating/deleting.

In your case you have to define lower level of ORM abstraction - write implementation of NHibernate.Dialect.Dialect, NHibernate.Connection.IConnectionProvider and NHibernate.Driver.IDriver. After that you have full control of persisting NHibernate objects.

Or, if your needs are much simpler and you just need to copy save data somehow to disk while persisting them into database, you can just attach listeners to NHibernate load/save process. Check namespace NHibernate.Event (IAutoFlushEventListener, IMergeEventListener, IPersistEventListener, etc...). Usage example is here.

Community
  • 1
  • 1
Petr Kozelek
  • 1,126
  • 8
  • 14
0

Using IUserType would be a possibility if you store the key of the blob in the database and use this key to retrieve the blob when the user type is read from the database. However, transaction management across the database and the blob storage would be an issue.

Entity persisters can be a lot of work to write and get right, as the documentation for this extensability mechanism of (N)Hibernate is not great. They are very geared towards relational databases, though could be used to access other storage mechanisms.

Using event triggers may indeed provide the best option. They provide a pretty clean and compact interface to the life cycle events of an entity and to the transactions in which they take place.

Gerke Geurts
  • 632
  • 4
  • 9