Download

Get Loom

Appendix C: Frequently Asked Questions

What is the easiest way of using a Loom Log class in my own code?

We tend to use the Loom Log frequently, so we have developed an eclipse template to use it. Include this in your eclipse config at Preferences -> Java -> Editor -> Templates:

Name: log
Description: Loom log
Context: Java
Automatically insert: true
Pattern:

${:import(org.loom.log.Log)}private static Log log = Log.getLog();

Next time you need to use it, just type "log" and Ctrl + Space, and the template will create the log attribute for you.

When using @RetrieveEntity, if the transaction does not get committed, the next access to the database triggers a commit anyway

This happens every once in a while with multiple transactional access to the database. The ORM retrieves the data and a commit is triggered on any subsequent database access, for example with the next EQL query.

There are two solutions available:

  • mark the method as @Transactional(readonly=true): by marking all readonly methods (findByXxxx, getAllXxxxx) with this annotation, the method will not trigger a commit before execution.
  • evict the persistent object in a beforeValidate() or beforePopulate() method: lazy collections should in this case be initialized by hand (using Hibernate.initialize() or invoking any collection method) before invoking evict().

When trying to inject ExtendedEntityManager, I get an error "Specified resource type [javax.persistence.EntityManager] is not assignable to field type [interface org.loom.persistence.ExtendedEntityManager]"

This happens with older versions of spring. Double check that you only have spring 2.5.5 or greater in your libs folder.

I have some problem with PersistentFileResolution and PostgreSQL blobs

Postgresql blobs can only be used within a transaction:

http://www.postgresql.org/docs/7.3/static/lo-interfaces.html
http://forum.hibernate.org/viewtopic.php?t=963507

When, say, a FileAction tries to retrieve a PersistentFile and send it to the browser (as and image or PDF), the File copy is executed by PersistentFileResolution outside any transaction. In that case, PostgreSQL will complain and will not allow the copy to proceed:

org.postgresql.util.PSQLException: ERROR: invalid large-object descriptor: 0

This error has several ugly workarounds:

  • Keep the persistent file contents as a byte array.
  • Keep the transaction open until the response has been commited.
  • Copy the file contents inside a transactional environment (for example, in your controller layer).
  • Change your database provider :)