-
1. Re: Can a JBoss Service-POJO be a Seam component?
paata.paatal.magtigsm.ge Jan 30, 2009 3:28 PM (in response to cvolk)i tried to do this for some days ago, but failed.
@Service bean is very useful for j2ee application.
i have not problem with then in ejb application,
but into my seam application i got this error :Caused by: java.lang.IllegalArgumentException: @PersistenceContext may only be used on session bean or message driven bean components: commonService
i need this service for loading data from database only one time, also i have reloader.
singleton service has no problem in ejb app.here is an example of my service component :
@Name("commonService") @Local(CommonServiceLocal.class) @Service(objectName = "jboss:custom=CommonServiceBean") public class CommonServiceBean implements CommonServiceMan, CommonServiceLocal { @PersistenceContext EntityManager oracleManager; private ArrayList<Description> descriptions; private Hashtable<Long, Hashtable<Long, Description>> descriptionList; public void create() throws Exception { System.out.println("Start Creating Common Service"); } public void destroy() throws Exception { System.out.println("Start Destroying Common Service"); } public void reloadDescriptions() { try { long time = System.currentTimeMillis(); descriptions = (ArrayList<Description>) oracleManager .createNamedQuery("Description.getAllDescriptions") .getResultList(); if (descriptions != null && !descriptions.isEmpty()) { descriptionList = new Hashtable<Long, Hashtable<Long, Description>>(); for (Description description : descriptions) { Hashtable<Long, Description> item = new Hashtable<Long, Description>(); item.put(description.getId(), description); descriptionList.put(description.getLanguageId(), item); } } time = System.currentTimeMillis() - time; System.out.println("Descriptions Load Time : " + time); } catch (Exception e) { e.printStackTrace(); } } public void start() throws Exception { System.out.println("Starting Common Service"); try { long time = System.currentTimeMillis(); descriptions = (ArrayList<Description>) oracleManager .createNamedQuery("Description.getAllDescriptions") .getResultList(); if (descriptions != null && !descriptions.isEmpty()) { descriptionList = new Hashtable<Long, Hashtable<Long, Description>>(); for (Description description : descriptions) { Hashtable<Long, Description> item = new Hashtable<Long, Description>(); item.put(description.getId(), description); descriptionList.put(description.getLanguageId(), item); } } time = System.currentTimeMillis() - time; System.out.println("Descriptions Load Time : " + time); } catch (Exception e) { e.printStackTrace(); } } public void stop() throws Exception { System.out.println("Stopping Common Service"); } public Description getDescriptionByIdAndLang(Long langId, Long descriptionId) { System.out.println("Getting Description By ID and Language"); if (langId == null || descriptionId == null) { return null; } if (descriptionList == null || descriptionList.isEmpty()) { return null; } Hashtable<Long, Description> item = descriptionList.get(langId); if (item == null || item.isEmpty()) { return null; } return item.get(descriptionId); } }
PS.
it is great that ejb 3.1 already has singleton services. -
2. Re: Can a JBoss Service-POJO be a Seam component?
cvolk Jan 30, 2009 11:47 PM (in response to cvolk)Thanks, Paata, for your input. I've run into a different problem - I don't get any exceptions, but I need to make sure the service is started before the main logic gets rolling, so I would need a mechanism for that. If I have any success I'll update this.
Happy Friday...!
-
3. Re: Can a JBoss Service-POJO be a Seam component?
paata.paatal.magtigsm.ge Jan 31, 2009 12:48 PM (in response to cvolk)hi chris,
seam component class check all your components, it's fields and methods, this exception i got means that if i need @PersistenceContext then this component must be session bean or message driven bean.
Error Stacktrace :
at org.jboss.seam.Component.checkPersistenceContextForComponentType(Component.java:898) at org.jboss.seam.Component.scanField(Component.java:874) at org.jboss.seam.Component.initMembers(Component.java:554) at org.jboss.seam.Component.<init>(Component.java:245) at org.jboss.seam.Component.<init>(Component.java:206) at org.jboss.seam.init.Initialization.addComponent(Initialization.java:1162)
i don't know is this bug or not.
if you resolve this problem post here.Regards,
Paata Lominadze
Magticom LTD.