-
2. Re: Using stateless beans generated by seam in standalone Ja
jbossding Jul 12, 2007 12:03 PM (in response to jbossding)enzhao,
Thanks for the reply. However, I am looking for solution to use seam generated session/entity beans in standalone Java client, not JSF. My standalone Java client has no user interface at all, let alone JSF. Once the ejb code generated by seam-gen, I would prefer no code modification at all. Actually, I am starting to wonder if the seam-generated code is standard ejb3 because I did not find @stateless in HostHome.java or HostList.java.
Thanks and waiting for more help. -
4. Re: Using stateless beans generated by seam in standalone Ja
ntsankov Jul 12, 2007 4:15 PM (in response to jbossding)"JbossDing" wrote:
... My standalone Java client has no user interface at all, let alone JSF. Once the ejb code generated by seam-gen, I would prefer no code modification at all. Actually...
ROFL
Nice one :) Good laugh -
5. Re: Using stateless beans generated by seam in standalone Ja
jbossding Jul 12, 2007 4:31 PM (in response to jbossding)The link above does not help me but I still appreciate it. I need idea if it is possible to use seam-generated code in plain java application.
Based on my simple understanding of seam-gen, not seam, if I have a database with tables, I can use seam-gen to generate a web application in 5 minutes. That is terrific. However, I have another plain java application also needs to access and manipulate the database. I do not want to code another data-access layer. I would like to use the code generated by seam-gen. This standalone Java application will run out of JBoss and I wonder if my java code can use the seam-gen generated data-access code.
Why it concerns me is the code generated by seam-gen seems not ejb3 (without @stateless etc.) and I do not know how could standalone java application look it up using JNDI (there is no ejb-jar.xml to define jndi binding).
Could someone tell if it is doable, and if so, give me some direction. Many thanks. -
6. Re: Using stateless beans generated by seam in standalone Ja
trickyvail Jul 12, 2007 4:53 PM (in response to jbossding)The entity beans generated by seam-gen are EJB3 beans. I don't see any reason why you should not be able to use them directly in a stand alone java application (outside of JBoss). You will have to create an application managed persistence context to do so.
-
7. Re: Using stateless beans generated by seam in standalone Ja
trickyvail Jul 12, 2007 5:03 PM (in response to jbossding)Here is an example of an "Application-Managed Entity Manager" from the book "Pro EJB 3"
public class EmployeeClient { public static void main(String[] args) { EntityManagerFactory emf = Persistence.createEntityManagerFactory("EmployeeService"); EntityManager em = emf.createEntityManager(); Collection emps = em.createQuery("SELECT e FROM Employee e") .getResultList(); for(Iterator i = emps.iterator(); i.hasNext();) { Employee e = (Employee) i.next(); System.out.println(e.getId() + ", " + e.getName()); } em.close(); emf.close(); }
* from page 117 -
8. Re: Using stateless beans generated by seam in standalone Ja
jbossding Jul 13, 2007 12:17 AM (in response to jbossding)Thanks for the reply and code example. But I thought the code generated by seam-gen is not ejb (please refer to my above first message). I am very shallow on seam so far. When I follow the seam tutorial of the Registration example, everything is making sense, like you will code the session bean with annotation @stateless and entity bean with @entity. What's more, there is a ejb-jar.xml for deployment descriptor and each bean has remote methods that client can call, for example method register().
However, if you look closely at the generated code as I posted above, for table host, seam-gen generated 2 java files in src/Action folder, which I think should be where session beans are. They HostHome.java and HostList.java. By looking at those code closely, they do not have annotation @stateless or @entity. What is more, I do not know what remote methods will execute CRUD operations. For example, in HostHome.java, it has setHostId, getHostId, isWired, wire, getDefinedInstance. If I need to update the records, what remote method to call?
I am not very familiar with JPA. I thought the code you put in the last message is for client to use JPA to query database. That is terrific. However, because seam-gen generated data-access layer codes like session bean and entity beans, I would like to be lazy and use the generated codes in client directly.
After a little reading of seam, it occurs to me that seam-gen generated data-access code in src/Action folder is not suitable for direct call from a standalone java application. Please correct me if I am wrong. I really need some jboss seam guru to tell me if there is a way for standalone java client (replacing jsf) to reuse seam-gen generated data-access codes. seam-gen is great, but it's just too mysterious for me to us in a not so usual way.
Thanks for your attention nd help -
9. Re: Using stateless beans generated by seam in standalone Ja
matt.drees Jul 13, 2007 12:32 AM (in response to jbossding)Seam lets you use Ejb3 session beans or plain java beans as components. (See the documentation linked to by enzhao). Many of the examples use session beans. Seam-gen creates apps that use java beans. So no, you couldn't remotely use them.
However, I don't think it'd take too much work to turn them into Ejb3 session beans. You'd have to create a business interface for them and tag them with @Stateful. I think that's it, though don't quote me on that. -
10. Re: Using stateless beans generated by seam in standalone Ja
pmuir Jul 13, 2007 10:56 AM (in response to jbossding)Seam-gen doesn't generate EJB3 SFSBs/SLSBs but JavaBean Seam components. As Matt says, you can probably convert them into EJB3s easily, and then, as long as you do a JNDI lookup, you should be fine. This isn't the right forum to ask about accessing EJB3s from a java app (try the EJB3 forum as a start).
-
11. Re: Using stateless beans generated by seam in standalone Ja
jbossding Aug 13, 2007 3:51 PM (in response to jbossding)Hi Pete and Matt, Thanks for the reply. I just wonder is there a way for seam-gen to generate EJB session beans instead of seam javabean components. In seam-gen setup, I specify it is ear project, but it still generates javabean. Thanks
-
12. Re: Using stateless beans generated by seam in standalone Ja
pmuir Aug 13, 2007 3:59 PM (in response to jbossding)Not currently. I don't think there is a JIRA feature request for this open either.