Activate framework and play 2.4

142 views
Skip to first unread message

Michał Jurczuk

unread,
Jun 22, 2015, 5:34:43 AM6/22/15
to activate-p...@googlegroups.com
Is it possible to use activate-framework with play 2.4?

Michał Jurczuk

unread,
Dec 29, 2015, 8:36:10 AM12/29/15
to Activate Persistence Framework
The problem is with class loader, after application start and before loading plugins, some of db classes has been already loaded so activate cannot add id:

Can't find the entity 'id' property for class models.db.Task, probably the entity class was loaded before the persistence context. Try to add a 'transactional{}' call on the application startup to force the persistence.

package net.fwbrasil.activate.play

import javax.inject.Inject

import net.fwbrasil.activate.ActivateContext
import play.api.{Play, Plugin}

class ActivatePlayPluginPlay24 @Inject() (app: play.Application) extends Plugin {

 
override def onStart = {
   
ActivateContext.setClassLoader(Play.current.classloader)
    models
.db.persistenceContext.context
  }

 
override def onStop = {
 
}
}

I also tried with Eager Module, this time it is too early (no application):

Error injecting constructor, java.lang.RuntimeException: There is no started application
trait Hello {}

class MyHelloClass extends Hello {
  initialize
() // running initialization in constructor
  def initialize() = {

   
ActivateContext.setClassLoader(Play.current.classloader)

 
}
}

class ActivatePlayModule2 extends AbstractModule {
 
def configure() = {
    bind
(classOf[Hello])
     
.to(classOf[MyHelloClass]).asEagerSingleton
 
}
}

Finally I tried implement own application loader (base on Guice, here I have classloader but application is not started yet:
override final def load(context: ApplicationLoader.Context): Application = {
 
implicit val app = builder(context).build
 
ActivateContext.setClassLoader(app.classloader)
  models
.db.persistenceContext.context
  app
}


It's seems to be impossible to use activate-framework with play-2.4, or you have any other ideas?

dfo...@gmail.com

unread,
Mar 13, 2016, 11:01:05 AM3/13/16
to Activate Persistence Framework
Hi, I have found a solution:

package net.fwbrasil.activate


import _root_.play.api.inject.Module

import _root_.play.api.inject.Binding

import _root_.play.api.Environment

import _root_.play.api.Configuration

import _root_.play.api.Play

import _root_.play.api.Plugin

import _root_.play.api.inject.ApplicationLifecycle


import javax.inject.Inject

import models.PersistenceContext._


class ActivateNewPlayPlugin extends Plugin {


    override def onStart = {

        ActivateContext.setClassLoader(Play.current.classloader)      

        transactional{}

    }

}


Hope that helps,
Diego

dfo...@gmail.com

unread,
Jul 17, 2016, 11:33:47 AM7/17/16
to Activate Persistence Framework, dfo...@gmail.com
I forgot to mention something, to make it work you might also need to remove you EntityForm s from the Controller classes, because controllers are loaded before the application is fully initialized and so your Entities would get loaded too early and then they cannot be instrumented by Activate. I put the forms in a Controller Companion object, not sure that is the best way.

Best,
Diego
Reply all
Reply to author
Forward
0 new messages