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 java.net.

Example:

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._
import java.io.Serializable

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

Source: http://vikasrao.wordpress.com/2010/05/05/jsf-2-0-session-beans-and-jpa-using-scala/

SourceAlias.com 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