Hibernate custom type in grails 1.2.2

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Hibernate custom type in grails 1.2.2

SanjayGupta

Hi I am trying use jasypt to encrypt a column in the database (oracle). My domain class looks like this:

 

package com.bwse.model

import org.jasypt.hibernate.type.EncryptedStringType

class xxxxxxxxxx {

    String xxx     

    static mapping = {

        columns {

            xxx    type: 'EncryptedStringType'

        }   

    }

}

 

I get the following error during server start. Am I missing anything?

 

2010-04-29 18:56:31,812 [main] ERROR [localhost].[/cwa2]  - Exception sending co

ntext initialized event to listener instance of class org.codehaus.groovy.grails

.web.context.GrailsContextLoaderListener

org.springframework.beans.factory.BeanCreationException: Error creating bean wit

h name 'messageSource': Initialization of bean failed; nested exception is org.s

pringframework.beans.factory.BeanCreationException: Error creating bean with nam

e 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while

setting bean property 'sessionFactory'; nested exception is org.springframework.

beans.factory.BeanCreationException: Error creating bean with name 'sessionFacto

ry': Invocation of init method failed; nested exception is org.hibernate.Mapping

Exception: Could not determine type for: EncryptedStringType, at table: loan_app

lication, for columns: [org.hibernate.mapping.Column(social_security_number)]

        at org.grails.tomcat.TomcatServer.start(TomcatServer.groovy:135)

        at grails.web.container.EmbeddableServer$start.call(Unknown Source)

        at _GrailsRun_groovy$_run_closure5_closure12.doCall(_GrailsRun_groovy:15

8)

        at _GrailsRun_groovy$_run_closure5_closure12.doCall(_GrailsRun_groovy)

        at _GrailsSettings_groovy$_run_closure10.doCall(_GrailsSettings_groovy:2

82)

        at _GrailsSettings_groovy$_run_closure10.call(_GrailsSettings_groovy)

        at _GrailsRun_groovy$_run_closure5.doCall(_GrailsRun_groovy:149)

        at _GrailsRun_groovy$_run_closure5.call(_GrailsRun_groovy)

        at _GrailsRun_groovy.runInline(_GrailsRun_groovy:115)

        at _GrailsRun_groovy.this$4$runInline(_GrailsRun_groovy)

        at _GrailsRun_groovy$_run_closure1.doCall(_GrailsRun_groovy:59)

        at RunApp$_run_closure1.doCall(RunApp.groovy:33)

        at gant.Gant$_dispatch_closure4.doCall(Gant.groovy:324)

        at gant.Gant$_dispatch_closure6.doCall(Gant.groovy:334)

        at gant.Gant$_dispatch_closure6.doCall(Gant.groovy)

        at gant.Gant.withBuildListeners(Gant.groovy:344)

        at gant.Gant.this$2$withBuildListeners(Gant.groovy)

        at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source)

        at gant.Gant.dispatch(Gant.groovy:334)

        at gant.Gant.this$2$dispatch(Gant.groovy)

        at gant.Gant.invokeMethod(Gant.groovy)

        at gant.Gant.processTargets(Gant.groovy:495)

        at gant.Gant.processTargets(Gant.groovy:480)

Reply | Threaded
Open this post in threaded view
|

Re: Hibernate custom type in grails 1.2.2

burtbeckwith
Don't quote the class name, it should be

   xxx type: EncryptedStringType

Burt

