12 Replies Latest reply on Aug 13, 2007 3:59 PM by Pete Muir

    Using stateless beans generated by seam in standalone Java a

    xiaojun ding Newbie

      I am pretty new to seam framework but have 3 years experience with previous versions of EJB. Our project is using seam to generate codes for a web application to access backend database. It works pretty good. However, I have the need to access the same database in standalone Java applications outside of Jboss virtual machine. When I looked at the seam-generated code, I am lost and need help.

      First how to look up session bean in my Java application? I can not find the ejb-jar.xml so I do not know what is the jndi name used for the generated beans. Second, I do not know how to call those generated beans. For example, I have a table called Host in a test database, the table is simple with id, hostname, and connect_time. Use seam setup, seam new-project, seam generate-entities, and seam explode, seam framework did almost everything for me. It generates two java files in the action folder. Here is the code: in HostList.java

      @Name("hostList")
      public class HostList extends EntityQuery {
      
       private static final String[] RESTRICTIONS = {"lower(host.hostname) like concat(lower(#{hostList.host.hostname}),'%')",};
      
       private Host host = new Host();
      
       @Override
       public String getEjbql() {
       return "select host from Host host";
       }
      
       @Override
       public Integer getMaxResults() {
       return 25;
       }
      
       public Host getHost() {
       return host;
       }
      
       @Override
       public List<String> getRestrictions() {
       return Arrays.asList(RESTRICTIONS);
       }
      
      }


      in HostHome.java

      @Name("hostHome")
      public class HostHome extends EntityHome<Host> {
      
       public void setHostId(Integer id) {
       setId(id);
       }
      
       public Integer getHostId() {
       return (Integer) getId();
       }
      
       @Override
       protected Host createInstance() {
       Host host = new Host();
       return host;
       }
      
       public void wire() {
       }
      
       public boolean isWired() {
       return true;
       }
      
       public Host getDefinedInstance() {
       return isIdDefined() ? getInstance() : null;
       }
      
      }


      By looking at the code, I am lost at how I should call the bean to make select, update, delete, and insert operations.

      Would anyone give me some help or point me to some documents or tutorials? Thanks a lot.