What is a good architecture for a Lift-JPA application?

I was wondering what works best for the JPA model in Lift? I noticed that in the jpa demo application there is only a Model object, it looks like a super object that does everything. I don’t think this could be the most scalable approach, no?

Can I still make a DAO drawing in Lift? For example, there is some code that looks somewhat bloated and can be simplified for all objects of the model:

Model.remove(Model.getReference(classOf[Author], someId))

May be:

AuthorDao.remove(someId)

I would be grateful for advice on creating something that will work with the way the elevator wants to work, as well as being easy to organize and maintain. It is advisable from someone who actually used JPA on a medium or large elevator, and not just postulated what Spring is doing (we know how to do this);)

The first stage of development will be about 30-40 tables, and ultimately get more than 100 ... we need a scalable, accurate approach.

+3
source share
1 answer

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]()

// etc.

}

, -, MyDBModel, ( , ). :

object Person {
def findByLastName = MyDBModel.createQuery[Person]
("...").findAll.toList

// etc.

}

, , :

S.addAround(new LoanWrapper {
   def apply[T](f: => T):T = {
      try {
         f
      }
      catch {
         case e => MyDBModel.getTransaction.setRollbackOnly
      }
      finally {
         MyDBModel.cleanup
      }
   }

})

, , HTTP- , , . MyDBModel , EM, , .

, .

+2

Source: https://habr.com/ru/post/1748143/


All Articles