Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » JBoss User Help »

[jboss-user] [JBoss Seam] - @PersistenceContext in a SFSB created
 by a factory

scott.stark@jboss.org

2007-08-07


Hi there,

is it possible to have a PersistenceContext in a bean (don't really know which type it is, sorry, I'm a noob somedays :D) which is created by a factory?

The thing I want to do is to imlpement the possibility to switch the implementation of an interface. This works. In one of these implementations I want to obtain the PersistenceContext and that doesn't work.

But let me show you some code:

@Name("upDownloadFactory")
| @Scope(ScopeType.APPLICATION)
| @Startup
| public class UpDownloadFactory implements Serializable {
|  private String className;
|  
|  @Out(required=false)
|  private UpDownload upDownload;
|  
|  @Factory(value="upDownload", scope=ScopeType.SESSION, autoCreate=true)
|  public UpDownload getUpDownload() {
|   if(upDownload == null) {
|     try {
|      if(className == null || className.equals("")) {
|       className = "com.idsscheer.ares.sessions.UpDownloadDatabase";
|      }
|      upDownload = (UpDownload) Class.forName(className).newInstance();
|      ... and so on ...
|      }
|
|      return upDownload;
|   }
|
|  public void setClassName(String className) {
|   this.className = className;
|  }
| }
This is the factory I wrote. As you can see the implementation has to be set in components.xml and sets the className property. All those parameters I set in the @Factory annotation shall setup the "upDownload" as SFSB.

Here is one implementation of the managed bean:
@Scope(ScopeType.SESSION)
| @Stateful
| public class UpDownloadDatabase implements UpDownload, Serializable {
|  @PersistenceContext(unitName = "aresDatabase")
|  private transient EntityManager em;
|  
|  public boolean upload(UpDownloadFileinfo fileInfo) {
|   ... do the upload with em ...
|  }
|
|  public List<UpDownloadFileinfo> getAttachedFiles(long testactionID) {
|   ... show a list of attached files ...
|  }
|
|  @Remove @Destroy
|  public void destroy() {
|  }
| }

In this implementation the EntityManager is needed but on invokation of this bean the console tells me that
Caused by: java.lang.IllegalArgumentException: @PersistenceContext may only be used on session bean or message driven bean components: upDownload
|  at org.jboss.seam.Component.initMembers(Component.java:663)
|  at org.jboss.seam.Component.<init>(Component.java:253)
|  at org.jboss.seam.Component.<init>(Component.java:203)
|  at org.jboss.seam.init.Initialization.addComponent(Initialization.java:851)
|  ... 93 more

Has anybody an idea how to implement such a factory?

Thanks in advance
Newlukai

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4071517#4071517

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4071517
_______________________________________________
jboss-user mailing list
jboss-user@(protected)
https://lists.jboss.org/mailman/listinfo/jboss-user
©2008 junlu.com - Jax Systems, LLC, U.S.A.