> Hi I am trying use jasypt to encrypt a column in the database (oracle). My domain class looks like this:
>
> package com.bwse.model
> import org.jasypt.hibernate.type.EncryptedStringType
> class xxxxxxxxxx {
>     String xxx
>     static mapping = {
>         columns {
>             xxx    type: 'EncryptedStringType'
>         }
>     }
> }
>
> I get the following error during server start. Am I missing anything?
>
> 2010-04-29 18:56:31,812 [main] ERROR [localhost].[/cwa2]  - Exception sending co
> ntext initialized event to listener instance of class org.codehaus.groovy.grails
> .web.context.GrailsContextLoaderListener
> org.springframework.beans.factory.BeanCreationException: Error creating bean wit
> h name 'messageSource': Initialization of bean failed; nested exception is org.s
> pringframework.beans.factory.BeanCreationException: Error creating bean with nam
> e 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while
> setting bean property 'sessionFactory'; nested exception is org.springframework.
> beans.factory.BeanCreationException: Error creating bean with name 'sessionFacto
> ry': Invocation of init method failed; nested exception is org.hibernate.Mapping
> Exception: Could not determine type for: EncryptedStringType, at table: loan_app
> lication, for columns: [org.hibernate.mapping.Column(social_security_number)]
>         at org.grails.tomcat.TomcatServer.start(TomcatServer.groovy:135)
>         at grails.web.container.EmbeddableServer$start.call(Unknown Source)
>         at _GrailsRun_groovy$_run_closure5_closure12.doCall(_GrailsRun_groovy:15
> 8)
>         at _GrailsRun_groovy$_run_closure5_closure12.doCall(_GrailsRun_groovy)
>         at _GrailsSettings_groovy$_run_closure10.doCall(_GrailsSettings_groovy:2
> 82)
>         at _GrailsSettings_groovy$_run_closure10.call(_GrailsSettings_groovy)
>         at _GrailsRun_groovy$_run_closure5.doCall(_GrailsRun_groovy:149)
>         at _GrailsRun_groovy$_run_closure5.call(_GrailsRun_groovy)
>         at _GrailsRun_groovy.runInline(_GrailsRun_groovy:115)
>         at _GrailsRun_groovy.this$4$runInline(_GrailsRun_groovy)
>         at _GrailsRun_groovy$_run_closure1.doCall(_GrailsRun_groovy:59)
>         at RunApp$_run_closure1.doCall(RunApp.groovy:33)
>         at gant.Gant$_dispatch_closure4.doCall(Gant.groovy:324)
>         at gant.Gant$_dispatch_closure6.doCall(Gant.groovy:334)
>         at gant.Gant$_dispatch_closure6.doCall(Gant.groovy)
>         at gant.Gant.withBuildListeners(Gant.groovy:344)
>         at gant.Gant.this$2$withBuildListeners(Gant.groovy)
>         at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source)
>         at gant.Gant.dispatch(Gant.groovy:334)
>         at gant.Gant.this$2$dispatch(Gant.groovy)
>         at gant.Gant.invokeMethod(Gant.groovy)
>         at gant.Gant.processTargets(Gant.groovy:495)
>         at gant.Gant.processTargets(Gant.groovy:480)
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

RE: Hibernate custom type in grails 1.2.2

SanjayGupta
Thanks Burt for the quick response. After removing quote I am getting this error. In fact I had tried without quote earlier.

2010-04-29 19:26:41,250 [main] ERROR context.ContextLoader  - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'messageSource': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is java.lang.NullPointerException
        at org.grails.tomcat.TomcatServer.start(TomcatServer.groovy:135)
        at grails.web.container.EmbeddableServer$start.call(Unknown Source)
        at _GrailsRun_groovy$_run_closure5_closure12.doCall(_GrailsRun_groovy:158)
        at _GrailsRun_groovy$_run_closure5_closure12.doCall(_GrailsRun_groovy)
        at _GrailsSettings_groovy$_run_closure10.doCall(_GrailsSettings_groovy:282)
        at _GrailsSettings_groovy$_run_closure10.call(_GrailsSettings_groovy)
        at _GrailsRun_groovy$_run_closure5.doCall(_GrailsRun_groovy:149)
        at _GrailsRun_groovy$_run_closure5.call(_GrailsRun_groovy)
        at _GrailsRun_groovy.runInline(_GrailsRun_groovy:115)
        at _GrailsRun_groovy.this$4$runInline(_GrailsRun_groovy)
        at _GrailsRun_groovy$_run_closure1.doCall(_GrailsRun_groovy:59)
        at RunApp$_run_closure1.doCall(RunApp.groovy:33)
        at gant.Gant$_dispatch_closure4.doCall(Gant.groovy:324)
        at gant.Gant$_dispatch_closure6.doCall(Gant.groovy:334)
        at gant.Gant$_dispatch_closure6.doCall(Gant.groovy)
        at gant.Gant.withBuildListeners(Gant.groovy:344)
        at gant.Gant.this$2$withBuildListeners(Gant.groovy)
        at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source)
        at gant.Gant.dispatch(Gant.groovy:334)
        at gant.Gant.this$2$dispatch(Gant.groovy)
        at gant.Gant.invokeMethod(Gant.groovy)
        at gant.Gant.processTargets(Gant.groovy:495)
        at gant.Gant.processTargets(Gant.groovy:480)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is java.lang.NullPointerException
        ... 23 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is java.lang.NullPointerException
        ... 23 more
Caused by: java.lang.NullPointerException
        at org.jasypt.hibernate.type.AbstractEncryptedAsStringType.setParameterValues(AbstractEncryptedAsStringType.java:161)
        ... 23 more
