Thursday, September 13, 2012

How to check out a project from SVN repository ignoring some directories

I recently was working on the project with number of directories that were not used to build the project but were quite large in size. The obvious choice to ignore them on the checkout, however it is not that easily achievable using SVN.
So, here is a remedy (step-by-step guide):

  1. Identify names of directories that should be omitted from the checkout.
  2. Start general checkout of the branch: svn co <branch URL> <directory name>
  3. Interrupt checkout as soon as it creates directory (directories) that should be omitted.
  4. Delete directory that should be omitted from the disk.
  5. Run svn cleanup
  6. Do a checkout of the directory to be omitted specifying empty depth: svn co <branch URL>/directory --depth empty
  7. Do this for each directory that should be omitted. Note, that these directories could be situated at any level in the source tree, but the checkout with the empty depth should be done then from the directory that holds the one that should be omitted.
On the very large project it might make sense to do it iteratively, by running the updates and interrupting it immediately after the directory in question is created either by checkout or by update.

Wednesday, September 12, 2012

Magic of the disappearing hibernate session

In the past couple of years we came across a bizarre error on the number of occasions linked to the Hibernate session becoming not available to the thread.
It usually manifests itself with the following exception:

org.springframework.transaction.support.TransactionSynchronizationUtils - TransactionSynchronization.beforeCompletion threw exception
java.lang.IllegalStateException: No value for key [org.hibernate.impl.SessionFactoryImpl@2ea60563] bound to thread [WorkManager(2)-7]


However, from time to time it shows the different message with the similar message which reads that Hibernate session is not available to the current thread.

After some investigation it appears that it is highly likely that this exception occurs when the particular combination of the frameworks involved into the application. We observed it in the J2EE project that is built using combination of Hibernate and Spring running on JBoss 5.1 application server where transaction management is delegated to the JBoss.

It seems that Spring by default wraps the Hibernate's SessionFactory implementation into its own transactional version attached to Spring's transaction support. Since we delegated transaction management to JBoss Hibernate Session will not be bound to the Spring's transaction manager. But Spring's SessionFactoryUtil checks if it is bound to Spring's transaction manager and reports the error if it does not unless it is instructed not to do so.

In order to instruct Spring to ignore the fact that Hibernate session is not bound to the Spring's transaction support the following property should be added to the definition of the Hibernate Session Factory:

<property name="exposeTransactionAwareSessionFactory" value="false"/>

Note that this property makes sense only in case of JTA transaction manager involved and not required when local transaction manager is used.

Back to the future

It is two years since i have abandoned my own blog where i mostly wrote the solution to the technical problems that were encountered across various projects. Since, the old blog does only exist in the archives i need to move old articles here at some stage as it had proven before to be fairly useful at least for myself. Quite possible it might help the others in their quest as we seem to be making similar mistakes.