Lift-mapper - inserting items to database

193 views Asked by At

I am trying to add item to H2 database. My code is:

class Test extends LongKeyedMapper[Test] with IdPK {
  def getSingleton = Test
  object name extends MappedString(this, 100)
}

and Test.create.name("some_name").id(2).save, but I always get java.lang.Exception: Do not have permissions to set this field. What can I do wrong? Connection is of course open and I have permission to data from database.

1

There are 1 answers

2
yǝsʞǝla On

IdPK extends MappedLongIndex which is not writable by default, that's why it restricts you from setting the field. Usually you would let the DB generate an PK ID automatically for you via autoincrement field (postgres, mysql), trigger + sequence (oracle), etc. So in most common scenarios you don't need to set this field. To be able to still set it add an override like this on your field:

override def writePermission_? = true