2010-04-29 19:26:41,312 [main] ERROR [localhost].[/cwa2]  - Exception sending context initialized event to listener instance of class org.codehaus.groovy.grails.web.context.GrailsContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'messageSource': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is java.lang.NullPointerException
        at org.grails.tomcat.TomcatServer.start(TomcatServer.groovy:135)
        at grails.web.container.EmbeddableServer$start.call(Unknown Source)
        at _GrailsRun_groovy$_run_closure5_closure12.doCall(_GrailsRun_groovy:158)
        at _GrailsRun_groovy$_run_closure5_closure12.doCall(_GrailsRun_groovy)
        at _GrailsSettings_groovy$_run_closure10.doCall(_GrailsSettings_groovy:282)
        at _GrailsSettings_groovy$_run_closure10.call(_GrailsSettings_groovy)
        at _GrailsRun_groovy$_run_closure5.doCall(_GrailsRun_groovy:149)
        at _GrailsRun_groovy$_run_closure5.call(_GrailsRun_groovy)
        at _GrailsRun_groovy.runInline(_GrailsRun_groovy:115)
        at _GrailsRun_groovy.this$4$runInline(_GrailsRun_groovy)
        at _GrailsRun_groovy$_run_closure1.doCall(_GrailsRun_groovy:59)
        at RunApp$_run_closure1.doCall(RunApp.groovy:33)
        at gant.Gant$_dispatch_closure4.doCall(Gant.groovy:324)
        at gant.Gant$_dispatch_closure6.doCall(Gant.groovy:334)
        at gant.Gant$_dispatch_closure6.doCall(Gant.groovy)
        at gant.Gant.withBuildListeners(Gant.groovy:344)
        at gant.Gant.this$2$withBuildListeners(Gant.groovy)
        at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source)
        at gant.Gant.dispatch(Gant.groovy:334)
        at gant.Gant.this$2$dispatch(Gant.groovy)
        at gant.Gant.invokeMethod(Gant.groovy)
        at gant.Gant.processTargets(Gant.groovy:495)
        at gant.Gant.processTargets(Gant.groovy:480)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is java.lang.NullPointerException
        ... 23 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is java.lang.NullPointerException
        ... 23 more
Caused by: java.lang.NullPointerException
        at org.jasypt.hibernate.type.AbstractEncryptedAsStringType.setParameterValues(AbstractEncryptedAsStringType.java:161)
        ... 23 more
2010-04-29 19:26:41,359 [main] ERROR core.StandardContext  - Error listenerStart
2010-04-29 19:26:41,453 [main] ERROR core.StandardContext  - Context [/cwa2] startup failed due to previous errors
-----Original Message-----
From: Burt Beckwith [mailto:[hidden email]]
Sent: Thursday, April 29, 2010 7:13 PM
To: [hidden email]
Subject: Re: [grails-user] Hibernate custom type in grails 1.2.2

Don't quote the class name, it should be

   xxx type: EncryptedStringType

Burt

> Hi I am trying use jasypt to encrypt a column in the database (oracle). My domain class looks like this:
>
> package com.bwse.model
> import org.jasypt.hibernate.type.EncryptedStringType
> class xxxxxxxxxx {
>     String xxx
>     static mapping = {
>         columns {
>             xxx    type: 'EncryptedStringType'
>         }
>     }
> }
>
> I get the following error during server start. Am I missing anything?
>
> 2010-04-29 18:56:31,812 [main] ERROR [localhost].[/cwa2]  - Exception sending co
> ntext initialized event to listener instance of class org.codehaus.groovy.grails
> .web.context.GrailsContextLoaderListener
> org.springframework.beans.factory.BeanCreationException: Error creating bean wit
> h name 'messageSource': Initialization of bean failed; nested exception is org.s
> pringframework.beans.factory.BeanCreationException: Error creating bean with nam
> e 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while
> setting bean property 'sessionFactory'; nested exception is org.springframework.
> beans.factory.BeanCreationException: Error creating bean with name 'sessionFacto
> ry': Invocation of init method failed; nested exception is org.hibernate.Mapping
> Exception: Could not determine type for: EncryptedStringType, at table: loan_app
> lication, for columns: [org.hibernate.mapping.Column(social_security_number)]
>         at org.grails.tomcat.TomcatServer.start(TomcatServer.groovy:135)
>         at grails.web.container.EmbeddableServer$start.call(Unknown Source)
>         at _GrailsRun_groovy$_run_closure5_closure12.doCall(_GrailsRun_groovy:15
> 8)
>         at _GrailsRun_groovy$_run_closure5_closure12.doCall(_GrailsRun_groovy)
>         at _GrailsSettings_groovy$_run_closure10.doCall(_GrailsSettings_groovy:2
> 82)
>         at _GrailsSettings_groovy$_run_closure10.call(_GrailsSettings_groovy)
>         at _GrailsRun_groovy$_run_closure5.doCall(_GrailsRun_groovy:149)
>         at _GrailsRun_groovy$_run_closure5.call(_GrailsRun_groovy)
>         at _GrailsRun_groovy.runInline(_GrailsRun_groovy:115)
>         at _GrailsRun_groovy.this$4$runInline(_GrailsRun_groovy)
>         at _GrailsRun_groovy$_run_closure1.doCall(_GrailsRun_groovy:59)
>         at RunApp$_run_closure1.doCall(RunApp.groovy:33)
>         at gant.Gant$_dispatch_closure4.doCall(Gant.groovy:324)
>         at gant.Gant$_dispatch_closure6.doCall(Gant.groovy:334)
>         at gant.Gant$_dispatch_closure6.doCall(Gant.groovy)
>         at gant.Gant.withBuildListeners(Gant.groovy:344)
>         at gant.Gant.this$2$withBuildListeners(Gant.groovy)
>         at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source)
>         at gant.Gant.dispatch(Gant.groovy:334)
>         at gant.Gant.this$2$dispatch(Gant.groovy)
>         at gant.Gant.invokeMethod(Gant.groovy)
>         at gant.Gant.processTargets(Gant.groovy:495)
>         at gant.Gant.processTargets(Gant.groovy:480)
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: Hibernate custom type in grails 1.2.2

burtbeckwith
That's because you need to configure the attributes of EncryptedStringType - see the javadoc here: http://www.jasypt.org/api/jasypt/apidocs/org/jasypt/hibernate/type/EncryptedStringType.html

It doesn't look like you can set attributes for custom types in GORM (and it'd be inconvenient to create a typedef), so I got it working by creating a subclass that sets them. Unfortunately EncryptedStringType is final but it was easy enough to subclass its superclass:

   package com.bwse.model

   import org.jasypt.hibernate.type.AbstractEncryptedAsStringType
   import org.jasypt.hibernate.type.ParameterNaming

   class MyEncryptedString extends AbstractEncryptedAsStringType {

      void setParameterValues(Properties parameters) {
         parameters = [
            (ParameterNaming.ALGORITHM): 'PBEWithMD5AndDES',
            (ParameterNaming.PASSWORD): 'your_password',
            (ParameterNaming.KEY_OBTENTION_ITERATIONS): 1000
         ]
         super.setParameterValues(parameters)
      }

      protected Object convertToObject(String stringValue) { stringValue }

      Class returnedClass() { String }
   }

Use the values for ParameterNaming.ALGORITHM, ParameterNaming.PASSWORD, and ParameterNaming.KEY_OBTENTION_ITERATIONS that make sense for your application. There are 3 other properties that can also be set: ParameterNaming.ENCRYPTOR_NAME, ParameterNaming.PROVIDER_NAME, and ParameterNaming.STRING_OUTPUT_TYPE.

Change the name to your class name:

   static mapping = {
      xxx type: MyEncryptedString
   }

and it should work.

Note that rather than hard-coding the parameter values, you should probably set them in Config.groovy and access them using ConfigurationHolder.config.

Burt

