Sunday, August 7, 2011

grails detecting dependency conflicts

To find out what kind of dependency conflicts you might have in your grails application execute the following:


grails dependency-report

A conflict resulted when I had different versions of the slf4j api

Refernece: http://www.grails.org/doc/latest/ref/Command%20Line/dependency-report.html

grails No thread-bound request found

When attempting to save a Domain object outside of a web request (which is running in a forked thread),
I received the following error message:

No thread-bound request found

This has something to do with Grails thinking that the Domain object is a Command object, which is not true.

To workaround this issue, I  had to make some changes in the controller where the binding of the form parameters takes place.

Previously, I would bind parameters as follows:

def save = { MiddlewareCase mCase ->

...
       
}

Now to avoid the error, I do the following:

def save = { 
        
        // IMPORTANT!!! Must bind this way or we get "No thread-bound request found"        
        MiddlewareCase mCase = new MiddlewareCase();
        bindData(mCase, params)

}

Sunday, July 31, 2011

sshj could not load keys

Needed to include bouncy castle in maven dependencies:



         
   
        org.bouncycastle
        bcprov-jdk16
        1.45
   
     
     
   
        net.schmizz
        sshj
        0.3.0
   

apache httpd forbidden selinux

I had an issue where a folder that I was trying to share on the web was not accessible resulting in FORBIDDEN.

It turns out that SELinux policies in Linux were preventing access. To enable it use the following:

/usr/sbin/setsebool -P httpd_disable_trans 1
/etc/init.d/httpd restart

Thursday, July 28, 2011

grails Second-level cache is not enabled for usage

Make sure the domain class doesn't have a mapping with cache usage parameter

    static mapping = {
        cache usage: 'read-only'
    }

Tuesday, June 28, 2011

Associated entities and org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session

The problem:
I encountered this problem when attempting to save an entity that had a many-to-one association with an object that was being referenced multiple times in the same hibernate session. Hence the error below:

org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [au.edu.apf.phenomebank.db.mouse.MouseStrain#5044]
        at org.hibernate.engine.StatefulPersistenceContext.checkUniqueness(StatefulPersistenceContext.java:637)
        at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performUpdate(DefaultSaveOrUpdateEventListener.java:305)
        at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsDetached(DefaultSaveOrUpdateEventListener.java:246)
Below is the hibernate mapping configuration file that I was using:

    <class name="au.edu.apf.phenomebank.inventory.mouse.EmbryoOocyte" table="embryo_oocyte">
        <id name="id" type="java.lang.Long">
            <generator class="increment"/>
        </id>
        
        <many-to-one name="mother" column="mother_id" cascade="save-update" not-null="true" />
        <many-to-one name="father" column="father_id" cascade="save-update" not-null="true" />
        <many-to-one name="strain" column="strain_id" cascade="save-update" not-null="true" />
        <property name="type" column="type" type="au.edu.apf.phenomebank.inventory.mouse.EnumEmbryoOocyteUserType"  not-null="true" />        
        <property name="breedingColour" column="breeding_colour" type="au.edu.apf.phenomebank.inventory.mouse.EnumBreedingColourUserType"  not-null="true" />
        
    </class>


 The Solution:

Since it was the associated objects that were causing the problem, the solution was to get Hibernate to merge them rather than attempt a save or update. This was achieved using the cascade propery as follows:

    <class name="au.edu.apf.phenomebank.inventory.mouse.EmbryoOocyte" table="embryo_oocyte">
        <id name="id" type="java.lang.Long">
            <generator class="increment"/>
        </id>
        
        <many-to-one name="mother" column="mother_id" cascade="merge,save-update" not-null="true" />
        <many-to-one name="father" column="father_id" cascade="merge,save-update" not-null="true" />
        <many-to-one name="strain" column="strain_id" cascade="merge,save-update" not-null="true" />
        <property name="type" column="type" type="au.edu.apf.phenomebank.inventory.mouse.EnumEmbryoOocyteUserType"  not-null="true" />        
        <property name="breedingColour" column="breeding_colour" type="au.edu.apf.phenomebank.inventory.mouse.EnumBreedingColourUserType"  not-null="true" />
        
    </class>