Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NHibernate 'Write Only' collection, if there is such a thing?

Does anyone know if it's possible to add an item to a collection without actually retrieving the persisted items in that collection? Is there a mapping that will allow me to achieve this?

I have a scenario where I'm performing some batch processing on some customer objects. I want to add some notes to my customers as I go but don't want/need the already persisted notes for that customer as it's a background process and simply adds to the collection.

like image 719
Matt Avatar asked Dec 31 '25 12:12

Matt


2 Answers

18.5.3. Bags and lists are the most efficient inverse collections

In any case, you can skip the collection completely and just use a many-to-one (i.e. set Note.Customer instead of adding a Note to Customer.Notes)

like image 116
Diego Mijelshon Avatar answered Jan 05 '26 02:01

Diego Mijelshon


I'm not sure about your original question, but I can offer a workaround- create a new Note object, set its Customer property to the wanted customer, and persist it. simple, and works well for me.

like image 20
J. Ed Avatar answered Jan 05 '26 02:01

J. Ed



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!