|
Hi, I have the below code. No matter where i put userInstance.save(flush:true) it fails with the error message: null id in User entry (don't flush the Session after an exception occurs)
what you see below is the latest incarnation of me just randomly moving things in and out of services, controller methods, and try/catch blocks trying to get something a little more useful to spit out at me other than that error message. I've read around on this and tried almost everything I could find that made sense. I could only assume that the save is failing and throwing an error, but why isn't validate catching that if true? Any help would be great, thanks - Joe Using Java:7, Grails:2.0.3, OS X: Lion def register(){ |
|
Have you tried putting failOnError:true in your save?
Steve Good http://stevegood.org/ http://twitter.com/stevegood Then I heard the voice of the Lord saying, “Whom shall I send? And who will go for us?” And I said, “Here am I. Send me!” - Isaiah 6:8 On Sunday, May 6, 2012 at 6:27 PM, Joe Greenawalt wrote:
|
|
I just did based on your recommendation and i get the same result. Interestingly enough, if i give it bad data it will fail validation as expected.
On Sun, May 6, 2012 at 7:35 PM, Steve Good <[hidden email]> wrote:
|
|
I had almost this exact same error happen to me for a project. Deleting the dev db file and restarting Grails helped solve the problem.
If you have User extending the domain object created by the s2-quickstart script, and use h2 as the database, add static mapping = { tablePerHierarchy false } to both source and extending domain classes. This should help. I know h2 doesn't like alter statements all that much, and extending a domain class does some weird things. |
|
Thanks for the replies everyone i traced it back to some constraints i was trying to pull off, its strange though in that situation there is no way to diagnose the problem.
Thanks all, Joe
On Sun, May 6, 2012 at 8:53 PM, maineguy <[hidden email]> wrote: I had almost this exact same error happen to me for a project. Deleting the |
|
Hi Joe,
What were the constraints? Were they doing database lookups? Alex On 8 May 2012 21:47, Joe Greenawalt <[hidden email]> wrote: > Thanks for the replies everyone i traced it back to some constraints i was > trying to pull off, its strange though in that situation there is no way to > diagnose the problem. > > Thanks all, > Joe > > > On Sun, May 6, 2012 at 8:53 PM, maineguy <[hidden email]> wrote: >> >> I had almost this exact same error happen to me for a project. Deleting >> the >> dev db file and restarting Grails helped solve the problem. >> >> If you have User extending the domain object created by the s2-quickstart >> script, and use h2 as the database, add >> >> static mapping = { >> tablePerHierarchy false >> } >> >> to both source and extending domain classes. This should help. I know h2 >> doesn't like alter statements all that much, and extending a domain class >> does some weird things. >> >> -- >> View this message in context: >> http://grails.1312388.n4.nabble.com/null-id-in-User-entry-don-t-flush-the-Session-after-an-exception-occurs-tp4613735p4613807.html >> Sent from the Grails - user mailing list archive at Nabble.com. >> >> --------------------------------------------------------------------- >> 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 |
|
I don't remember exactly what I was trying to do, it was on the password, but it was not a database lookup. It was a combination of regex and something else, I will try to look through the git commits and see if i dig it up.
On Wed, May 9, 2012 at 3:30 AM, Alex Anderson <[hidden email]> wrote: Hi Joe, |
|
this happened to me as well. and on the password field. If i disable all validation on the password field it seemed to work. the only validation I am doing is blank:false, size:5..15 and it still gives me that error message
haven't found a solution yet. can you please let me know if you have any update on this. and how did you exactly resolve this? I am using grails spring-security-core plugin |
|
This post has NOT been accepted by the mailing list yet.
I also had this problem and thanks to this forum I was able to partially resolve it. It does relate to password validation constraints. In my case I had constraints set for password entry that fail when trying to store an encrypted password. This is an issue as for user entry I want to validate the unencrypted text, yet still store an encrypted value in the DB. The encrypted value is much longer then any standard user password length should be.
Solutions for now: 1) Remove password encryption in the DB (not secure) 2) Remove password constraint validation (also not ideal). You could however ensure validation occurs by using a Command. This would decouple the form and database validation constraints. 3) There may be someway manually ensure the database table does not have the same constraints set in the domain object. Here is the User class that fails. class User { transient springSecurityService static final String ANONYMOUS String username String password String email Date dateCreated Date lastUpdated boolean enabled boolean accountExpired boolean accountLocked boolean passwordExpired static constraints = { username size: 3..30, blank: false, unique: true password size: 5..16, blank: false, validator: { passwd, user -> passwd != user.username } email email: true, nullable: true } Set<Role> getAuthorities() { UserRole.findAllByUser(this).collect { it.role } as Set } def beforeInsert() { encodePassword() } def beforeUpdate() { if (isDirty('password')) { encodePassword() } } protected void encodePassword() { password = springSecurityService.encodePassword(password) } } Thanks for posting help on this. Saved me some time. If I figure out a good way to make form validation and database validation happy I will share. D |
| Powered by Nabble | Edit this page |
