spring - Grails TransientObjectException -


this related this post, find of config. ldap user mapped database user table , entry created fine. userdetails tries authorities main user class resulting in following exception:

2014-01-31 12:10:52,076 [http-bio-8111-exec-4] error [/step].[default]  - servlet.service() servlet [default] in context path [/step] threw exception message: object references unsaved transient instance - save transient instance before flushing: packagae.user; nested exception org.hibernate.transientobjectexception: object references unsaved transient instance - save transient instance before flushing: package.user     line | method ->>  102 | docall                in org.grails.datastore.gorm.gormstaticapi$_methodmissing_closure2 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  |     42 | getauthorities        in package.user |     27 | getauthorities . . .  in package.mdtuserdetails |     72 | attemptauthentication in grails.plugin.springsecurity.web.authentication.requestholderauthenticationfilter |     49 | dofilter . . . . . .  in     '' |     82 | dofilter              in grails.plugin.springsecurity.web.authentication.logout.mutablelogoutfilter |   1145 | runworker . . . . . . in java.util.concurrent.threadpoolexecutor |    615 | run                   in java.util.concurrent.threadpoolexecutor$worker ^    744 | run . . . . . . . . . in java.lang.thread caused transientobjectexception: object references unsaved transient instance - save transient instance before flushing: package.user ->>  102 | docall                in org.grails.datastore.gorm.gormstaticapi$_methodmissing_closure2 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  |     42 | getauthorities        in package.user |     27 | getauthorities . . .  in package.mdtuserdetails |     72 | attemptauthentication in grails.plugin.springsecurity.web.authentication.requestholderauthenticationfilter |     49 | dofilter . . . . . .  in     '' |     82 | dofilter              in grails.plugin.springsecurity.web.authentication.logout.mutablelogoutfilter |   1145 | runworker . . . . . . in java.util.concurrent.threadpoolexecutor |    615 | run                   in java.util.concurrent.threadpoolexecutor$worker ^    744 | run . . . . . . . . . in java.lang.thread 

here user details class:

import java.util.collection;  import org.springframework.security.core.grantedauthority import org.springframework.security.ldap.userdetails.ldapuserdetails  import package.role import package.user  class mdtuserdetails extends user implements ldapuserdetails{        public mdtuserdetails(string fullname, string email, string username, string password, boolean enabled, boolean accountexpired,         boolean accountlocked, boolean passwordexpired, collection<grantedauthority> authorities) {         super(username: username, password: password, email: email, fullname: fullname, enabled: enabled, accountexpired: accountexpired, accountlocked: accountlocked, passwordexpired: passwordexpired, authorties: authorities)      }       @override      public set<role> getauthorities(){         return super.getauthorities()     }      @override     public boolean isaccountnonexpired() {         // todo auto-generated method stub         return false;     }      @override     public boolean isaccountnonlocked() {         // todo auto-generated method stub         return false;     }      @override     public boolean iscredentialsnonexpired() {         // todo auto-generated method stub         return false;     }      @override     public string getdn() {         // todo auto-generated method stub         return null;     }   } 

and user:

class user {      transient springsecurityservice      string username     string tostring() {         "${username}"     }     string password     string email     string fullname     string userorg     boolean enabled = true     boolean accountexpired     boolean accountlocked     boolean passwordexpired      static belongsto = [organization : organization]     static hasmany = [reports: report, invoices: invoice]      static mappedby = [invoices:'lastupdatedby', reports: 'lastupdatedby']     static transients = ['springsecurityservice']      static constraints = {         username blank: false, unique: true         //have nullable true password in order map mdtusers applicaiton roles.         password nullable: true, blank: true         email blank: true, nullable: true         fullname nullable: true, blank: true         userorg nullable: true, blank: true         organization nullable: true, blank: true     }      static mapping = {         table 'step_users'         password column: '`password`'     }      set<role> getauthorities() {         userrole.findallbyuser(this).collect { it.role } set     }      def beforeinsert() {         encodepassword()     }      def beforeupdate() {         if (isdirty('password')) {             encodepassword()         }     }      protected void encodepassword() {         password = springsecurityservice.encodepassword(password)     } } 

i'm not sure if related cascading events or how should save session, or how i'm calling super class in userdetails?

edit

finally figured out!

in userdetails class extending own user class:

import package.user  class mdtuserdetails extends user { 

instead needed extend springsecurity user class here :

import org.springframework.security.core.userdetails.user 

i believe causing transient object exception, answer suggested need have belongsto, etc. did have on classes.

caused transientobjectexception: object references unsaved transient instance - save transient instance before flushing: package.user 

this message tells user object want save contains @ least 1 reference domain object isn't saved.

according user class unsaved reference report or invoice object. have following options solve issue:

save reports , invoices manually before adding them user

or

enable automatic cascading of reports , invoices using

static mapping = {   reports cascade: 'all-delete-orphan'   reports invoices: 'all-delete-orphan' } 

or

add belongsto relationship invoice , report:

static belongsto = [user: user] 

Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -