| Author |
Confusion in accessing ENTITY bean
|
Devendra Thomare
Greenhorn
Joined: Dec 13, 2008
Posts: 15
|
|
HI ,
1. I have created Employee class and qualified it as @Entity(name = "EMPLOYEE")
2. Then I created Persistence.xml as follows
<persistence>
<persistence-unit name="EmployeePersistentUnit">
<jta-data-source>java:/DefaultDS</jta-data-source>
<properties>
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
</properties>
</persistence-unit>
</persistence>
3.I then created one stateless bean and tried to access Employee entity in that as follows
@PersistenceContext(unitName = "EmployeePersistentUnit")
private EntityManager entityManager;
.
.
.
Employee emp1 = createEmployee("Johny", 35, 10000, 1L);
entityManager.persist(emp1);
4. Then I created one standalone client to access above stateless bean as follows :
Context con =new InitialContext();
Object ref = con.lookup("PersistenceEmployeeBean/remote");
PersistenceEmployee calc = (PersistenceEmployee) PortableRemoteObject.narrow(ref, PersistenceEmployee.class);
calc.createEmployees();
And it worked fine ….Am able to insert,select Employee from table
Now In same standalone client I am using following code
EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("EmployeePersistentUnit");
EntityManager em1= entityManagerFactory.createEntityManager();
But this gives me following error .
javax.persistence.PersistenceException: No Persistence provider for EntityManager named EmployeePersistentUnit
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:33)
at by.iba.client.EmployeeTest.main(EmployeeTest.java:114)
Further in stateless bean which I have created to access entity if I use this code
EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("EmployeePersistentUnit");
EntityManager em1= entityManagerFactory.createEntityManager();
Instead of
@PersistenceContext(unitName = "EmployeePersistentUnit")
private EntityManager entityManager;
Then also it works fine …. (I am using JBOSS with eclipse )
So my doubt was if I want to access Entity bean from some standalone client( and not using starteless or stateful bean) how can I do that ?
Please forgive me …I know there would be so many simple mistakes or silly question or observation which I might have done …..since I am beginner in EJB world
Thanks,
Devendra Thomare
|
SCJP 88% SCWCD 88%SCBCD 88%
|
 |
 |
|
|
subject: Confusion in accessing ENTITY bean
|
|
|