java - Hibernate EJB architecture - Model ClassNotFoundException -


i'm trying understand basic architecture of javaee achitecture working struts2, hibernate , ejb.

i have simple application add employees , list them.

so far, i've made 3 projects in eclipse:

  • jpa project contains model linked database
  • ejb project handle service layer
  • dynamic web project struts 2

dynamic web project > controller.employeeaction.java:

import local.employeeservice; import model.employee;  public class employeeaction extends actionsupport {         private employee employee;     private collection<employee> employeelist;      @ejb     private employeeservice employeemanager;      public string execute() {         this.employeelist = employeemanager.findall();         return success;     }      public string add() {         employeemanager.additem(this.employee);         this.employeelist = employeemanager.findall();         return success;     }      [...] } 

ejb project > local.employeeservice.java:

import model.employee;  @stateless public class employeeservice {      @persistencecontext     private entitymanager em;       public void additem(employee i) {          em.persist(i);      }       public collection<employee> findall() {          query query = em.createquery("select e employee e");          return (collection<employee>) query.getresultlist();      } } 

jpa project > model.employee:

@entity @table(name="\"employee\"") @namedquery(name="employee.findall", query="select e employee e") public class employee implements serializable {     private static final long serialversionuid = 1l;      @id     @column(unique=true, nullable=false)     private integer idemployee;      @column(length=255)     private string password;      @column(nullable=false, length=255)     private string username;      public employee() {     }      public integer getidemployee() {         return this.idemployee;     }      public void setidemployee(integer idemployee) {         this.idemployee = idemployee;     }          [...] } 

but when try add employee, classnotfoundexception model.employee.

the classpath seems good. missing ?

you need add jpa proyect dependency in ejb proyect, , mark web library dependency in properties -> java ee module dependencies.

good luck


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -