scala - How do I use Squeryl's KeyedEntity? -


the information find relating keyedentity was:

objects extend keyedentity[k] k numeric type have id field assigned newly created primary key value (the mechanism generating keys specific each databaseadaptor).

how apply when keyed object immutable? isn't impossible object have id field assigned newly created primary key value?

i assume supposed override abstract id method inside keyedentity on object in order return key of object. how squeryl find out field use key when it's writing database?

i'm using squeryl 9.5 if matters. can't find documentation on these issues.

in 0.95, squeryl field id or in case of compositekey, function named id. so, either of these definitions work:

case class mytable(val id:long, ...) extends keyedentity[long]  case class mytable(val field1:long, val field2:string, ...) extends keyedentity[compositekey2[long, string]] {   def id = compositekey(field1, field2) }  

if using single field, looks db field named id, or can use @column annotation specify alternate name in db. in case of compositekey, db fields corresponding key made of (in example above: field1 , field2). can use @column map different column name in db.

as mentioned in other answer can alias fields, id doesn't work way in 0.95 - see: classcastexception when trying insert squeryl. in 0.96 things change around bit, keyedentity no longer required can find more info on here.

if curious how internals of insert method works, can take @ source of table on github.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -