Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class User extends Record[User] {
- val name = "name".TEXT.NOT_NULL
- val admin = "admin".BOOLEAN.NOT_NULL.DEFAULT('false')
- }
- object User extends Table[User] {
- def byName(n: String): Seq[User] = criteria.add(this.name LIKE n).list
- }
- // example with foreign keys:
- class Account extends Record[Account] {
- val accountNumber = "acc_number".BIGINT.NOT_NULL
- val user = "user_id".REFERENCES(User).ON_DELETE(CASCADE)
- val amount = "amount".NUMERIC(10,2).NOT_NULL
- }
- object Account extends Table[Account]
- import javax.persistence.Entity;
- import javax.persistence.GeneratedValue;
- import javax.persistence.Id;
- @Entity { val name = "Users" }
- class User {
- @Id
- @GeneratedValue
- var userid:Long = _
- var login:String = _
- var password:String = _
- var firstName:String = _
- var lastName:String = _
- }
- /*
- Corresponding table:
- CREATE TABLE `users` (
- `id` int(11) NOT NULL auto_increment,
- `name` varchar(255) default NULL,
- `admin` tinyint(1) default '0',
- PRIMARY KEY (`id`)
- )
- */
- import _root_.javax.persistence._
- @Entity
- @Table{val name="users"}
- class User {
- @Id
- @Column{val name="id"}
- var id: Long = _
- @Column{val name="name"}
- var name: String = _
- @Column{val name="admin"}
- var isAdmin: Boolean = _
- override def toString = "UserId: " + id + " isAdmin: " + isAdmin + " Name: " + name
- }
- class Product(val name: String, val attributes: Set[Attribute])
- class Attribute(val name: String, val value: String)
- ...
- val product = new Product("blue jean", Set(new Attribute("colour", "blue"), new Attribute("size", "medium")))
- val inserted = mapperDao.insert(ProductEntity, product)
- // the persisted entity has an id property:
- println("%d : %s".format(inserted.id,inserted))
- val o=OrderEntity
- import Query._
- val orders = query(select from o where o.totalAmount >= 20.0 and o.totalAmount <= 30.0)
- println(orders) // a list of orders
Add Comment
Please, Sign In to add comment