Injecting EntityManager

Hi,
I tried to get the entity manager injected into my servlet context listener class but with no success.
I am using JPA with Toplink and deploying on Sun Application Server.
The servlet is a simple servlet which has a field of type EntityManager and with @PersistenceContext annotation.
I also tried to get the EntityManagerFactory injected. Even it is null.
Is it at all possible to inject EntityManager into a normal servlet?
Please help.
Thanks in advance.
Regards,
Anand.

Hi,
Try verifying that all configuration details are set for OC4J.
You may refer the to following end-to-end quickstart enterprise application tutorial that contains the same @PersistenceContext injection on a stateless session ejb bean.
http://wiki.eclipse.org/EclipseLink/Examples/JPA/OC4J_Web_Tutorial
specifically
http://wiki.eclipse.org/EclipseLink/Examples/JPA/OC4J_Web_Tutorial#Perform_a_JPQL_query
and code
http://dev.eclipse.org/svnroot/rt/org.eclipse.persistence/trunk/examples/org.eclipse.persistence.example.jpa.server.oc4j.enterpriseEJB/ejbModule/org/eclipse/persistence/example/jpa/server/business/ApplicationService.java
If configurations match between both apps, then we can triage further.
thank you
/michael
www.eclipselink.org

Similar Messages

  • How to inject EntityManager in non-EJB based WebService?

    Hi,
    I want to know how we can inject EntityManager in non-EJB based WebService?
    Regards,
    imran

    I think the way to go would be to actually do use an EJB for the persistence stuff and use that EJB in your webservice. Use the right tool for the job and all that.

  • How to inject EntityManager dynamically

    I have a class in which I want to inject a EntityManager based on not compile time known persistence unit name.
    In an EE environment you would normally do something like
    @PersistenceContext(unitName="pu1") private EntityManager em;
    Now the problem is that I want this "pu1" to be dynamic based based upon a parameter.
    In an SE environment (or also EE) I could create a
    emf = Persistence.createEntityManagerFactory(name);
    manually and pass in a dynamic persistence unit name.
    But creating the emf is exepensive.
    What is best way to do this in an EE environment?

    If there will only be one persistence unit in scope then you can just leave the unitName out altogether :
    @PersistenceContext private EntityManager em;
    In this case the container will just consider the one persistence unit defined at the module or application level as the default and inject it.
    If there might be more than one, you can define the dependency in your web.xml or ejb-jar.xml file.
    That will allow you to set the unit-name without having to recompile the code.
    persistence-context-ref is the analog of @PersistenceContext within the deployment descriptor :
    <persistence-context-ref>
    <persistence-context-ref-name>persistence/myemref</persistence-context-ref-name>
    <persistence-unit-name>pu1</persistence-unit-name>
    </persistence-conetxt-ref>
    Then you could look it up via java:comp/env :
    (EntityManager) initialContext.lookup("java:comp/env/persistence/myemfref");
    If you want to get a little fancier, you can use the .xml elements to cause the injection to happen.
    <persistence-context-ref>
    <persistence-context-ref-name>persistence/myemref</persistence-context-ref-name>
    <persistence-unit-name>pu1</persistence-unit-name>
    <injection-target>
    <injection-target-class>com.acme.Foo</injection-target-class>
    <injection-target-name>em</injection-target-name>
    </injection-target>
    </persistence-conetxt-ref>
    Then your java code would look like :
    // dependency and injection declared via deployment descriptor
    private EntityManager em;
    --ken                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Injecting EntityManager into Interceptor class, naming exception

    Hello , I try the code below :
    class MyInterceptor {
    @PersistenceContext(unitName="Model")
    private EntityManager em;
    @AroundInvoke
    doIntercept....
    but I got a naming exception , oc4j told me ....failed to inject the resource.....
    Anyone know ,why ?
    Anyway I resolved to make a special name into context :
    class MySessioBean { // this bean use MyInterceptor
    @PersistenceContext(name ="AdminPC",unitName="Model")
    private EntityManager em;
    and on MyInterceptor :
    class MyInterceptor{
    @AroundInvoke
    public Object doIntercept(InvocationContext ic)throws BusinessException{
    try {
    InitialContext ctx = new InitialContext();
    EntityManager temp = (EntityManager)ctx.lookup("java:comp/env/AdminPC");
    em =temp;
    } catch (NamingException e) {
    // TODO
    }

    Hi,
    Try verifying that all configuration details are set for OC4J.
    You may refer the to following end-to-end quickstart enterprise application tutorial that contains the same @PersistenceContext injection on a stateless session ejb bean.
    http://wiki.eclipse.org/EclipseLink/Examples/JPA/OC4J_Web_Tutorial
    specifically
    http://wiki.eclipse.org/EclipseLink/Examples/JPA/OC4J_Web_Tutorial#Perform_a_JPQL_query
    and code
    http://dev.eclipse.org/svnroot/rt/org.eclipse.persistence/trunk/examples/org.eclipse.persistence.example.jpa.server.oc4j.enterpriseEJB/ejbModule/org/eclipse/persistence/example/jpa/server/business/ApplicationService.java
    If configurations match between both apps, then we can triage further.
    thank you
    /michael
    www.eclipselink.org

  • EJB JTA EntityManager not injected (null)

    Hello,
    I'm writing an enterprise application which uses JSF, EJB and the Java Persistence API (JPA) and I ran into a problem.
    I'm trying to implement username and password based authentication with the username and password stored in a database. The problem is that I cannot access the database because my injected EntityManager is always null.
    Here are some details: My application is called application, it has two modules: a Web application module (application-web) and an EJB module (application-ejb).
    I have a JSP page in which I use JSF tag libraries (login.jsp). I have a backing bean specifically for authentication purposes, called AuthenticationBackingBean. The backing bean is properly declared in faces-config.xml, I can access it without any problems. It has a method, authenticate, which I use to check if the current username and password (stored in the bean from the JSP) validate against the database. authenticate solves this by calling an EJB method with the same name. The EJB is injected with the @EJB annotation. It works, there's no problem calling the authenticate method of the EJB through the remote interface.
    The problems begin in my EJB, AuthenticationBean. I inject the EntityManager (em) into the EJB with the @PersistenceContext annotation. I understand that injecting it into EJBs should work, because they're container-managed. The problem is that it is always null, I used java.utils.logging.Logger to log its value in the server log. I also tried to inject EntityManagerFactory with the @PersistenceUnit annotation. It doesn't work either, it's null, just like em. I have read about 10 other posts and could not find any solution.
    Some other information: I inject the EntityManager in the EJB outside of any method, I understood that it would pose a problem. The server doesn't say anything, the DB tables are created. I'm using Sun Java System Application Server Platform Edition 9.0 Update 1 Patch 1.
    Here are some of the relevant parts of the code:
    AuthenticationBackingBean.java
    (the backing bean)
    package com.aci.application.backing;
    import com.aci.application.ejb.AuthenticationRemote;
    import javax.ejb.EJB;
    public class AuthenticationBackingBean
        private Boolean authenticated;
        private String password;
        private String username;
        @EJB
        AuthenticationRemote authenticationBean;
        public AuthenticationBackingBean()
         authenticated = false;
        public String authenticate()
         if (authenticationBean.authenticate(username, password) == false)
             return "failure";
         return "success";
        public Boolean getAuthenticated()
         return authenticated;
        public void setAuthenticated(Boolean authenticated)
         this.authenticated = authenticated;
        public String getPassword()
         return password;
        public void setPassword(String password)
         this.password = password;
        public String getUsername()
         return username;
        public void setUsername(String username)
         this.username = username;
    AuthenticationBean.java
    (the EJB)
    package com.aci.application.ejb;
    import com.aci.application.entity.UserDBAO;
    import java.util.logging.Logger;
    import javax.ejb.Stateless;
    import javax.persistence.EntityManager;
    import javax.persistence.PersistenceContext;
    @Stateless
    public class AuthenticationBean implements com.aci.application.ejb.AuthenticationRemote
        private UserDBAO dbao;
        @PersistenceContext
        private EntityManager em;
        private Logger logger;
        public AuthenticationBean()
         dbao = new UserDBAO(em);
         logger = Logger.getLogger("com.aci.application.ejb.AuthenticationBean");
         String record = "";
         record += "em: " + em + "\n";
         logger.info(record);
        public Boolean authenticate(final String username, final String password)
         if (dbao.getUserByCredentials(username, password) == null)
             return false;
         return true;
    UserDBAO.java
    (I use this class to access the entities (currently only entity).)
    package com.aci.application.entity;
    import java.util.logging.Logger;
    import javax.persistence.EntityManager;
    public class UserDBAO
        private EntityManager em;
        private Logger logger;
        public UserDBAO(EntityManager em)
         this.em = em;
         logger = Logger.getLogger("com.aci.application.entity.UserDBAO");
        public User getUserByCredentials(final String username, final String password)
         String record = "";
         record += "em: " + em + "\n";
         logger.info(record);
         return null;
         return (User)em.createNamedQuery("getUserByCredentials")
             .setParameter("username", username)
             .setParameter("password", password)
             .getSingleResult();
    User.java
    (the entity)
    package com.aci.application.entity;
    import java.io.Serializable;
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.GenerationType;
    import javax.persistence.Id;
    import javax.persistence.NamedQuery;
    import javax.persistence.Table;
    @Entity
    @NamedQuery
        name = "getUserByCredentials",
        query =
         "SELECT user " +
            "FROM User user " +
         "WHERE user.username = :username AND user.password = :password"
    @Table(name = "Users")
    public class User implements Serializable
        private Long id;
        private String username;
        private String password;
        @Id
        @GeneratedValue(strategy = GenerationType.TABLE)
        public Long getId()
            return this.id;
        public void setId(Long id)
         this.id = id;
        @Column(name = "username")
        public String getUsername()
         return username;
        public void setUsername(String username)
         this.username = username;
        @Column(name = "password")
        public String getPassword()
         return password;
        public void setPassword(String password)
         this.password = password;
    persistence.xml
    I've read that if some version number is wrong the container does not bother to inject.
    <?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="ApplicationPersistenceUnit" transaction-type="JTA">
        <provider>oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider</provider>
        <jta-data-source>jdbc/TestDB</jta-data-source>
        <properties>
          <property name="toplink.ddl-generation" value="create-tables"/>
        </properties>
      </persistence-unit>
    </persistence>I don't know if this will do any good, but I'm posting web.xml and faces-context.xml too.
    web.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <!--
    <web-app version="2.5"
          xmlns="http://java.sun.com/xml/ns/javaee"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    -->
    <web-app xmlns="http://java.sun.com/xml/ns/javaee"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
          version="2.5">
        <servlet>
            <servlet-name>Faces Servlet</servlet-name>
            <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
            <load-on-startup>1</load-on-startup>
        </servlet>
        <servlet-mapping>
            <servlet-name>Faces Servlet</servlet-name>
            <url-pattern>/faces/*</url-pattern>
        </servlet-mapping>
        <session-config>
            <session-timeout>30</session-timeout>
        </session-config>
    </web-app>
    faces-context.xml
    <?xml version='1.0' encoding='UTF-8'?>
    <faces-config version="1.2" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd">
        <navigation-rule>
            <from-view-id>/login.jsp</from-view-id>
         <navigation-case>
             <from-outcome>failure</from-outcome>
             <to-view-id>/failure.jsp</to-view-id>
         </navigation-case>
            <navigation-case>
             <from-outcome>success</from-outcome>
             <to-view-id>/success.jsp</to-view-id>
         </navigation-case>
        </navigation-rule>
        <managed-bean>
         <managed-bean-name>authentication</managed-bean-name>
         <managed-bean-class>com.aci.application.backing.AuthenticationBackingBean</managed-bean-class>
         <managed-bean-scope>session</managed-bean-scope>
        </managed-bean>
    </faces-config>I'm totally new to Java EE, this is my first application (test program), I would really appreciate some detailed information, please.

    Hi Csabi,
    Glad to hear it fixed your issue.
    --ken                                                                                                                                                                                                           

  • Using EntityManager inside an entity

    I have a JPA entity which contains a List of other entities. My containing entity has a method which logically requires the List to be emptied. It's straightforward to iterate over the list, and null the reference from the containing entity to the contained entity, and vice versa. However, the contained entities also need to be removed from the database. The obvious place to do this is in the loop that nulls the references, using an injected EntityManager as follows:
    @Entity
    public class Experiment implements Serializable {
    @PersistenceContext(unitName="SchedulingPU", type=PersistenceContextType.EXTENDED)
    EntityManager em;
    private int granularity = 0; // # minutes in a time slot
    * Holds value of property days.
    * If the experiment is persisted, its days must be persisted, too.
    @OneToMany(mappedBy = "experiment", cascade=CascadeType.PERSIST)
    private List<Day> days;
    /** deletes all days */
    public void resetGranularity(int granularity) {
    for (Iterator<Day> i = days.iterator(); i.hasNext(); ) {
    Day day = i.next();
    day.setExperiment(null);
    em.remove(day);
    days.clear();
    this.granularity = granularity;
    However, when I inject an EntityManager into my containing entity, I get the following error:
    Caused by: org.apache.derby.client.am.SqlException: Column 'EM' is either not in any table in the FROM list or appears within a join specification and is outside the scope of the join specification or appears in a HAVING clause and is not in the GROUP BY list. If this is a CREATE or ALTER TABLE statement then 'EM' is not a column in the target table.
    Obviously, it's trying to persist the injected EntityManager, which is not a meaningful thing to do. However, making the em field transient is illegal.
    Should I be passing the entity manager from a session bean? Should the containing object (Experiment) ask a session bean to remove the contained objects (Days) from the database (breaking encapsulation)? Or should I go about this some entirely other way?

    Problem solved. I've added this line
    <option>-lc++</option>
    to the platformOptions.xml.
    Now OpenCV works great in my actionscript native extension.

  • 11g Release 1 Patch Set 3 (WLS 10.3.4)

    Hi.
    While creating new server in OEPE Helios(11.1.1.6) I found that WLS 10.3.4 is available for selection. However I didnt find any information neither links to download it. Only 10.3.3 is available.
    When and where it is\would be available for download?
    Thanks

    frf,
    Hello, as part of the WebLogic 10.3.4 release on friday - we verified JPA 2.0 functionality for enterprise users using JPA as their persistence pattern. The main issues were JPA 2.0 XSD validation and JPA 2.0 container managed persistence unit injection.
    The details of the following post outline what happens out of the box and how JPA 2.0 can be officially enabled on JEE5 compliant WebLogic 10.3.4 install +(with or without the QWG8 patch)+
    In 10.3.3.0 you were required to use the FilteringClassLoader via the *<wls:prefer-application-packages>* addition to your application managed persistence unit - this workaround is now deprecated and not required in 10.3.4.0 for both application and container managed persistence contexts.
    Specifically we will start retesting EE applications using a SSB injected @PersistenceContext container managed JTA transactional JPA 2.0 persistence units with/without JPA 2.0 XSD elements.
    I verified the server and it is using SVN rev# *8635 from 6 Dec 2010* https://fisheye2.atlassian.com/changelog/eclipselink/?cs=8635
    Essentially in order to enable JPA 2.0 functionality on WebLogic 10.3.4 shipped on 14 Jan 2011 - you apply the QWG8 patch below or manually edit your server classpath to put the JPA 2.0 persistence specification API jar and the com.oracle.jpa2support_1.0.0.0_2-0.jar ahead of the other liibraries on the classpath.
    commEnv.cmd: line 67
    @rem Set BEA Home
    set BEA_HOME=C:\opt\wls1034r20110115
    @rem Enable JPA 2.0 functionality on WebLogic Server 10.3.4 with the following patch line for commEnv.cmd:67
    set PRE_CLASSPATH=%BEA_HOME%\modules\javax.persistence_1.0.0.0_2-0-0.jar;%BEA_HOME%\modules\com.oracle.jpa2support_1.0.0.0_2-0.jarEverything is shipped with WebLogic 10.3.4 but JPA 1.0 is enabled by default so that this JEE5 capable server is backwards compatible with JEE5/JPA1 out of the box. Without the above patch you will see the following.
    <15-Jan-2011 5:58:40 o'clock PM EST> <Info> <Management> <BEA-141107> <Version: WebLogic Server 10.3.4.0 Fri Dec 17 20:47:33 PST 2010 1384255 >
    [EL Info]: 2011-01-15 18:06:38.082--ServerSession(48997950)--Thread(Thread[[ACTIVE] ExecuteThread: '3' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--EclipseLink, version: Eclipse Persistence Services - 2.1.2.v20101206-r8635
    [EL Info]: 2011-01-15 18:06:38.082--ServerSession(48997950)--Thread(Thread[[ACTIVE] ExecuteThread: '3' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--Server: 10.3.4.0
    We have the required bundles in the modules directory...
    javax.persistence_1.0.0.0_2-0-0.jar (upgraded from 1-0-2)
    org.eclipse.persistence_1.0.0.0_2-1.jar (upgraded from 2-0)
    A very quick test of a JPA 2.0 container managed app with the following persistence.xml in the ejb.jar works as detailed below.
    There are 3 issues we must check.
    1) JPA 2.0 XSD parsing errors: as expected there are no more JPA 2.0 schema parsing issues.
    2) New JPA 2.0 schema elements like the *<shared-cache-mode>NONE</shared-cache-mode>* element - this passes validation but we need to verify runtime functionality
    3) JPA 2.0 runtime API like a entityManager.getMetamodel(); call on the Servlet or Statless session bean
    4) JPA 2.0 weaving/instrumentation - Again we need to verify something like weaving of Entities contaiing lazy IndirectLists are weaved properly by the container.
    Note: All testing in this post is on a WebLogic 10.3.4.0 install out-of-the-box. The only modification I made was in creating a derby 10.5.3.0 JTA global datasource "localJTA" on the server - and drop a container managed JPA 2.0 app as an EAR in the autodeploy directory on the default user domain.
    <persistence version="2.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_2_0.xsd">
        <persistence-unit name="example" transaction-type="JTA">
            <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> <!-- we will default to Kodo without specifying the provider -->
            <jta-data-source>localJTA</jta-data-source>
            <shared-cache-mode>NONE</shared-cache-mode><!-- shared-cache-mode must come after any class definitions (usually SE only) - the JPA schema is ordered -->
            <properties>
                <property name="eclipselink.target-server" value="WebLogic_10"/>
                <property name="eclipselink.target-database" value="Derby"/>           
                <property name="eclipselink.logging.level" value="FINEST"/>
                <!-- new for 10.3.4.0 http://wiki.eclipse.org/EclipseLink/Examples/JPA/Logging#Server_Logging  -->
                <property name="eclipselink.logging.logger" value="DefaultLogger"/>
                <!-- turn off DDL generation after the model is stable -->           
                <!-- property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
                <property name="eclipselink.ddl-generation.output-mode" value="database"/-->
            </properties>      
        </persistence-unit>For 3) we get the following exception out of the box on a servlet if we do not apply the above mentioned patch below - because the container defaults to Java EE 5 functionality - or JPA 1.0
    http://download.oracle.com/docs/cd/E18476_01/doc.220/e18480/weblogicchap.htm
    java.lang.NoSuchMethodError: javax/persistence/EntityManager.getMetamodel()Ljavax/persistence/metamodel/Metamodel;
    at org.eclipse.persistence.example.jpa.server.weblogic.enterprise.presentation.FrontController.processGliderComm
    and(FrontController.java:346)
    or 3) The same exception if we try to run JPA 2.0 on the DI entityManager from the SSB in the EJB container classLoader
    javax.ejb.EJBException: EJB Exception: : java.lang.NoSuchMethodError: javax/persistence/EntityManager.getMetamodel()Ljavax/persistence/metamodel/Metamodel;
    +     at org.eclipse.persistence.example.jpa.server.business.ApplicationService.insertObjects(ApplicationService.java:66)+
    +     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)+
    +     at java.lang.reflect.Method.invoke(Method.java:597)+
    +     at com.bea.core.repackaged.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:310)+
    +..+
    +     at $Proxy74.insertObjects(Unknown Source)+
    +     at org.eclipse.persistence.example.jpa.server.business.ApplicationService_5ptwty_ApplicationServiceLocalImpl.__WL_invoke(Unknown Source)+
    We also get the Kodo/OpenJPA provider when we attempt to weave.
    +<openjpa-1.1.1-SNAPSHOT-r422266:965591 fatal user error> org.apache.openjpa.util.MetaDataException: "org.eclipse.persistence.example.jpa.server.business.Cell.id" declares generator name "EL_SEQUENCE_CELL", but uses the AUTO generation type. The only valid generator names under AUTO are "uuid-hex" and "uuid-string".+
    +     at org.apache.openjpa.persistence.AnnotationPersistenceMetaDataParser.getGeneratedValueStrategy(AnnotationPersistenceMetaDataParser.java:1226)+
    Therefore there is still a little bit of configuration required.
    Enabling JPA2 support
    1) install the QWG8 patch, or
    2) manually add the com.oracle.jpa2support_1.0.0.0_2-0.jar ahead of the server classpath by following the instructions in the documentation at
    http://download.oracle.com/docs/cd/E17904_01/web.1111/e13720/using_toplink.htm#EJBAD1309
    or doing it manually by modifying the following line
    C:\opt\wls10340_pub110115\wlserver_10.3\common\bin\commEnv.cmd
    set PRE_CLASSPATH=%BEA_HOME%\modules\javax.persistence_1.0.0.0_2-0-0.jar;%BEA_HOME%\modules\com.oracle.jpa2support_1.0.0.0_2-0.jar
    Results
    The following code
    @Local
    @Stateless
    public class ApplicationService implements ApplicationServiceLocal {
        @PersistenceContext(unitName="example", type=PersistenceContextType.TRANSACTION)     
        private EntityManager entityManager;
        public boolean insertObjects(List<Cell> classes) {
            try {
                for(int i=0; i< classes.size(); i++) {
                    entityManager.persist(classes.get(i));
                System.out.println("JPA 2.0 Metamodel: " + entityManager.getMetamodel());           ...prints out the JPA 2.0 EntityManager dependency injected into the SSB proxy for the life of the transaction in the function
    JPA 2.0 Metamodel: MetamodelImpl@34817119 [ 5 Types: , 2 ManagedTypes: , 2 EntityTypes: , 0 MappedSuperclassTypes: , 0 EmbeddableTypes: ]+
    +[EL Finer]: 2011-01-15 22:36:00.33--UnitOfWork(34913451)--Thread(Thread[[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--TX beforeCompletion callback, status=STATUS_ACTIVE+
    You can see that when we debug the stateless session bean $Proxy that has our injected EntityManager...
    this     ApplicationService_5ptwty_Impl  (id=11616)     
         __WL_EJBContext     SessionEJBContextImpl  (id=11654)     
         entityManager     $Proxy73  (id=11639)     
              h     TransactionalEntityManagerProxyImpl  (id=11638)     
                   appName     "org.eclipse.persistence.example.jpa.server.weblogic.enterpriseEAR" (id=11513)     
                   closeMethod     Method  (id=11663)     
                   moduleName     "org.eclipse.persistence.example.jpa.server.weblogic.enterpriseEJB.jar" (id=11515)     
                   persistenceUnit     PersistenceUnitInfoImpl  (id=11665)     
                   persistenceUnitName     "org.eclipse.persistence.example.jpa.server.weblogic.enterpriseEAR#org.eclipse.persistence.example.jpa.server.weblogic.enterpriseEJB.jar#example" (id=11666)     
                   queryMethods     HashSet<E>  (id=11668)     
                   transactionAccessMethod     Method  (id=11669)     
                   transactionalMethods     HashSet<E>  (id=11670)     
                   txHelper     TransactionHelperImpl  (id=11523)     
                   txRegistry     ServerTransactionManagerImpl  (id=11524)     
                   unqualifiedPersistenceUnitName     "example" (id=11672)     ...no longer complains about an unknown getMetamodel() JPA 2.0 method signature
    Oracle WebLogic Server 11gR1 PatchSet 3 r20110115 at localhost [Oracle WebLogic Server]     
         Java HotSpot(TM) Client VM[localhost:8453]     
              Daemon Thread [[ACTIVE] ExecuteThread: '20' for queue: 'weblogic.kernel.Default (self-tuning)'] (Running)     
              Daemon Thread [[ACTIVE] ExecuteThread: '18' for queue: 'weblogic.kernel.Default (self-tuning)'] (Suspended)     
                   TransactionalEntityManagerProxyImpl.invoke(Object, Method, Object[]) line: 18     
                   $Proxy59.getMetamodel() line: not available [local variables unavailable]     
                   ApplicationService_5ptwty_Impl(ApplicationService).insertObjects(List<Cell>) line: 60     
    ..               JdkDynamicAopProxy.invoke(Object, Method, Object[]) line: 204     
                   $Proxy71.insertObjects(List) line: not available     
                   ApplicationService_5ptwty_ApplicationServiceLocalImpl.__WL_invoke(Object, Object[], int) line: not available     
                   SessionLocalMethodInvoker.invoke(BaseLocalObject, MethodDescriptor, Object[], int, String, Class<?>) line: 39     
                   ApplicationService_5ptwty_ApplicationServiceLocalImpl.insertObjects(List) line: not available     
                   FrontController.generateGlider(PrintWriter) line: 252     
    ..               FrontController(HttpServlet).service(ServletRequest, ServletResponse) line: 820     
                   StubSecurityHelper$ServletServiceAction.run() line: 227     
    ..               ExecuteThread.run() line: 176     
    arg1     Method  (id=11511)     
         clazz     Class<T> (javax.persistence.EntityManager) (id=8312)     
         name     "getMetamodel" (id=11543)     
         returnType     Class<T> (javax.persistence.metamodel.Metamodel) (id=11545)     For 4) Weaving is occuring as expected on either the JPA 1.0 or JPA 2.0 entities. We check this by either checking that our Entity is an instanceof org.eclipse.persistence.internal.weaving.PersistenceWeaved interface, or debug into the Entity and look for our bytcode instrumented weaved fields that start with _persistence*.  The question is - we need a weaved field or weaved function that was introduced for JPA 2.0
    [4]     Cell  (id=11571)     
         _persistence_fetchGroup     null     
         _persistence_primaryKey     null     
         _persistence_session     null     
         _persistence_shouldRefreshFetchGroup     false     
         aCellAttribute     null     
         id     null     
         left     null     
         peers     HashSet<E>  (id=11572)     
              map     HashMap<K,V>  (id=11575)     
    com.oracle.jpa2support_1.0.0.0_2-0.jar forensicsI had a look at the patch jar com.oracle.jpa2support_1.0.0.0_2-0.jar that WebLogic 10.3.4 ships with that allows installers to enable JPA 2.0 (JSR-317) support to superceed the default JPA 1.0 (JSR-220) support. It looks like the container proxy code for container managed EntityManagerFactory and EntityManager $Proxy objects has been updated so that a JPA 2.0 EntityManager $Proxy object get injected with the proper API level object via the InvocationHandlerFactory, FactoryInterceptor. The Query proxy has been updated as well. There is a fix for Kodo(OpenJPA) and OpenJPA related to the recent change and deprecation of certain functions of those providers. The EclipseLink JPA 2.0 provider (as the provider for TopLink) did not need weblogic changes beyond placing the JPA javax.peristence 2.0 specification jar higher on the classpath.
    The root EclipseLink tracking bug is 334468
    https://bugs.eclipse.org/bugs/show_bug.cgi?id=334468
    OTN downloadhttp://www.oracle.com/technetwork/middleware/weblogic/downloads/wls-main-097127.html
    Patching
    http://download.oracle.com/docs/cd/E18476_01/doc.220/e18480/weblogicchap.htm
    Documentationhttp://download.oracle.com/docs/cd/E17904_01/web.1111/e13852/toc.htm
    Supported Oracle WebLogic Server Versionshttp://download.oracle.com/docs/cd/E15315_06/help/oracle.eclipse.tools.weblogic.doc/html/SupportedServerVersions.html
    TopLink JPA 2.0 Specifichttp://download.oracle.com/docs/cd/E17904_01/web.1111/e13720/using_toplink.htm#EJBAD1309
    see related
    JPA 2: Reverify JPA 2.0 XSD support in persistence.xml on AM/CM app on WebLogic 10.3.3.0
    http://bugs.eclipse.org/331569
    JPA 2.0: Add WebLogic 10.3 configuration process to enable the JPA 2.0 library functionality - updated
    http://bugs.eclipse.org/296271
    http://en.wikipedia.org/wiki/Oracle_WebLogic_Server - updated
    JPA: Add downloadable 60k weblogic.EAR to wiki page (outside of SVN) - reopened
    http://bugs.eclipse.org/294745
    JPA: support WebLogic 10.3.4.0 introduction of new JPA MBean that changes the default JPA provider
    http://bugs.eclipse.org/312824
    JPA: Update tutorial wiki for WebLogic 10.3 to match the Oracle WebLogic 11g 10.3.3.0 - assigned
    http://bugs.eclipse.org/310849
    To be answered
    OTN Post: WebLogic 10.0 + JPA 2.0 = errors - updated
    Re: WebLogic 10.0 + JPA 2.0 = errors
    Deploy Hibernate based EAR file on Weblogic 10.3.3?
    OTN Post: Default JPA provider for Weblogic Server 10.3.2 (11g) - updated
    Default JPA provider for Weblogic Server 10.3.2 (11g)
    OTN Post: Hibernate 3.6 Final (JPA 2.0) + WL 10.3.x :Unable to deploy sample appn - updated
    Hibernate 3.6 Final (JPA 2.0) + WL 10.3.x :Unable to deploy sample appn
    WebLogic 10.0 + JPA 2.0 = errors
    OTN Post: EJB with Hibernate On Weblogic - updated
    Re: EJB with Hibernate On Weblogic
    OTN Post: OEPE 1.6 - Oracle WebLogic Server 11gR1 PatchSet 3 requres WLS 10.3.4 - answered
    OEPE 1.6 - Oracle WebLogic Server 11gR1 PatchSet 3 requres WLS 10.3.4
    OTN Post: EJB with Hibernate On Weblogic - updated
    Re: EJB with Hibernate On Weblogic
    OTN Post: OpenJPA_2.0 NoSuchMethod error (getValidationMode()) - updated
    OpenJPA_2.0 NoSuchMethod error (getValidationMode())
    JPA 2.0 features used on WebLogic even if they are not available at runtime - notified
    http://netbeans.org/bugzilla/show_bug.cgi?id=189205
    Option to enable JPA 2.0 for dev WebLogic - notified
    http://netbeans.org/bugzilla/show_bug.cgi?id=189348
    False-positive error badge on project with JPA targeting WebLogic - notified
    http://netbeans.org/bugzilla/show_bug.cgi?id=189626
    Giving up on Hibernate (for now), trying EclipseLink...
    http://forums.netbeans.org/post-94817.html
    http://blogs.sun.com/arungupta/entry/which_java_ee_6_app
    Eclipselink 2.0 + WebLogic 10 => No joy (Unable to get Eclipse link 2.0 working with WebLogic 10) - answered
    http://www.eclipse.org/forums/index.php?t=msg&goto=644000&S=40e13288641c0af5dc8489343b896348#msg_644000
    eclipselink-users Problem of eclipselink upgrade (2.0.2) - WebLogic 10.3.3.0 - answered
    http://dev.eclipse.org/mhonarc/lists/eclipselink-users/msg04631.html
    Re: EclipseLink + JPA 2 in Weblogic 10.3.0
    http://dev.eclipse.org/mhonarc/lists/eclipselink-users/msg04375.html - answered below
    Re: eclipselink-users Problems with Eclipselink 2 (JPA 2.0) & WebLogic 10,
    http://dev.eclipse.org/mhonarc/lists/eclipselink-users/msg05609.html
    [eclipselink-users] Problems with Eclipselink 2 (JPA 2.0) & WebLogic 10 - answered
    http://dev.eclipse.org/mhonarc/lists/eclipselink-users/msg05639.html
    To be Deprecated
    JPA 2: Reverify JPA 2.0 XSD support in persistence.xml on AM/CM app on WebLogic 10.3.3.0
    http://bugs.eclipse.org/331569
    JPA 2.0: Add WebLogic 10.3 configuration process to enable the JPA 2.0 library functionality
    http://bugs.eclipse.org/296271
    WebLogic 10.3 availability?
    / Michael O'Brien
    http://www.eclipselink.org

  • Jpa trouble

    hello
    can anyone help me with this problem
    atm i'm making a project which uses EJBs (with JPA) and some fields in the EJBs get auto generated when persisting an EJB entity to the database
    Writing to the database and reading out of it works perfectly, but when i persist a brand new entity to the table, i don't receive the brand new generated ID
    (ID is a primary key in the table)
    is there any way to update the persisted entity right after persisting it to the database ? so that my entity, which got persisted, gets his ID injected?
    this is my code for inserting a new entity into the database:
    @Transactional
    public class JPAScenarioDAO implements ScenarioDAO{
        private EntityManager entityManager;
         * Spring injects entityManager
         * @param entityManager manager that handles persistence operations
        @PersistenceContext
        public void setEntityManager(EntityManager entityManager)
          this.entityManager = entityManager;
        public JPAScenarioDAO() {}
        public void createScenario(Scenario scenario){
            entityManager.persist(scenario); // <-- help?
        public void updateScenario(Scenario scenario){
            entityManager.merge(scenario);
        public void removeScenario(Scenario scenario){
            entityManager.remove(scenario);
    }The scenario is an EJB that i generated from a table
    import java.io.Serializable;
    import java.sql.Timestamp;
    import java.util.List;
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.GenerationType;
    import javax.persistence.Id;
    import javax.persistence.JoinColumn;
    import javax.persistence.ManyToOne;
    import javax.persistence.NamedQueries;
    import javax.persistence.NamedQuery;
    import javax.persistence.OneToMany;
    import javax.persistence.Table;
    @Entity
    @NamedQueries({
        @NamedQuery(name = "Scenario.getScenarios",
                    query = "select o from Scenario o"),
        @NamedQuery(name = "Scenario.getScenariosBetweenDates",
                    query = "select o from Scenario o where o.date >= :datum1 and o.date <= :datum2"),
        @NamedQuery(name = "Scenario.getScenariosByEdition",
                    query = "select o from Scenario o where o.edition = :edition"),
        @NamedQuery(name = "Scenario.getScenariosByIssue",
                    query = "select o from Scenario o where o.issue = :issue"),
        @NamedQuery(name = "Scenario.getLast2ScenariosFromEdition",
                    query = "select o from Scenario o where o.edition = :edition order by o.date desc")
    @Table(name = "WEBE_MAKR_DRAAIBOEK")
    public class Scenario implements Serializable {
        @Id
        @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="s_webe_makr_draaiboek")
        @Column(name="DRAAIBOEK_ID", nullable = false)
        private Long scenarioID;
        @Column(name="JAAR")
        private Long year;
        @Column(name="WEEK")
        private Long week;
        @Column(name="DATUM")
        private Timestamp date;
        @ManyToOne
        @JoinColumn(name = "EDITIE_ID", referencedColumnName = "EDITIE_ID")
        private Edition edition;
        @OneToMany(mappedBy = "scenario")
        private List<ScenarioItemStatus> scenarioItemStatusList;
        @ManyToOne
        @JoinColumn(name = "VERSCHIJNING_ID", referencedColumnName = "VERSCHIJNING_ID")
        private Issue issue;
        @OneToMany(mappedBy = "scenario")
        private List<ScenarioHistory> scenarioHistoryList;
        // CONSTRUCTOR
        public Scenario() {}
        // GETTERS
        public Long getScenarioID() {
            return scenarioID;
        public Long getYear() {
            return year;
        public Long getWeek() {
            return week;
        public Timestamp getDate() {
            return date;
        public Edition getEdition() {
            return edition;
        public Issue getIssue() {
            return issue;
        public List<ScenarioItemStatus> getScenarioItemStatusList() {
            return scenarioItemStatusList;
        public List<ScenarioHistory> getScenarioHistoryList() {
            return scenarioHistoryList;
        // SETTERS
        public void setScenarioID(Long scenarioID) {
            this.scenarioID = scenarioID;
        public void setDate(Timestamp date) {
            this.date = date;
        public void setYear(Long year) {
            this.year = year;
        public void setWeek(Long week) {
            this.week = week;
        public void setEdition(Edition edition) {
            this.edition = edition;
        public void setIssue(Issue issue) {
            this.issue = issue;
        public void setScenarioItemStatusList(List<ScenarioItemStatus> scenarioItemStatusList) {
            this.scenarioItemStatusList = scenarioItemStatusList;
        public void setScenarioHistoryList(List<ScenarioHistory> scenarioHistoryList) {
            this.scenarioHistoryList = scenarioHistoryList;
        // EXTRA METHODS
        public ScenarioItemStatus addScenarioItemStatus(ScenarioItemStatus scenarioItemStatus) {
            getScenarioItemStatusList().add(scenarioItemStatus);
            scenarioItemStatus.setScenario(this);
            return scenarioItemStatus;
        public ScenarioItemStatus removeScenarioItemStatus(ScenarioItemStatus scenarioItemStatus) {
            getScenarioItemStatusList().remove(scenarioItemStatus);
            scenarioItemStatus.setScenario(null);
            return scenarioItemStatus;
        public ScenarioHistory addScenarioHistory(ScenarioHistory scenarioHistory) {
            getScenarioHistoryList().add(scenarioHistory);
            scenarioHistory.setScenario(this);
            return scenarioHistory;
        public ScenarioHistory removeScenarioHistory(ScenarioHistory scenarioHistory) {
            getScenarioHistoryList().remove(scenarioHistory);
            scenarioHistory.setScenario(null);
            return scenarioHistory;
    }Edited by: NeoSniperkiller on 17-apr-2008 14:44

    public void createScenario(Scenario scenario){
            entityManager.persist(scenario); // <-- help?
        }I've seen this happen.
    Changing it to
    public Scenario createScenario(Scenario scenario){
            entityManager.persist(scenario); // <-- help?
            return scenario;
        }(and using the returned value) for some reason worked.
    Not quite sure yet why, I'll have to do some research to figure out exactly what happens.

  • Setting session variables in application context using OpenJPA

    Hi!
    I am using openjpa 1.2 with EJB 3.0. I am connecting to Oracle 11g database and need to use the oracle virtual private database for security and data segregation. For this purpose, I need to set some custom variables at the session level of the application context such as the application user name. Since, I am using container injected EntityManager using @PersistenceContext, I am finding it hard to do so.
    Can anyone please help me out
    Thanks in advance
    Abhi

    You will probably want to ask your question on an OpenJPA forum to see if they even can support VPD (if not, see EclipseLink http://wiki.eclipse.org/Introduction_to_EclipseLink_Sessions_(ELUG)#Isolated_Client_Sessions_and_Oracle_Virtual_Private_Database_.28VPD.29 )
    You might also want to try injecting the factory instead and use that to get the EntityManager instead of injecting the em directly. ie
    @PersistenceUnit(unitName="my-pu")
    private EntityManagerFactory emf;
    Best Regards,
    Chris

  • EJB + JPA Troubles

    hello
    can anyone help me with this problem
    atm i'm making a project which uses EJBs (with JPA) and some fields in the EJBs get auto generated when persisting an EJB entity to the database
    Writing to the database and reading out of it works perfectly, but when i persist a brand new entity to the table, i don't receive the brand new generated ID
    (ID is a primary key in the table)
    is there any way to update the persisted entity right after persisting it to the database ? so that my entity, which got persisted, gets his ID injected?
    this is my code for inserting a new entity into the database:
    @Transactional
    public class JPAScenarioDAO implements ScenarioDAO{
        private EntityManager entityManager;
         * Spring injects entityManager
         * @param entityManager manager that handles persistence operations
        @PersistenceContext
        public void setEntityManager(EntityManager entityManager)
          this.entityManager = entityManager;
        public JPAScenarioDAO() {}
        public void createScenario(Scenario scenario){
            entityManager.persist(scenario); // <-- help?
        public void updateScenario(Scenario scenario){
            entityManager.merge(scenario);
        public void removeScenario(Scenario scenario){
            entityManager.remove(scenario);
    }The scenario is an EJB that i generated from a table
    import java.io.Serializable;
    import java.sql.Timestamp;
    import java.util.List;
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.GenerationType;
    import javax.persistence.Id;
    import javax.persistence.JoinColumn;
    import javax.persistence.ManyToOne;
    import javax.persistence.NamedQueries;
    import javax.persistence.NamedQuery;
    import javax.persistence.OneToMany;
    import javax.persistence.Table;
    @Entity
    @NamedQueries({
        @NamedQuery(name = "Scenario.getScenarios",
                    query = "select o from Scenario o"),
        @NamedQuery(name = "Scenario.getScenariosBetweenDates",
                    query = "select o from Scenario o where o.date >= :datum1 and o.date <= :datum2"),
        @NamedQuery(name = "Scenario.getScenariosByEdition",
                    query = "select o from Scenario o where o.edition = :edition"),
        @NamedQuery(name = "Scenario.getScenariosByIssue",
                    query = "select o from Scenario o where o.issue = :issue"),
        @NamedQuery(name = "Scenario.getLast2ScenariosFromEdition",
                    query = "select o from Scenario o where o.edition = :edition order by o.date desc")
    @Table(name = "WEBE_MAKR_DRAAIBOEK")
    public class Scenario implements Serializable {
        @Id
        @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="s_webe_makr_draaiboek")
        @Column(name="DRAAIBOEK_ID", nullable = false)
        private Long scenarioID;
        @Column(name="JAAR")
        private Long year;
        @Column(name="WEEK")
        private Long week;
        @Column(name="DATUM")
        private Timestamp date;
        @ManyToOne
        @JoinColumn(name = "EDITIE_ID", referencedColumnName = "EDITIE_ID")
        private Edition edition;
        @OneToMany(mappedBy = "scenario")
        private List<ScenarioItemStatus> scenarioItemStatusList;
        @ManyToOne
        @JoinColumn(name = "VERSCHIJNING_ID", referencedColumnName = "VERSCHIJNING_ID")
        private Issue issue;
        @OneToMany(mappedBy = "scenario")
        private List<ScenarioHistory> scenarioHistoryList;
        // CONSTRUCTOR
        public Scenario() {}
        // GETTERS
        public Long getScenarioID() {
            return scenarioID;
        public Long getYear() {
            return year;
        public Long getWeek() {
            return week;
        public Timestamp getDate() {
            return date;
        public Edition getEdition() {
            return edition;
        public Issue getIssue() {
            return issue;
        public List<ScenarioItemStatus> getScenarioItemStatusList() {
            return scenarioItemStatusList;
        public List<ScenarioHistory> getScenarioHistoryList() {
            return scenarioHistoryList;
        // SETTERS
        public void setScenarioID(Long scenarioID) {
            this.scenarioID = scenarioID;
        public void setDate(Timestamp date) {
            this.date = date;
        public void setYear(Long year) {
            this.year = year;
        public void setWeek(Long week) {
            this.week = week;
        public void setEdition(Edition edition) {
            this.edition = edition;
        public void setIssue(Issue issue) {
            this.issue = issue;
        public void setScenarioItemStatusList(List<ScenarioItemStatus> scenarioItemStatusList) {
            this.scenarioItemStatusList = scenarioItemStatusList;
        public void setScenarioHistoryList(List<ScenarioHistory> scenarioHistoryList) {
            this.scenarioHistoryList = scenarioHistoryList;
        // EXTRA METHODS
        public ScenarioItemStatus addScenarioItemStatus(ScenarioItemStatus scenarioItemStatus) {
            getScenarioItemStatusList().add(scenarioItemStatus);
            scenarioItemStatus.setScenario(this);
            return scenarioItemStatus;
        public ScenarioItemStatus removeScenarioItemStatus(ScenarioItemStatus scenarioItemStatus) {
            getScenarioItemStatusList().remove(scenarioItemStatus);
            scenarioItemStatus.setScenario(null);
            return scenarioItemStatus;
        public ScenarioHistory addScenarioHistory(ScenarioHistory scenarioHistory) {
            getScenarioHistoryList().add(scenarioHistory);
            scenarioHistory.setScenario(this);
            return scenarioHistory;
        public ScenarioHistory removeScenarioHistory(ScenarioHistory scenarioHistory) {
            getScenarioHistoryList().remove(scenarioHistory);
            scenarioHistory.setScenario(null);
            return scenarioHistory;
    }Edited by: NeoSniperkiller on 17-apr-2008 14:46

    What database and JPA provider are you using? Since you are using a SEQUENCE object to generate the id, you should see it assigned after calling the persist(). Potentially you are using IDENTITY sequencing (not on Oracle), so you must first call flush() to have the id assigned.
    see,
    [http://en.wikibooks.org/wiki/Java_Persistence/Identity_and_Sequencing#Object.27s_id_is_not_assign_after_persist|http://en.wikibooks.org/wiki/Java_Persistence/Identity_and_Sequencing#Object.27s_id_is_not_assign_after_persist]
    -- James : EclipseLink

  • EntityManager no longer being injected after upgrade

    I upgraded the version of JSF being used by the Sun Java Application Server 9 to 1.2_02 by using the upgrade jar on the download site. After doing this, it appears that the JPA EntityManager is no longer being injected (I keep getting a NullPointer exception in the Controller's getEntityManager method).
    Is there something I have to do differently with 1.2 to get the EntityManager injected?
    cheers.

    Yes. Please see this thread:
    http://forums.java.net/jive/thread.jspa?threadID=17933&tstart=15

  • Com.sap.sql.log.OpenSQLException during EntityManager Call

    Hi!
    I deployed an EJB3 session bean on the NW 7.1.
    The aim is to use JPA with this bean.
    I configured the "persistence.XML" for the bean project and packed it into the jar File and a "data-source-aliases.xml" which is included in the ear file. The packaging of the ear-file is done with the developerStudio and deployed on the NW 7.1
    Then I created a dataSource project which contains the "data-sources.xml" and deployed this too.
    Here is my data-sources.xml:
    <?xml version="1.0" encoding="utf-8"?>
    <!DOCTYPE data-sources SYSTEM 'data-sources.dtd'>
    <data-sources>
        <data-source>
            <data-source-name>JPA_SDN_EXAMPLE_DS_555</data-source-name>
            <driver-name>ora10</driver-name>
            <sql-engine>native_sql</sql-engine>
            <jdbc-1.x>
                <driver-class-name>oracle.jdbc.driver.OracleDriver</driver-class-name>
    <!-- *** Edit the following entries appropriately *** -->
                <url>jdbc:oracle:thin:@10.XXX.7.27:1521:orcl</url>
                <user-name>bdeadm</user-name>
                <password>dmin</password>
    <!-- *** End editing ***  -->
            </jdbc-1.x>
        </data-source>
    </data-sources>
    My deployed session bean looks like this:
    @Stateless(name="WorkerBean")
    public class WorkerBean implements WorkerRemote {
         @PersistenceContext(unitName="JPAModel")
        private EntityManager em;
         public String sayHello() {
    The last step was the deploment of the oracle driver on the NW7.1 under the "Application Resources Overview". The driver I named "ora10".
    Now if I call my Bean shown above with its Entity Manager Call for the injection I got the following exception:
    Caused by: com.sap.sql.log.OpenSQLException: Error while accessing porting layer for ORACLE database via getSessionId().
         at com.sap.sql.log.Syslog.createAndLogOpenSQLException(Syslog.java:148)
         at com.sap.sql.jdbc.direct.DirectConnectionFactory.createPooledConnection(DirectConnectionFactory.java:532)
         at com.sap.sql.jdbc.direct.DirectConnectionFactory.createDirectPooledConnection(DirectConnectionFactory.java:157)
         at com.sap.sql.jdbc.direct.DirectConnectionFactory.createDirectPooledConnection(DirectConnectionFactory.java:117)
         at com.sap.sql.connect.factory.PooledConnectionFactory.createPooledConnection(PooledConnectionFactory.java:119)
         at com.sap.sql.connect.factory.DriverPooledConnectionFactory.getPooledConnection(DriverPooledConnectionFactory.java:38)
    I have no idea, whats wrong. Perhaps my driver is wrong or not set properly ?
    Can anybody help me please ?
    Thanks in advance,
    Hendrik
    Edited by: henne123 on May 18, 2009 6:19 PM

    I have tried that.
    [EXCEPTION]
    *com.sap.sql.log.OpenSQLException: The SQL statement "SELECT * FROM EPD.SAPEPDDB.UME_EP_SLD" contains the syntax error[s]: - Open SQL syntax error: table names must not specify a catalog name (delete "EPD". before "SAPEPDDB"."UME_EP_SLD")*
    Database name must be Ok, because i can access to other tables which are in the same DB...
    Thanks for your help

  • EJB 3.0 EntityManager null on JBoss 4.2

    Hi ,
    I am developing an application in EBJ 3.0.
    My application is properly deployed on JBoss 4.2 application server but when I am trying to persist data I am getting EntityManaget always null.
    My Mail Id is : [email protected]
    following is my code Please help me...........
    My datasource for oracle
    D:\jboss-4.2.2.GA\server\default\deploy\oracle-ds.xml
    <datasources>
    <local-tx-datasource>
    <jndi-name>OracleDS</jndi-name>
    <connection-url>jdbc:oracle:thin:@serverIp:1521:SID</connection-url>
    <!--
    Here are a couple of the possible OCI configurations.
    For more information, see http://otn.oracle.com/docs/products/oracle9i/doc_library/release2/java.920/a96654/toc.htm
    <connection-url>jdbc:oracle:oci:@youroracle-tns-name</connection-url>
    or
    <connection-url>jdbc:oracle:oci:@(description=(address=(host=youroraclehost)(protocol=tcp)(port=1521))(connect_data=(SERVICE_NAME=yourservicename)))</connection-url>
    Clearly, its better to have TNS set up properly.
    -->
    <driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
    <user-name>V2RND</user-name>
    <password>V2RND</password>
    <!-- Uses the pingDatabase method to check a connection is still valid before handing it out from the pool -->
    <!--valid-connection-checker-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleValidConnectionChecker</valid-connection-checker-class-name-->
    <!-- Checks the Oracle error codes and messages for fatal errors -->
    <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter</exception-sorter-class-name>
    <!-- sql to call when connection is created
    <new-connection-sql>some arbitrary sql</new-connection-sql>
    -->
    <!-- sql to call on an existing pooled connection when it is obtained from pool - the OracleValidConnectionChecker is prefered
    <check-valid-connection-sql>some arbitrary sql</check-valid-connection-sql>
    -->
    <!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml -->
    <metadata>
    <type-mapping>Oracle9i</type-mapping>
    </metadata>
    </local-tx-datasource>
    </datasources>
    Entity Bean
    com.ntpl.v2hralign.master.entity.Department
    package com.ntpl.v2hralign.master.entity;
    import java.io.Serializable;
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.Id;
    import javax.persistence.Table;
    @Entity
    @Table(name="MASTER_DEPARTMENT")
    public class Department implements Serializable {
    @Id
    @Column(name="DEPT_ID")
    private int deptId;
    @Column(name="DEPT_NAME")
    private String deptName;
    private static final long serialVersionUID = 1L;
    public Department() {
    super();
    public int getDeptId() {
    return this.deptId;
    public void setDeptId(int deptId) {
    this.deptId = deptId;
    public String getDeptName() {
    return this.deptName;
    public void setDeptName(String deptName) {
    this.deptName = deptName;
    Remote Interface
    package com.ntpl.v2hralign.master.session;
    import javax.ejb.Remote;
    @Remote
    public interface DepartmentRemote {
    public void createDepartment(int deptId, String deptName);
    package com.ntpl.v2hralign.master.session;
    import javax.annotation.Resource;
    import javax.ejb.Stateless;
    import javax.naming.InitialContext;
    import javax.persistence.EntityManager;
    import javax.persistence.EntityManagerFactory;
    import javax.persistence.Persistence;
    import javax.persistence.PersistenceContext;
    import javax.persistence.PersistenceContextType;
    import org.hibernate.mapping.Component;
    import org.jboss.aspects.Injected;
    import com.ntpl.v2hralign.master.entity.Department;
    @Stateless
    public class DepartmentSession implements DepartmentRemote {
    @PersistenceContext EntityManager entityManager;
    //@Injected protected EntityManager entityManager;
    /*EntityManagerFactory emf = Persistence.createEntityManagerFactory("V2HRAlign");
    EntityManager entityManager = emf.createEntityManager();*/
    /*protected EntityManager entityManager;
    public EntityManager getEntityManager() {
    if (entityManager == null){
    try{
    System.out.println("hi dear not yet get anaything");
    entityManager = (EntityManager)(new InitialContext()).lookup("java:comp/ejb/EntityManager");
    } catch (Exception e){};
    return entityManager;
    @Override
    public void createDepartment(int deptId, String deptName) {
    //entityManager = getEntityManager();
    Department department = new Department();
    department.setDeptId(deptId);
    department.setDeptName(deptName);
    System.out.println("entityManager="+entityManager);
    entityManager.persist(department);
    persistence.xml
    <?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="V2HRAlign">
    <jta-data-source>java:/OracleDS</jta-data-source>
    <class>com.ntpl.v2hralign.master.entity.Department</class>
    <properties>
    <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle9Dialect"/>
    <property name="hibernate.connection.driver_class" value="oracle.jdbc.driver.OracleDriver"/>
    <property name="hibernate.hbm2ddl.auto" value="create"/>
    <property name="hibernate.show_sql" value="true" />
    </properties>
    </persistence-unit>
    </persistence>
    Client Program
    package com.ntpl.v2hralignclient.master.client;
    import javax.ejb.EJB;
    import com.ntpl.v2hralign.master.session.DepartmentRemote;
    import com.ntpl.v2hralign.master.session.DepartmentSession;
    public class DepartmentClient {
    * @param args
    @EJB
    public static DepartmentRemote department = new DepartmentSession();
    public static void main(String[] args) {
    department.createDepartment(1, "Software");
    Error -------------------------------
    entityManager=null
    Exception in thread "main" java.lang.NullPointerException
    at com.ntpl.v2hralign.master.session.DepartmentSession.createDepartment(DepartmentSession.java:54)
    at com.ntpl.v2hralignclient.master.client.DepartmentClient.main(DepartmentClient.java:20)
    ---------------------------------------------------------------------------------------------------------------------------------------

    the problem is in your client code. you are instantiating the EJB locally. that is not what you want. you should be looking up the remote ejb using a Context object. look for information on setting up a client program to contact jboss using jndi.

  • Confuse about the injecting entity in EJB 3.0?

    Hi all,
    I have an customersBean which is inherit from customersRemote and my problem is i' am little confuse about injecting the entity(customer).
    Where can you apply the EntityManagerFactory is it outside on EJB or Inside the EJB? means outside EJB is use the web application or java application. i have and example.
    this is inside on EJB...............
    public class CustomersBean implements com.savingsaccount.session.CustomersRemote {
    @PersistenceContext(unitName="SavingAccounts")
    EntityManagerFactory emf;
    EntityManager em;
    /** Creates a new instance of CustomersBean */
    public CustomersBean() {
    public void create(int id, String name, String address, String telno, String mobileno)
    try{
    //This is the entity.
    Customer _customer = new Customer();
    _customer.setId(id);
    _customer.setName(name.toString());
    _customer.setAddress(address.toString());
    _customer.setTelno(telno.toString());
    _customer.setMobileno(mobileno.toString());
    em = emf.createEntityManager();
    em.persist(_customer);
    emf.close();
    }catch(Exception ex){
    throw new EJBException(ex.toString());
    in web application, i'm using the @EJB in customer servlets.
    public class CustomerProcessServlet extends HttpServlet {
    @EJB
    private CustomersRemote customerBean;
    blah blah inject directly coming request field from jsp.
    }

    Hi all,
    I have an customersBean which is inherit from customersRemote and my problem is i' am little confuse about injecting the entity(customer).
    Where can you apply the EntityManagerFactory is it outside on EJB or Inside the EJB? means outside EJB is use the web application or java application. i have and example.
    this is inside on EJB...............
    public class CustomersBean implements com.savingsaccount.session.CustomersRemote {
    @PersistenceContext(unitName="SavingAccounts")
    EntityManagerFactory emf;
    EntityManager em;
    /** Creates a new instance of CustomersBean */
    public CustomersBean() {
    public void create(int id, String name, String address, String telno, String mobileno)
    try{
    //This is the entity.
    Customer _customer = new Customer();
    _customer.setId(id);
    _customer.setName(name.toString());
    _customer.setAddress(address.toString());
    _customer.setTelno(telno.toString());
    _customer.setMobileno(mobileno.toString());
    em = emf.createEntityManager();
    em.persist(_customer);
    emf.close();
    }catch(Exception ex){
    throw new EJBException(ex.toString());
    in web application, i'm using the @EJB in customer servlets.
    public class CustomerProcessServlet extends HttpServlet {
    @EJB
    private CustomersRemote customerBean;
    blah blah inject directly coming request field from jsp.
    }

  • Cannot inject entitymanagerfactory in a helper class..

    I want to cache a inject EnityManagerFactory and use it to create application managed entity manager when needed. I thought of writing a single ton class and to store entitymanagerfactory reference and use it as wrapper to EnityManagerFactory.So, that this can be used across my beans to create entitymanager. but injection of EntityManagerFactory is not happening as my class is not a container managed class.
    Can any one help me to inject a EntityManagerFactory and cache it for use across beans.

    The cleanest thing to do is follow the steps outlined in our FAQ :
    https://glassfish.dev.java.net/javaee5/ejb/EJB_FAQ.html#POJOLocalEJB
    The example here deals with a local ejb ref but the issue is the same for any
    Java EE environment dependency.
    --ken                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Maybe you are looking for

  • Problem with import tag in xsl files and include in xsd files

    Hello, I've been developing an application using JBoss as server. Then, i created an especific path for xsd and another path for xsl files. In both cases, i created a main file that include (xsd) or import (xsl) the other files. My problem is that i

  • Strange sound when switching on the microph

    i use a "sound blaster li've! value". i don't remember when this strange signal noise had appeared but later found out, that you can hear it only, if you turn on the microphone input. the noise appears and disappears and it doesn't change if you use

  • Help getting the XPS writer working.

    Win7 ... the MS XPS Document writer has never worked well.  Today I uninstalled the feature and reinstalled it (to no avail). If I try from Outlook, I get a simple message box ... "Printer not ready". From Notepad, a message box ... "The parameter is

  • Information record

    Dear All, We are created a purchase order and before saving have checked the check box for creation of info record but when we go the info record and click on conditions to check the conditions but no condition exist. Secondly it gives an message "No

  • Reminders calculated back from Due Date?

    I'm a newbie to workflow and would like to set reminders (on notifications) to be calculated based on a due date rather than from the creation date of the notification. e.g. due_date attribute on a notification is set say 50 days in advance. I want t