Sent from the Lift Descendants mailing list ( source here ):
I can tell you a little about how we use JPA. I’m not sure what you are working with, but we use JBoss 4.2.2 and using the connection pool facilities.
scalajpa JPA
.
, RequestVarEM,
RequestVar HTTP-,
,
.
- ""
persistence.xml:
object MyDBModel extends LocalEMF("unitName", false) with
ThreadLocalEM
, .
, JPA
:
trait Persistent {
def persist = DBModel.persist(this)
def merge = DBModel.merge(this)
def remove = DBModel.remove(this)
}
,
@Entity
@Table{val name="person"}
class Person extends Persistent {
@Id
var id:String = _
@Column {val name="first_name", val nullable = false, val
updatable=false}
var firstName:String = _
@Column {val name="last_name", val nullable = false, val
updatable=false}
var lastName:String = _
@OneToMany{ ... }
var roles:Set[Role] = new HashSet[Role]()
}
,
-,
MyDBModel,
( , ). :
object Person {
def findByLastName = MyDBModel.createQuery[Person]
("...").findAll.toList
}
, ,
:
S.addAround(new LoanWrapper {
def apply[T](f: => T):T = {
try {
f
}
catch {
case e => MyDBModel.getTransaction.setRollbackOnly
}
finally {
MyDBModel.cleanup
}
}
})
, ,
HTTP- ,
, . MyDBModel
,
EM, ,
.
, .