> Thanks Burt for the quick response. After removing quote I am getting this error. In fact I had tried without quote earlier.
>
> 2010-04-29 19:26:41,250 [main] ERROR context.ContextLoader  - Context initialization failed
> org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'messageSource': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is java.lang.NullPointerException
> at org.grails.tomcat.TomcatServer.start(TomcatServer.groovy:135)
> at grails.web.container.EmbeddableServer$start.call(Unknown Source)
> at _GrailsRun_groovy$_run_closure5_closure12.doCall(_GrailsRun_groovy:158)
> at _GrailsRun_groovy$_run_closure5_closure12.doCall(_GrailsRun_groovy)
> at _GrailsSettings_groovy$_run_closure10.doCall(_GrailsSettings_groovy:282)
> at _GrailsSettings_groovy$_run_closure10.call(_GrailsSettings_groovy)
> at _GrailsRun_groovy$_run_closure5.doCall(_GrailsRun_groovy:149)
> at _GrailsRun_groovy$_run_closure5.call(_GrailsRun_groovy)
> at _GrailsRun_groovy.runInline(_GrailsRun_groovy:115)
> at _GrailsRun_groovy.this$4$runInline(_GrailsRun_groovy)
> at _GrailsRun_groovy$_run_closure1.doCall(_GrailsRun_groovy:59)
> at RunApp$_run_closure1.doCall(RunApp.groovy:33)
> at gant.Gant$_dispatch_closure4.doCall(Gant.groovy:324)
> at gant.Gant$_dispatch_closure6.doCall(Gant.groovy:334)
> at gant.Gant$_dispatch_closure6.doCall(Gant.groovy)
> at gant.Gant.withBuildListeners(Gant.groovy:344)
> at gant.Gant.this$2$withBuildListeners(Gant.groovy)
> at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source)
> at gant.Gant.dispatch(Gant.groovy:334)
> at gant.Gant.this$2$dispatch(Gant.groovy)
> at gant.Gant.invokeMethod(Gant.groovy)
> at gant.Gant.processTargets(Gant.groovy:495)
> at gant.Gant.processTargets(Gant.groovy:480)
> Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is java.lang.NullPointerException
> ... 23 more
> Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is java.lang.NullPointerException
> ... 23 more
> Caused by: java.lang.NullPointerException
> at org.jasypt.hibernate.type.AbstractEncryptedAsStringType.setParameterValues(AbstractEncryptedAsStringType.java:161)
> ... 23 more
> 2010-04-29 19:26:41,312 [main] ERROR [localhost].[/cwa2]  - Exception sending context initialized event to listener instance of class org.codehaus.groovy.grails.web.context.GrailsContextLoaderListener
> org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'messageSource': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is java.lang.NullPointerException
> at org.grails.tomcat.TomcatServer.start(TomcatServer.groovy:135)
> at grails.web.container.EmbeddableServer$start.call(Unknown Source)
> at _GrailsRun_groovy$_run_closure5_closure12.doCall(_GrailsRun_groovy:158)
> at _GrailsRun_groovy$_run_closure5_closure12.doCall(_GrailsRun_groovy)
> at _GrailsSettings_groovy$_run_closure10.doCall(_GrailsSettings_groovy:282)
> at _GrailsSettings_groovy$_run_closure10.call(_GrailsSettings_groovy)
> at _GrailsRun_groovy$_run_closure5.doCall(_GrailsRun_groovy:149)
> at _GrailsRun_groovy$_run_closure5.call(_GrailsRun_groovy)
> at _GrailsRun_groovy.runInline(_GrailsRun_groovy:115)
> at _GrailsRun_groovy.this$4$runInline(_GrailsRun_groovy)
> at _GrailsRun_groovy$_run_closure1.doCall(_GrailsRun_groovy:59)
> at RunApp$_run_closure1.doCall(RunApp.groovy:33)
> at gant.Gant$_dispatch_closure4.doCall(Gant.groovy:324)
> at gant.Gant$_dispatch_closure6.doCall(Gant.groovy:334)
> at gant.Gant$_dispatch_closure6.doCall(Gant.groovy)
> at gant.Gant.withBuildListeners(Gant.groovy:344)
> at gant.Gant.this$2$withBuildListeners(Gant.groovy)
> at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source)
> at gant.Gant.dispatch(Gant.groovy:334)
> at gant.Gant.this$2$dispatch(Gant.groovy)
> at gant.Gant.invokeMethod(Gant.groovy)
> at gant.Gant.processTargets(Gant.groovy:495)
> at gant.Gant.processTargets(Gant.groovy:480)
> Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is java.lang.NullPointerException
> ... 23 more
> Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is java.lang.NullPointerException
> ... 23 more
> Caused by: java.lang.NullPointerException
> at org.jasypt.hibernate.type.AbstractEncryptedAsStringType.setParameterValues(AbstractEncryptedAsStringType.java:161)
> ... 23 more
> 2010-04-29 19:26:41,359 [main] ERROR core.StandardContext  - Error listenerStart
> 2010-04-29 19:26:41,453 [main] ERROR core.StandardContext  - Context [/cwa2] startup failed due to previous errors
> -----Original Message-----
> From: Burt Beckwith [mailto:[hidden email]]
> Sent: Thursday, April 29, 2010 7:13 PM
> To: [hidden email]
> Subject: Re: [grails-user] Hibernate custom type in grails 1.2.2
>
> Don't quote the class name, it should be
>
>    xxx type: EncryptedStringType
>
> Burt
>
> > Hi I am trying use jasypt to encrypt a column in the database (oracle). My domain class looks like this:
> >
> > package com.bwse.model
> > import org.jasypt.hibernate.type.EncryptedStringType
> > class xxxxxxxxxx {
> >     String xxx
> >     static mapping = {
> >         columns {
> >             xxx    type: 'EncryptedStringType'
> >         }
> >     }
> > }
> >
> > I get the following error during server start. Am I missing anything?
> >
> > 2010-04-29 18:56:31,812 [main] ERROR [localhost].[/cwa2]  - Exception sending co
> > ntext initialized event to listener instance of class org.codehaus.groovy.grails
> > .web.context.GrailsContextLoaderListener
> > org.springframework.beans.factory.BeanCreationException: Error creating bean wit
> > h name 'messageSource': Initialization of bean failed; nested exception is org.s
> > pringframework.beans.factory.BeanCreationException: Error creating bean with nam
> > e 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while
> > setting bean property 'sessionFactory'; nested exception is org.springframework.
> > beans.factory.BeanCreationException: Error creating bean with name 'sessionFacto
> > ry': Invocation of init method failed; nested exception is org.hibernate.Mapping
> > Exception: Could not determine type for: EncryptedStringType, at table: loan_app
> > lication, for columns: [org.hibernate.mapping.Column(social_security_number)]
> >         at org.grails.tomcat.TomcatServer.start(TomcatServer.groovy:135)
> >         at grails.web.container.EmbeddableServer$start.call(Unknown Source)
> >         at _GrailsRun_groovy$_run_closure5_closure12.doCall(_GrailsRun_groovy:15
> > 8)
> >         at _GrailsRun_groovy$_run_closure5_closure12.doCall(_GrailsRun_groovy)
> >         at _GrailsSettings_groovy$_run_closure10.doCall(_GrailsSettings_groovy:2
> > 82)
> >         at _GrailsSettings_groovy$_run_closure10.call(_GrailsSettings_groovy)
> >         at _GrailsRun_groovy$_run_closure5.doCall(_GrailsRun_groovy:149)
> >         at _GrailsRun_groovy$_run_closure5.call(_GrailsRun_groovy)
> >         at _GrailsRun_groovy.runInline(_GrailsRun_groovy:115)
> >         at _GrailsRun_groovy.this$4$runInline(_GrailsRun_groovy)
> >         at _GrailsRun_groovy$_run_closure1.doCall(_GrailsRun_groovy:59)
> >         at RunApp$_run_closure1.doCall(RunApp.groovy:33)
> >         at gant.Gant$_dispatch_closure4.doCall(Gant.groovy:324)
> >         at gant.Gant$_dispatch_closure6.doCall(Gant.groovy:334)
> >         at gant.Gant$_dispatch_closure6.doCall(Gant.groovy)
> >         at gant.Gant.withBuildListeners(Gant.groovy:344)
> >         at gant.Gant.this$2$withBuildListeners(Gant.groovy)
> >         at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source)
> >         at gant.Gant.dispatch(Gant.groovy:334)
> >         at gant.Gant.this$2$dispatch(Gant.groovy)
> >         at gant.Gant.invokeMethod(Gant.groovy)
> >         at gant.Gant.processTargets(Gant.groovy:495)
> >         at gant.Gant.processTargets(Gant.groovy:480)

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

