1

I have a table definition

class Transaction(
  val ...
) extends KeyedEntity[Long] {
  val id:Long = 0
}

val transaction = table[Transaction]("transactions")

on(transaction) {t =>
    declare(
        t.id is unique
        ... (other fields)
    )
}

The database table was not generated by Squeryl (I created it manually), but the "ID" column is set to PrimaryKey and AutoIncrement.

Now I'm inserting a row in this table:

val row = new Transaction(...)
val rowResult = transaction.insert(row)
println("Id1="+row.id+"; Id2="+rowResult.id)

The row is correctly inserted into the database and there an ID is assigned (!=0). But the application prints "ID1=0; ID2=0" on the command line.

Why? And how do I get the assigned ID?

edit: I did also try the table definition this way

class Transaction(
    val id: Long,
    ...
) extends KeyedEntity[Long]

Didn't make any differences.

Heinzi
  • 5,793
  • 4
  • 40
  • 69

1 Answers1

1

When I remove the declaration

t.id is unique

it works. So the problem is solved.

Is this a bug in squeryl?

Heinzi
  • 5,793
  • 4
  • 40
  • 69
  • 3
    It isn't a bug. By default, any numeric id field is set to be auto-incremented. When you specify `t.id is unique` you are overriding the default behavior. It isn't necessary to specify that it's unique since it's a primary key, but if you wanted to you would have to include the autoincremented attribute as well `t.id is (unique, autoIncremented)` – Dave Whittaker Aug 16 '12 at 17:05