jsp - Empty EntityManager in Java EE bean on JBoss 5.1 -
i'm newbie in java ee. first project i'm trying , have problem can't solve.
i've created 3 projects: slowka-beans (ejb), slowka-persistance (jpa) , slowka-web(jsf). after deploying them can't access persistence unit - entitymanager null. works fine - can create beans, inside them instantiate entity classes , show them on jsf page. how can store them in db? have mysql database configured on jboss site.
the code have looks following: languagesmanager.java (in slowka-beans)
@stateless public class languagesmanager implements languagesmanagerlocal { @persistencecontext(unitname="slowka-persistance") private entitymanager em; public languagesmanager() { system.out.println("languagesmanagerbean constructor"); } public string getworking() { if(em == null) { system.out.println("not working..."); return "not working..."; } else { system.out.println("it's alive!"); return "it's alive!"; } } }
persistence.xml (slowka-persistance):
<?xml version="1.0" encoding="utf-8"?> <persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"> <persistence-unit name="slowka-persistance"> <provider>org.hibernate.ejb.hibernatepersistence</provider> <jta-data-source>java:/praktykids</jta-data-source> <class>pl.edu.uj.sobczak.szymon.language</class> </persistence-unit> </persistence>
deploying on server doesn't cause exceptions. i've spotted following warnings in server's output:
23:02:23,801 info [persistenceunitdeployment] starting persistence unit persistence.unit:unitname=slowka.ear/slowka-persistance.jar#slowka-persistance 23:02:23,803 info [ejb3configuration] processing persistenceunitinfo [ name: slowka-persistance ...] 23:02:23,804 warn [ejb3configuration] persistence provider caller not implement ejb3 spec correctly. persistenceunitinfo.getnewtempclassloader() null. (... trimmed ...) 23:02:23,868 info [sessionfactoryobjectfactory] bound factory jndi name: persistence.unit:unitname=slowka.ear/slowka-persistance.jar#slowka-persistance 23:02:23,868 warn [sessionfactoryobjectfactory] initialcontext did not implement eventcontext
every time i'm accessing languagesmanager::getworking()
jsp i'm getting "not working..." output.
i've created project in eclipse, jpa using eclipselink. i've tried both - eclipselink 1.1.4 , 2.1.0 same result.
can please me?
don't call ejbs jsps. call them servlets, inject them @ejb
.
if instantiate object manually, injection not happen. object (ejb) must instantiated ejb container.
Comments
Post a Comment