RE: Hibernate custom type in grails 1.2.2

SanjayGupta
Thanks burt. That worked!!!!!!!!

-----Original Message-----
From: Burt Beckwith [mailto:[hidden email]]
Sent: Thursday, April 29, 2010 8:38 PM
To: [hidden email]
Subject: Re: [grails-user] Hibernate custom type in grails 1.2.2

That's because you need to configure the attributes of EncryptedStringType - see the javadoc here: http://www.jasypt.org/api/jasypt/apidocs/org/jasypt/hibernate/type/EncryptedStringType.html

It doesn't look like you can set attributes for custom types in GORM (and it'd be inconvenient to create a typedef), so I got it working by creating a subclass that sets them. Unfortunately EncryptedStringType is final but it was easy enough to subclass its superclass:

   package com.bwse.model

   import org.jasypt.hibernate.type.AbstractEncryptedAsStringType
   import org.jasypt.hibernate.type.ParameterNaming

   class MyEncryptedString extends AbstractEncryptedAsStringType {

      void setParameterValues(Properties parameters) {
         parameters = [
            (ParameterNaming.ALGORITHM): 'PBEWithMD5AndDES',
            (ParameterNaming.PASSWORD): 'your_password',
            (ParameterNaming.KEY_OBTENTION_ITERATIONS): 1000
         ]
         super.setParameterValues(parameters)
      }

      protected Object convertToObject(String stringValue) { stringValue }

      Class returnedClass() { String }
   }

Use the values for ParameterNaming.ALGORITHM, ParameterNaming.PASSWORD, and ParameterNaming.KEY_OBTENTION_ITERATIONS that make sense for your application. There are 3 other properties that can also be set: ParameterNaming.ENCRYPTOR_NAME, ParameterNaming.PROVIDER_NAME, and ParameterNaming.STRING_OUTPUT_TYPE.

