Sunday, October 10, 2010

Named Beans in EJB 3.1 using Scala

For Named Beans in EJB 3.1 to work, they need implement the Serializable interface in Java, so while writing the same in Scala programming language, we “extend” it. The @LocalBean annotation is unique to the Scala implementation. Without this annotation, the session bean exposes a local business interface (ScalaObject in this case) as its client instead of UserController. Refer to this post on


import scala.reflect._
import java.util.ArrayList;
import java.util.{List => JList}
import javax.inject.Named
import javax.ejb.LocalBean
import javax.enterprise.context.SessionScoped
import javax.faces.model.DataModel
import javax.faces.model.ListDataModel;
import javax.ejb.Stateful;
import javax.persistence._

@Named{val value="userController"}
class UserController extends Serializable {

Source: also found this out :

The Scala version requires the @LocalBean annotation while the Java version does not (not sure why).  Also the EntityManager is defined as a var without the Java-style getters and setters.  The container is able to inject the EntityManager using the Scala-style mutator (bean.manager = x) but it does log an error about it not having a set method.

Now you know why :)

No comments:

Post a Comment