Tuesday, November 22, 2011

Hibernate, ElementCollection, and Transactions

Hibernate implemented @ElementCollection in the JPA by binding the persistence of the ElementCollection of a new entity at the end of the transaction, and NOT at the time you tell the EntityManager to persist.  Under most use cases, this should not be a problem, however it does mean that you cannot detach the entity from the EntityManager prior to ending the Transaction.

For example, the following will not persist your ElementCollection.


You will likely not run into situations like this, however I'm posting as I ran into some code that I was refactoring for Spring 3.1.  3.1 did not like nested @Transactions on a particular thread, and in the code's original design, it was detaching the entity on the nested item to avoid conflicts, I removed the nested @Transaction but did not notice the detach, and spent days figuring out why hibernate was not persisting the collection.  The answer is, as stated above, hibernate does not persist the collection at .persist, but on commit.

CIFS share accessed in Linux returning 'cannot allocate memory'?

http://www.codenition.com/solving-cannot-allocate-memory-error-on-windows-7-linux-cifs-mounts
From the blog post:
Set the following registry key to ’1′:
HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management\LargeSystemCache
and set the following registry key to ’3′:
HKLM\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters\Size

Exporting all tables to CSV in SQL Server

The following script will output a list of statements to use bcp to export all tables to CSV. To use another format, see the bcp documentation.

Deleting a database remotely with SQL Server

This should never be done on a production server, as it will open up security risks. This is useful for integration tests and utilities. Replace %dbName% appropriately