Change the name to your class name:

   static mapping = {
      xxx type: MyEncryptedString
   }

and it should work.

Note that rather than hard-coding the parameter values, you should probably set them in Config.groovy and access them using ConfigurationHolder.config.

Burt

> Thanks Burt for the quick response. After removing quote I am getting this error. In fact I had tried without quote earlier.
>
> 2010-04-29 19:26:41,250 [main] ERROR context.ContextLoader  - Context initialization failed
> org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'messageSource': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is java.lang.NullPointerException
> at org.grails.tomcat.TomcatServer.start(TomcatServer.groovy:135)
> at grails.web.container.EmbeddableServer$start.call(Unknown Source)
> at _GrailsRun_groovy$_run_closure5_closure12.doCall(_GrailsRun_groovy:158)
> at _GrailsRun_groovy$_run_closure5_closure12.doCall(_GrailsRun_groovy)
> at _GrailsSettings_groovy$_run_closure10.doCall(_GrailsSettings_groovy:282)
> at _GrailsSettings_groovy$_run_closure10.call(_GrailsSettings_groovy)
> at _GrailsRun_groovy$_run_closure5.doCall(_GrailsRun_groovy:149)
> at _GrailsRun_groovy$_run_closure5.call(_GrailsRun_groovy)
> at _GrailsRun_groovy.runInline(_GrailsRun_groovy:115)
> at _GrailsRun_groovy.this$4$runInline(_GrailsRun_groovy)
> at _GrailsRun_groovy$_run_closure1.doCall(_GrailsRun_groovy:59)
> at RunApp$_run_closure1.doCall(RunApp.groovy:33)
> at gant.Gant$_dispatch_closure4.doCall(Gant.groovy:324)
> at gant.Gant$_dispatch_closure6.doCall(Gant.groovy:334)
> at gant.Gant$_dispatch_closure6.doCall(Gant.groovy)
> at gant.Gant.withBuildListeners(Gant.groovy:344)
> at gant.Gant.this$2$withBuildListeners(Gant.groovy)
> at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source)
> at gant.Gant.dispatch(Gant.groovy:334)
> at gant.Gant.this$2$dispatch(Gant.groovy)
> at gant.Gant.invokeMethod(Gant.groovy)
> at gant.Gant.processTargets(Gant.groovy:495)
> at gant.Gant.processTargets(Gant.groovy:480)
> Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is java.lang.NullPointerException
> ... 23 more
> Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is java.lang.NullPointerException
> ... 23 more
> Caused by: java.lang.NullPointerException
> at org.jasypt.hibernate.type.AbstractEncryptedAsStringType.setParameterValues(AbstractEncryptedAsStringType.java:161)
> ... 23 more
> 2010-04-29 19:26:41,312 [main] ERROR [localhost].[/cwa2]  - Exception sending context initialized event to listener instance of class org.codehaus.groovy.grails.web.context.GrailsContextLoaderListener
> org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'messageSource': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is java.lang.NullPointerException
> at org.grails.tomcat.TomcatServer.start(TomcatServer.groovy:135)
> at grails.web.container.EmbeddableServer$start.call(Unknown Source)
> at _GrailsRun_groovy$_run_closure5_closure12.doCall(_GrailsRun_groovy:158)
> at _GrailsRun_groovy$_run_closure5_closure12.doCall(_GrailsRun_groovy)
> at _GrailsSettings_groovy$_run_closure10.doCall(_GrailsSettings_groovy:282)
> at _GrailsSettings_groovy$_run_closure10.call(_GrailsSettings_groovy)
> at _GrailsRun_groovy$_run_closure5.doCall(_GrailsRun_groovy:149)
> at _GrailsRun_groovy$_run_closure5.call(_GrailsRun_groovy)
> at _GrailsRun_groovy.runInline(_GrailsRun_groovy:115)
> at _GrailsRun_groovy.this$4$runInline(_GrailsRun_groovy)
> at _GrailsRun_groovy$_run_closure1.doCall(_GrailsRun_groovy:59)
> at RunApp$_run_closure1.doCall(RunApp.groovy:33)
> at gant.Gant$_dispatch_closure4.doCall(Gant.groovy:324)
> at gant.Gant$_dispatch_closure6.doCall(Gant.groovy:334)
> at gant.Gant$_dispatch_closure6.doCall(Gant.groovy)
> at gant.Gant.withBuildListeners(Gant.groovy:344)
> at gant.Gant.this$2$withBuildListeners(Gant.groovy)
> at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source)
> at gant.Gant.dispatch(Gant.groovy:334)
> at gant.Gant.this$2$dispatch(Gant.groovy)
> at gant.Gant.invokeMethod(Gant.groovy)
> at gant.Gant.processTargets(Gant.groovy:495)
> at gant.Gant.processTargets(Gant.groovy:480)
> Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is java.lang.NullPointerException
> ... 23 more
> Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is java.lang.NullPointerException
> ... 23 more
> Caused by: java.lang.NullPointerException
> at org.jasypt.hibernate.type.AbstractEncryptedAsStringType.setParameterValues(AbstractEncryptedAsStringType.java:161)
> ... 23 more
> 2010-04-29 19:26:41,359 [main] ERROR core.StandardContext  - Error listenerStart
> 2010-04-29 19:26:41,453 [main] ERROR core.StandardContext  - Context [/cwa2] startup failed due to previous errors
> -----Original Message-----
> From: Burt Beckwith [mailto:[hidden email]]
> Sent: Thursday, April 29, 2010 7:13 PM
> To: [hidden email]
> Subject: Re: [grails-user] Hibernate custom type in grails 1.2.2
>
> Don't quote the class name, it should be
>
>    xxx type: EncryptedStringType
>
> Burt
>
> > Hi I am trying use jasypt to encrypt a column in the database (oracle). My domain class looks like this:
> >
> > package com.bwse.model
> > import org.jasypt.hibernate.type.EncryptedStringType
> > class xxxxxxxxxx {
> >     String xxx
> >     static mapping = {
> >         columns {
> >             xxx    type: 'EncryptedStringType'
> >         }
> >     }
> > }
> >
> > I get the following error during server start. Am I missing anything?
> >
> > 2010-04-29 18:56:31,812 [main] ERROR [localhost].[/cwa2]  - Exception sending co
> > ntext initialized event to listener instance of class org.codehaus.groovy.grails
> > .web.context.GrailsContextLoaderListener
> > org.springframework.beans.factory.BeanCreationException: Error creating bean wit
> > h name 'messageSource': Initialization of bean failed; nested exception is org.s
> > pringframework.beans.factory.BeanCreationException: Error creating bean with nam
> > e 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while
> > setting bean property 'sessionFactory'; nested exception is org.springframework.
> > beans.factory.BeanCreationException: Error creating bean with name 'sessionFacto
> > ry': Invocation of init method failed; nested exception is org.hibernate.Mapping
> > Exception: Could not determine type for: EncryptedStringType, at table: loan_app
> > lication, for columns: [org.hibernate.mapping.Column(social_security_number)]
> >         at org.grails.tomcat.TomcatServer.start(TomcatServer.groovy:135)
> >         at grails.web.container.EmbeddableServer$start.call(Unknown Source)
> >         at _GrailsRun_groovy$_run_closure5_closure12.doCall(_GrailsRun_groovy:15
> > 8)
> >         at _GrailsRun_groovy$_run_closure5_closure12.doCall(_GrailsRun_groovy)
> >         at _GrailsSettings_groovy$_run_closure10.doCall(_GrailsSettings_groovy:2
> > 82)
> >         at _GrailsSettings_groovy$_run_closure10.call(_GrailsSettings_groovy)
> >         at _GrailsRun_groovy$_run_closure5.doCall(_GrailsRun_groovy:149)
> >         at _GrailsRun_groovy$_run_closure5.call(_GrailsRun_groovy)
> >         at _GrailsRun_groovy.runInline(_GrailsRun_groovy:115)
> >         at _GrailsRun_groovy.this$4$runInline(_GrailsRun_groovy)
> >         at _GrailsRun_groovy$_run_closure1.doCall(_GrailsRun_groovy:59)
> >         at RunApp$_run_closure1.doCall(RunApp.groovy:33)
> >         at gant.Gant$_dispatch_closure4.doCall(Gant.groovy:324)
> >         at gant.Gant$_dispatch_closure6.doCall(Gant.groovy:334)
> >         at gant.Gant$_dispatch_closure6.doCall(Gant.groovy)
> >         at gant.Gant.withBuildListeners(Gant.groovy:344)
> >         at gant.Gant.this$2$withBuildListeners(Gant.groovy)
> >         at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source)
> >         at gant.Gant.dispatch(Gant.groovy:334)
> >         at gant.Gant.this$2$dispatch(Gant.groovy)
> >         at gant.Gant.invokeMethod(Gant.groovy)
> >         at gant.Gant.processTargets(Gant.groovy:495)
> >         at gant.Gant.processTargets(Gant.groovy:480)

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email