ProtoUser, primary key as string not saving

13 views
Skip to first unread message

Allyn

unread,
Oct 21, 2010, 5:06:27 PM10/21/10
to Lift
Hello,

I have copied the ProtoUser out of lift and pasted it into a different
file in my project. I have run into an issue and I don't know what to
do next. The root of the issue is that my pk is null. My User table
has strings for primary keys. I created a beforeCreate callback to
set the primary key as User records are created. For some reason they
are still not getting saved, even though I am sure they are getting
assigned, and the field has write permissions. Observe the following
code snippets:

########## In the custom ProtoUser ############
override def primaryKeyField = user_id
object user_id extends MappedStringIndex(this, 36) {
override def dbColumnName = "user_id"
override def writePermission_? = true
}


######## In the user model############

override def beforeCreate = List((user: User) => {
user.user_id(UUID.randomUUID().toString())

println("[User creation] " + user.user_id.writePermission_? + " ~
" + user.user_id)
()
})
}

and the results:

[User creation] true ~ 301c2d20-0320-410f-81b4-ba4a504d868e
ERROR - Exception being returned to browser when processing /user/
sign_up: Message: org.postgresql.util.PSQLException: ERROR: null value
in column "user_id" violates not-null constraint

Any ideas?

David Pollak

unread,
Oct 22, 2010, 9:26:16 AM10/22/10
to lif...@googlegroups.com
Please post your entire file so that we can reproduce the issue.


--
You received this message because you are subscribed to the Google Groups "Lift" group.
To post to this group, send email to lif...@googlegroups.com.
To unsubscribe from this group, send email to liftweb+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.




--
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Blog: http://goodstuff.im
Surf the harmonics

Will Bagby

unread,
Oct 25, 2010, 11:10:04 AM10/25/10
to Lift
I had the same NULL problem, which I fixed, but then my MetaMapper
object wasn't writing my value to the DB. Here's what I did:


object user_id extends MappedStringIndex(this, 32) {
override def dbNotNull_? = true // we have to do this, even though
MappedStringIndex is a primary key!
override def writePermission_? = true // not sure if this is
necessary
override def dbAutogenerated_? = false // we are creating this value
ourselves, not the DB
}

BTW...since MappedStringIndex extends MappedUniqueId, it automatically
generates a default value when you create your object, so you may not
have to do that yourself (unless you need it in a specific format).
Take a look at MappedUniqueId.scala for details.

HTH,

-Will
Reply all
Reply to author
Forward
0 new messages