JPA EntityManager connection

Hi, I'm trying to get into the Java Persistence Api, so I came up with these questions:
I'm planning to use it in a existing db desktop application, currently using java.sql.connection object to query the mysql server.
May I share the connection between the JPA and the current logic or should I open a new one for the JPA ?..
As this is a desktop app, I would like to dinamically create the JPA connection as I do with the java.sql.connection, I dont want setup again in the persistence.xml file, is this possible without create a Datasource?..
I do appreciate your help!!..

Using Jboss 4.0.5 + SQLServer. When calling
con = (Connection) login.connectToDatasource(null);
I get
java.lang.Throwable: STACKTRACE
     at org.jboss.resource.connectionmanager.CachedConnectionManager.registerConnection(CachedConnectionManager.java:290)
     at org.jboss.resource.connectionmanager.BaseConnectionManager2.allocateConnection(BaseConnectionManager2.java:417)
     at org.jboss.resource.connectionmanager.BaseConnectionManager2$ConnectionManagerProxy.allocateConnection(BaseConnectionManager2.java:842)
     at org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:88)
     at oracle.toplink.essentials.jndi.JNDIConnector.connect(JNDIConnector.java:145)
     at oracle.toplink.essentials.sessions.DatasourceLogin.connectToDatasource(DatasourceLogin.java:185)
at my calling line

Similar Messages

  • JPA EntityManager shared across OSGi modules

    Hi,
    I'd like to create an OSGi module which would act as a 'JPA master' making JPA EntityManager available to other OSGi modules. The persistence.xml would be part of this module but it would do nothing more.
    I'd like to then access EntityManager from other OSGi bundles, both JARs and WARs (JAR Bundles and WAR Bundles).
    I'm running on GlassFish 3.1.2.2 and using EclipseLink as the JPA provider.
    Any idea for best practices?
    Thank you

    Hi, thanks for the link.
    It says 'Refer to the examples to see it being used.' without a link so I read the section above that (8. JPA in OSGi Application)
    It says about some config entries in GlassFish, I enabled it but still no luck.
    Here's my /src/main/resources/META-INF/persistence.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <persistence 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" version="1.0">
    <persistence-unit name="cmsdbconnection">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
         <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties>
    <property name="javax.persistence.jdbc.url" value="jdbc:mysql://172.16.145.139:3306/test_db"/>
    <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
    <property name="javax.persistence.jdbc.user" value="db_user"/>
    <property name="javax.persistence.jdbc.password" value="db_user"/>
    <property name="eclipselink.ddl-generation.table-creation-suffix" value="engine=InnoDB" />
    <property name="eclipselink.ddl-generation" value="create-tables" />
    <property name="eclipselink.target-server" value="=SunAS9" />
    </properties>
    </persistence-unit>
    </persistence>
    Maven pom.xml to generate MANIFEST.MF:
    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-jar-plugin</artifactId>
                        <version>2.4</version>
                        <extensions>true</extensions>
                        <configuration>
                             <archive>
                                  <manifestEntries>
                                       <Bundle-ManifestVersion>2</Bundle-ManifestVersion>
                                       <Bundle-SymbolicName>com.ifp.vault.service.persistence</Bundle-SymbolicName>
                                       <Bundle-Version>${project.version}</Bundle-Version>
                                       <Import-Package>org.osgi.framework,org.osgi.util.tracker,javax.persistence;jpa="2.0";version="1.1.0",org.eclipse.persistence.jpa</Import-Package>
                                       <JPA-PersistenceUnits>cmsdbconnection</JPA-PersistenceUnits>
                                       <Meta-Persistence>META-INF/persistence.xml</Meta-Persistence>
                                  </manifestEntries>
                             </archive>
                        </configuration>
                   </plugin>
    Deploying in GlassFish succeeds, but I cannot obtain the EntityManagerFactory from other OSGi bundles.
    Should that be registered as an OSGi service anyway? Because I can't see that when listing all OSGi bundles.

  • Toplink JPA: jdbc connection access required

    I have a strong reason why direct access to the connections used by Toplink JPA is required: for each connection I need to execute
    - a "set role" to grant permissions,
    - "set lock mode" to prevent hangups,
    - "set isolation" to get the correct transaction type,
    - possibly a "set explain on" to get query costs info,
    - and a "set constraints all deferred" to have constraints checked at commit time, not earlier.
    Can the Toplink pooling mechanism be replaced?

    You can use either an external data source from your container or an JDBC data source for that matter but you cannot replace the internal connection pool. Although one option may be to use a wrapped connection pool of your own I would first recommend looking at the SessionEventListener callbacks. Implementing this interface and registering it using a SessionCustomizer (persistence unit property) would allow you to be notified and get access to the JDBC connection when acquired and released from either pooling mechanism.
    Here is an example:
    public class JDBCConnectionListener extends SessionEventAdapter implements SessionCustomizer {
         * This method is used when this class is configured as the session customizer
         * in the persistence unit properties.
        public void customize(Session session) {
            session.getEventManager().addListener(this);
         * This event is raised after a connection is acquired from a connection pool.
        public void postAcquireConnection(SessionEvent event) {
            DatabaseAccessor da = (DatabaseAccessor)event.getResult();
            Connection con = da.getConnection();
            PreparedStatement statement;
            try {
                event.getSession().log(SessionLog.FINE, SessionLog.SQL, "POST-ACQUIRE> SELECT SYSDATE FROM DUAL");
                statement = con.prepareStatement("SELECT SYSDATE FROM DUAL");
                ResultSet rs = statement.executeQuery();
                rs.close();
            } catch (SQLException e) {
                // TODO
         * This event is raised before a connection is released into a connection pool.
        public void preReleaseConnection(SessionEvent event) {
    }Doug

  • JPA, EntityManager and RMI

    Hello,
    in my client server application, I want to get a DAO from the server to add or update a business object.
    My problem is that the DAO must have a property with the EntityManager so he can do his job, this EntityManager
    is not serializable, so RMI throw a NotSerializableException, but when I set the property tansient, the EntityManager
    will be null after serialize the DAO to the client.
    How can I solve that problem?
    Thanks.

    teramor1 wrote:
    Thank you! I undestand, the domain objects are not attached and therefor not JPA managed, when some changes are made to the objects.
    When I take a Service Interface and take the implementation from the Rmi Server, so I can call update(...) the ServiceImplementation must have a property to a DAO and the DAO to an EntityManager, but the EntityManager is not serializable.
    How can I detach the ServicImplementation from the DAO and/or the EntityManager so the Client gets the ServiceImplementation and can call the update(...) method and this method can do his job on the dao and the dao can do his job on the EntityManager?Assuming i understand your usage of the word "Service" (and i'm not sure i do), the client will never get an instance of the Service implementation. the Service implementation never leaves the server. a client gets a handle to the Service interface through some sort of jndi lookup. it then invokes remote methods on this Service which may return entity objects. then only things that travel between the client and server are the entity objects themselves.

  • JPA - EntityManager - createQuery - Inheritance

    I'm quite new to JPA and I need support on query syntax.
    I have an abstract entity:
    @MappedSuperclass
    public abstract class HACCP implements Serializable {
    }and more than one concrete implementations used to differentiate the DB table where data are stored
    @Entity
    @Table(schema = "dbo", name = "haccp_01")
    public class HACCP01 extends HACCP {
    @Entity
    @Table(schema = "dbo", name = "haccp_02")
    public class HACCP02 extends HACCP {
    }I want to use only one service to execute CRUD functionalities.
    When I retrieve data using the find method of the EntityManager everithing works fine:
    em.find(HACCP.class, id);and at runtime the concrete class identifies the correct DB table.
    Now I need to write my own query with a where clause
    Query query = getEntityManager().createQuery( "select p FROM HACCP p WHERE [...]");obviously forcing the name of the table is not what I want!
    How shold I write the query?
    Edited by: mbm63 on Aug 1, 2008 11:52 AM

    Solved!
    I just get the runtime simple name of the argument class and build the query using it:
    public HACCP retrieveCurrent(HACCP haccp) {
       Query query = getEntityManager().createQuery( "select p FROM " + haccp.getClass().getSimpleName() + " p WHERE [...]");
    }

  • Problem accesing JPA EntityManager from JSP scriplet

    Hy,
    I am trying to access an EntityManager from JSP scriptlet for testing purposes and it just doesn't work.
    Here is the JSP scriptlet:
    <%
    EntityManager em = (EntityManager) (new InitialContext()).lookup("java:comp/env/persistence/em");
    Query query = em.createQuery("select u from USER u");
    List<User> users = (List<User>) query.getResultList();
    for (User user : users) { user.toString(); }
    %>
    The application is deployed in JBoss 4.2.2.GA.

    Sorry for my previous post. It was incomplete.
    I am trying to access an EntityManager from JSP scriptlet for testing purposes and it doesn't work.
    Here is the JSP scriptlet:
    <%
    EntityManager em = (EntityManager) (new InitialContext()).lookup("java:comp/env/persistence/em");
    Query query = em.createQuery("select u from USER u");
    List<User> users = (List<User>) query.getResultList();
    for (User user : users) { user.toString(); }
    %>
    persistence.xml file :
    <persistence-unit name="myApp">
              <provider>org.hibernate.ejb.HibernatePersistence</provider>
              <jta-data-source>java:/XAOracleDS</jta-data-source>
    <properties>
    <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle9iDialect"/>
    </properties>
    </persistence-unit>
    web.xml file :
    <persistence-context-ref>
              <persistence-context-ref-name>persistence/em</persistence-context-ref-name>
              <persistence-unit-name>myApp</persistence-unit-name>
         </persistence-context-ref>
    The application is deployed in JBoss 4.2.2.GA. When I access the JSP page I get the following exception:
    javax.servlet.ServletException: javax.naming.NameNotFoundException: persistence not bound
    I guess I have to configure the resource in jboss-web.xml too, but I don't know how. I tried with <resource-ref>, but I got the same error.
    Any help at all would be highly appreciated !
    Thanks.
    Andrei

  • Spring and TopLink/JPA on OC4J 10.1.3.4.0

    Our configuration worked fine on OC4J 10.1.3.1 (linux) and 10.1.3.3 (windows). We have a problem with JPA (toplink essentials--not eclipselink) on OC4J 10.1.3.4.0 using Spring (2.0.7 and 2.5.6). We found that it was trying to connect to the default OracleDS data source(there were 2 connections in toplink essentials for some reason), but once we defined an OracleDS, it gave us this error:
    javax.servlet.ServletException: javax.faces.el.EvaluationException: Error getting property 'experiments' from bean of type gov.llnl.nif.dataviz.mssar.web.ExperimentListBean: org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is java.lang.IllegalStateException:
    Exception Description: Cannot use an EntityTransaction while using JTA.
    Our persistence.xml looks like:
    <?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="mssar">
              <class>gov.llnl.nif.dataviz.mssar.model.ExperimentInfo</class>
              <class>gov.llnl.nif.dataviz.mssar.model.UsePlan</class>
         <properties>
         <property name="toplink.cache.shared.gov.llnl.nif.dataviz.mssar.model.ExperimentInfo" value="false"/>
         <property name="toplink.cache.shared.gov.llnl.nif.dataviz.mssar.model.UsePlan" value="false"/>
         </properties>
         </persistence-unit>
    </persistence>
    Our orm.xml looks like:
    <?xml version="1.0" encoding="UTF-8"?>
    <entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_1_0.xsd" version="1.0">
    </entity-mappings>
    Our spring configuration looks like:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:jee="http://www.springframework.org/schema/jee"
    xmlns:aop="http://www.springframework.org/schema/aop"
         xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
    http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.0.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
         http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"
         default-autowire="byName">
    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="dataSource" ref="dataSource"/>
    <property name="jpaVendorAdapter">
    <bean class="org.springframework.orm.jpa.vendor.TopLinkJpaVendorAdapter">
    <property name="showSql" value="true"/>
    <property name="databasePlatform" value="oracle.toplink.essentials.platform.database.oracle.OraclePlatform"/>
    </bean>
    </property>
    <property name="loadTimeWeaver">
         <bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"/>
    </property>
    </bean>
    <jee:jndi-lookup id="dataSource" jndi-name="jdbc/SSARDS"/>
    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    <property name="entityManagerFactory" ref="entityManagerFactory" />
         <property name="dataSource" ref="dataSource" />
    </bean>
         <bean id="experimentsQueryBuilder" class="gov.llnl.nif.dataviz.mssar.dao.jpa.ExperimentsQueryBuilderJpa"/>
         <bean id="experimentsDao" class="gov.llnl.nif.dataviz.mssar.dao.jpa.ExperimentsDaoJpa"/>
         <bean id="experimentListManager" class="gov.llnl.nif.dataviz.mssar.service.impl.ExperimentListManagerImpl"/>
    </beans>
    ExperimentInfo.java mapping looks like:
    @Entity
    @Table(name = "EXPERIMENT_IDS")
    public class ExperimentInfo implements ExperimentInformation {
         @Id
         @Column(name="EXPERIMENT_ID")
         String experimentId;
         @Column(name="EXPERIMENT_DESCRIPTION")
         String expDescription;
         @Column(name="STATUS")
         String status;
         @Column(name="EXPERIMENT_PI")
         String expPI;
         //Date lpomDate;
         //Date settingsDate;
         @Column(name="LPOM_DATE")
         Timestamp lpomDate;
         @Column(name="SETTINGS_DATE")
         Timestamp settingsDate;     
    UsePlan.java looks like:
    @Entity
    @Table(name="USE_PLAN")
    public class UsePlan extends BasePlan implements PlanData, Serializable {
         static final long serialVersionUID = -1555327955428351924L;
         @Id
         @Column(name="EXP_SHOT_ID")
         String expShotId;
         @Id
         @Column(name="LOCATION")
         String location;
         @Id
         @Column(name="INFO_VAR")
         String infoVar;
         @Id
         @Column(name="USE_ITEM_NAME")
         String useItemName;
         @Column(name="USE_PRIORITY")
         String usePriority;
    ExperimentListManagerImpl looks like:
    @Transactional(readOnly=true)
    public class ExperimentListManagerImpl implements ExperimentListManager {
    This is a read-only app but it should not use the cache.
    Our Dao Looks like:
    public class ExperimentsDaoJpa extends JpaDaoSupport implements ExperimentsDao {
    private QueryBuilder experimentsQueryBuilder;
    public List<ExperimentInfo> shotsByQueryBean(ExperimentsQueryBean queryBean, String sortColumn, boolean ascending) {
         try {
              getJpaTemplate().flush();
              experimentsQueryBuilder.buildQuery(queryBean);
         experimentsQueryBuilder.setSortColumn(sortColumn, ascending);
         List<ExperimentInfo> result = getJpaTemplate().findByNamedParams(experimentsQueryBuilder.getQuery().toString(), experimentsQueryBuilder.getParams());
         // pull new results from database
         /*for (ExperimentInfo ei : result) {
              getJpaTemplate().refresh(ei);
         return result;
         } catch (Throwable t) {
              t.printStackTrace();
              return null;
         public void setExperimentsQueryBuilder(QueryBuilder experimentsQueryBuilder) {
              this.experimentsQueryBuilder = experimentsQueryBuilder;
    Thanks,
    John Carlson

    We also had this problem. We have changed the TransactionManager.
    Replace the JPATransactionManager with the JTATransactionManager.
    <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager" />
    If you are using JTA you can't use the JPA Transaction Manager. It doesn't support JTA.
    Found it on a forum of Spring. (http://forum.springframework.org/showthread.php?t=48191)
    Dennis

  • Progress Reporter - Failed to connect to data source

    Installed Progress Reporter and successfully call up the configuration page (http://WLS_server_name:7001/pr/admin/configuration) fill out the Database URL with the URL I use in SQL Developer (jdbc:oracle:thin:@db_Server_Name:1521:primavera) Public Group ID: 1 username: pubuser and password: pubuser. I put nothing in the Application Server section. When I click on save I get the message "Failed to connect to data source, please verify your settings and try again." I know the URL is correct as it connects using SLQ Developer. I have also created a datasource and pool using the same parameters just to validate the connection URL in different products.
    Now I do get errors when starting up WebLogic
    1) java.io.FileNotFoundException: C:\prhome\primavera-configuration.properties ...
    2) Local Exception Stack: Exception [EclipseLink-7042] (Eclipse Persistence Services - 1.1.0.r3639-SNAPSHOT): org.eclipse.persistence.exceptions.ValidationException Exception Description: Database platform class [${databasePlatform}] not found...
    3) Exception in thread "timerFactory" org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; ...
    4) A number of these: Exception Description: Database platform class [${databasePlatform}] not found....
    I am running on Windows 2008-r2 using WebLogic (64bit) and Java 1.6.0_27 (64bit); Progress Reporter installed in its own domain on a standalone (not managed) weblogic server
    I've checked the configuration steps in the documentation (especially for the setDomainEnv.cmd and the PRE_CLASSPATH settings)
    Any suggestions appreciated.
    Are any of the errors (1 through 4) causing the issue of being unable to connect to the data source?

    I have tried both privuser and pubuser. Both username/password combinations work when using sql-developer but not through the database section on the P6 Progress Reporter configuration web page.
    I don't login as admin. When I enter the URL http://WLS_server_name:7001/pr/admin it comes up with the configuration screen that has the database and application server configuration sections.
    The file primavera-configuration.properties is not created. If I create a blank file that removes the "java.io.FileNotFoundException: C:\prhome\primavera-configuration.properties ..." message but it doesn't get any content.
    Thanks,
    Greg

  • Can't get EntityManager access in JSP/Servlet

    Hi all,
    our team has started a EJB project (EJBs + JPA configurations)
    we managed to access the configured JPA (EntityManager etc) within the EJB instance; however we don't know how to access the EntityManager within JSP/Servlet
    Our project's structure:
    1 EJB project (EJB classes, EntityBean classes, JPA configuration + eclipselink)
    1 Web project (for JSP, Servlets)
    the main problem is ... we can't access EntityManager(s) in JSP / Servlets (and we already tried using Struts2.0 to replace servlets/jsp... the problem is the same... so it is not ... the matter of choosing the view technology...)
    Jason

    Hi Jason,
    How i tried to get EntityManager is as following:
    Suppose I want to define my Persistence unit like Following:
    *<Your-EAR>/APP-INF/classes/MyEmployee.java*
    "*MyEmployee.java*"
    package entityA;
    import java.io.Serializable;
    import org.apache.commons.lang.builder.EqualsBuilder;
    import org.apache.commons.lang.builder.HashCodeBuilder;
    import org.apache.commons.lang.builder.ToStringBuilder;
    import javax.persistence.*;
    @Entity()
    @Table(name="MYEMPLOYEE")
    public class MyEmployee implements Serializable {
         //default serial version id, required for serializable classes.
         private static final long serialVersionUID = 1L;
         private Long empno;
         private String empname;
    public MyEmployee() {
         @Id()
         @Column(name="EMPNO", unique=true, nullable=false, precision=22)
         public Long getEmpno() {
              return this.empno;
         public void setEmpno(Long empno) {
              this.empno = empno;
         @Basic()
         @Column(name="EMPNAME", length=15)
         public String getEmpname() {
              return this.empname;
         public void setEmpname(String empname) {
              this.empname = empname;
         public boolean equals(Object other) {
              if (this == other) {
                   return true;
              if (!(other instanceof MyEmployee)) {
                   return false;
              MyEmployee castOther = (MyEmployee)other;
              return new EqualsBuilder()
                   .append(this.getEmpno(), castOther.getEmpno())
                   .isEquals();
         public int hashCode() {
              return new HashCodeBuilder()
                   .append(getEmpno())
                   .toHashCode();
         public String toString() {
              return new ToStringBuilder(this)
                   .append("empno", getEmpno())
                   .toString();
    And I have Placed My "*persistence.xml*" file in *"<Your-EAR>/APP-INF/classes/META-INF/persistence.xml"*
    <?xml version="1.0" encoding="UTF-8"?>
    <persistence 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"
         version="1.0">     
         <persistence-unit name="JPA_A_EJB" transaction-type="RESOURCE_LOCAL">
              <provider>org.hibernate.ejb.HibernatePersistence</provider>
              <class>entityA.MyEmployee</class>
              <properties>
                   <property name="hibernate.dialect" value="org.hibernate.dialect.OracleDialect"/>
                   <property name="hibernate.connection.driver_class" value="oracle.jdbc.OracleDriver"/>
                   <property name="hibernate.connection.url" value="jdbc:oracle:thin:@localhost:1521:xe"/>
                   <property name="hibernate.connection.username" value="jack"/>
                   <property name="hibernate.connection.password" value="password"/>
              </properties>
         </persistence-unit>     
    </persistence>
    ***********************************HOW I Access The Above Unit from my EJB mentioned Below*******************************
    "*EmployeeSessionBean.java*"
    package sfsbA;
    import entityA.*;
    import javax.ejb.*;
    import javax.persistence.*;
    @Stateless
    public class EmployeeSessionBean implements EmployeeSessionRemoteIntf
    *@PersistenceContext*
    protected EntityManager entityManager;
    *///NOTE: Using the Above Technique You can access the "EntityManager" Object in your Servlets As well...Just write the Above two Lines inside your Servlet*
    public void createEmployee(Long empno,String empname) throws Exception{
              System.out.println("\n\tcreateEmployee() called. EntityManager entityManager = "+entityManager);
              MyEmployee employee = new MyEmployee();
    employee.setEmpno(empno);
    employee.setEmpname(empname);
    entityManager.persist(employee);
              System.out.println("\n\t Entity Manager has persisted the Employee Information...");
    int count = 0;
    public EmployeeSessionBean() {
    System.out.println("\n\t EmployeeSessionBean--> EmployeeSessionBean() invoked");
    @Init("create")
    public void initMethod() throws CreateException {
    System.out.println("\n\t EmployeeSessionBean--> public void initMethod() invoked");
    @Remove(retainIfException=true)
    public void removeWithRetain() throws Exception{
    System.out.println("\n\t EmployeeSessionBean--> removeWithRetain() invoked");
    @Remove
    public void removeWithoutRetain() throws Exception{
    System.out.println("\n\t EmployeeSessionBean--> removeWithoutRetain() invoked");
    public String printRemoteIntf () {
    System.out.println("\n\t EmployeeSessionBean ---> public String printRemoteIntf () invoked");
         return "ReplicableSFSRemoteObjectIntf";
    public String printLocalIntf () {
    System.out.println("\n\t EmployeeSessionBean ---> public String printLocalIntf () invoked");
         return "ReplicableSFSLocalObjectIntf";
    public String printBean () {
    System.out.println("\n\t EmployeeSessionBean ---> public String printBean () invoked");
         return "EmployeeSessionBean";
    public int testIncrement() throws Exception
    System.out.println("\n\t EmployeeSessionBean ---> public int testIncrement() invoked");
    count=count+5;
    return count;
    public int testDecrement() throws Exception
    System.out.println("\n\t EmployeeSessionBean ---> public int testDecrement() invoked");
    count=count-2;
    return count;
    public int getCount() throws Exception
    System.out.println("\n\t EmployeeSessionBean ---> public int getCount() invoked");
    return count;
    "*EmployeeSessionRemoteIntf.java*"
    package sfsbA;
    public interface EmployeeSessionRemoteIntf {
    public void createEmployee(Long emono,String empname)     throws Exception;
    public void removeWithRetain()throws Exception;
    public void removeWithoutRetain() throws Exception;
    public String printBean ();
    public int testIncrement() throws Exception;
    public int testDecrement() throws Exception;
    public int getCount() throws Exception;
    *"ejb-jar.xml"*
    <?xml version="1.0" encoding="UTF-8"?>
    <ejb-jar version="3.0" 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/ejb-jar_3_0.xsd">
    <enterprise-beans>
    <session>
    <ejb-name>EmployeeSessionBean</ejb-name>
    <business-remote>sfsbA.EmployeeSessionRemoteIntf</business-remote>
    <ejb-class>sfsbA.EmployeeSessionBean</ejb-class>
    <session-type>Stateless</session-type>
    </session>
    </enterprise-beans>
    </ejb-jar>
    *"weblogic-ejb-jar.xml"* (I am writing these file Just because i want my Own JNDI Simple name...Not the Container Generated Complex JNDI name)
    <weblogic-ejb-jar xmlns="http://www.bea.com/ns/weblogic/90" xmlns:j2ee="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.bea.com/ns/weblogic/90 http://www.bea.com/ns/weblogic/90/weblogic-ejb-jar.xsd">
    <weblogic-enterprise-bean>
    <ejb-name>EmployeeSessionBean</ejb-name>
    <stateless-session-descriptor>
         <business-interface-jndi-name-map>
    <business-remote>sfsbA.EmployeeSessionRemoteIntf</business-remote>
    <jndi-name>EmployeeSessionBean</jndi-name>
         </business-interface-jndi-name-map>
    </stateless-session-descriptor>
    </weblogic-enterprise-bean>
    </weblogic-ejb-jar>
    "*application.xml*"
    <!DOCTYPE application PUBLIC '-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN' 'http://java.sun.com/dtd/application_1_3.dtd'>
    <application>
    <display-name>JPAs_Demo_Jason</display-name>
    <module>
    <ejb>AccessEntityManager.jar</ejb>
    </module>
    </application>
    NOTE: The Jar "" Contains
    1). EmployeeSessionBean
    2). EmployeeSessionRemoteIntf
    3). META-INF/ejb-jar.xml
    4). META-INF/weblogic-ejb-jar.xml
    Thanks
    Jay SenSharma
    http://jaysensharma.wordpress.com  (Real WebLogic Stuff...Not less Than a Magic...Here)
    Edited by: Jay SenSharma on Dec 16, 2009 10:59 PM
    Edited by: Jay SenSharma on Dec 16, 2009 11:00 PM

  • Error lookup EntityManager on OC4J 10.1.3.1.0

    Hi,
    I've just upgraded my development environment from 10.1.3.0.0 to 10.1.3.1.0.
    I'm heaving trouble in this version when I try to lookup a JPA EntityManager using JNDI.
    I got following code fragment from the howto guides from 10.1.3.0, and they worked well on previous version:
    public EntityManager getEntityManager() {
    try {
    if (em == null) {
    em = (EntityManager) getContext().lookup("java:comp/ejb/EntityManager");
    } catch (NamingException e) {
    throw new RuntimeException(e);
    return em;
    However, when installed on 10.1.3.1 I got the following error message:
    06/08/22 07:23:10 java.lang.RuntimeException: javax.naming.NameNotFoundException: Default application EntityManager is not available; no deployed entities
    This didn't make much sence to me, as the log showed my entities being mapped at deployment. Just for verification, I've added a SessionBean to my code (It's not my intention to use session beans) and tried to access an EntityManager instance from this sessionbean, which I got using the @Resource anntotation. That worked fine, suggesting that my entities indeed did deploy.
    Is there any difference in how the EntityManager should be looked up from jndi, compared to the previous version? JNDI tree from the Enterprise Manager doesn't show any entitymanagers...
    Thanks for any help
    Bert

    Hello,
    One of the major differences for the EJB container between 10.1.3.0.0 and 10.1.3.1.0 is the fact that we move from the last draft of the EJB 3 specification to the final version of the specifications.
    So you can now use the @PersistenceContext to lookup the entity manager.
    The EJB 3.0 page has been updated and sample applications too, to reflect the change.
    Regards
    Tugdual Grall

  • 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

  • JPA - PERSISTENCE PROVIDER NOT FOUND

    Hi,
    I am using JPA to connect to my SQL Database and using web logic 9.2 server..
    I get an No Persistence Provider exception
    any idea what this cud be
    Thanks
    Karthik

    Well, i've never worked with WebLogic, but you need a JPA implementation provider, like toplink-essentials or hibernate-entity-manager.
    You can also check your persistence.xml and look for some missing configuration.
    Here's an example from the hibernate documentation:
    <persistence 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"
       version="1.0">
       <persistence-unit name="sample">
          <jta-data-source>java:/DefaultDS</jta-data-source>
          <properties>
             <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
             <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
          </properties>
       </persistence-unit>
    </persistence>Hope it helps...

  • Toplink 11 & JPA: advisable way going forward?

    Hi,
    We're considering the Toplink configuration choices of a new major information system.
    This system will not be in production for at least a year or more.
    I think we have a few options:
    - keep on using Toplink Workbench ORM 10.1.3
    - start using Toplink JPA 11. I get the impression that this is the preferred way forward for J2EE applications on Oracle AS. It makes me wonder whether all Toplink specific value added functionality, like historical queries f.i., will be available using this annotation based approach. Another concern obviously is how many problems we'll encounter because the product is in preview. Is it suitable for development yet? Will there be regular preview updates? Will Toplink 11 work under OC4J 10.1.3?
    - start using Toplink JPA 10.1.3. If I understand the documentation correctly this is an implementation of a preview of the JPA/EJB spec and is not recommended.
    - start using Toplink Essentials. I get the impression that this precludes us from using Oracle Toplink specific functionality like historical queries.
    Thanks for your advice.
    Regards,
    Joost

    Do I understand correctly that all Toplink specific functionality is available when using Toplink 11 JPA? Can you give me a clue how this will work? TopLink exposes its' functionality beyond the JPA specification in several ways:
    - Extended annotations are provided in the oracle.toplink.annotations package. These allow you to configure functionality like caching, locking and additional mappings not included in the JPA spec.
    - The TopLink sessions.xml and project.xml files can be used in place of the JPA orm.xml (or annotations), this gives you access to using the TopLink Mapping Workbench and all of TopLink's mapping functionality. You just need to set the sessions XML property in your JPA persistence.xml to do this.
    - You can customize your JPA generated TopLink descriptors or session using the DescriptorCustomizer or SessionCustomizer from your persistence.xml or using the @Customizer annotation.
    - You can cast your JPA EntityManager to the TopLink EntityManager interface, which exposes additional API. The JPA Query can also be cast to the TopLink Query interface. You can also access the underlying TopLink Session and DatabaseQuery from these to make use of any TopLink functionality that is not exposed.
    As you can imagine it's much harder organizationally to migrate server infrastructure to Oracle AS 11 then that it is to migrate the TopLink library used by an application. What is Oracle's policy in that respect? Oracle TopLink has always done its best to be portable across ALL application servers. It is our goal that TopLink 11g could be used in OC4J 10.1.3, and it should work, but I have not tested this myself.
    James Sutherland

  • Queries inside Entity list - JPA

    Hi all,
    I want to create a query inside already taken list of entities form the DB.
    So the first query (list of entities) will be taken from DB using JPA entityManager (eg. select from HugeEntity), and the second one from memory (from already taken list).
    The reason I want to do this is that DB table is very big (about 200GB of data) and I need to fetch only 50-100 rows and have all other manipulation of fetched data in memory in order to achieve best performance.
    Is it possible?

    Thank you...
    Don't your fortune cookies have a unique id as a number? ...Yes they have but, cookies can be removed and thus, interval is not continuous. E.g. {1,2,5,6,7} after 3 and 4 has been removed.
    ... you could preload and cache them in a collection and
    randomize on the position of an element in that collection...Cacheing seems like a good idea -- I'll probably add some FortuneCookieDAO as layer between my accessor session beans (FortuneCookieAccess) and cookie entity (FortuneCookie). But where should I store instance of this DAO? It has to be accessible from any session bean instance. Into my server's directory (jndi)?
    Or did you mean cache on site of web application? That's not possible, my selecting random cookie is responsibility of FortuneCookieAccess ejb.
    ~~
    Adam
    PS: I know that using ejbs for fortune cookie selection is not a model usecase (there's saying in my country: "It's like shooting sparrow with a cannon") ... is not a model usecase, but it's just training application.

  • Authentication using database accounts (EJB)

    Hi.
    I'm developing a web app(struts, jsp). Users should log-in using their Oracle
    database accounts (created with CREATE USER ...). Is it possible to accomplish that using EJB? How?
    I've read that i can somehow map application server's users with database users
    using sql authentication providers: Wouldn't then sql queries made by ejbs
    still be executed with the same user every time?

    Normally application servers use a shared login to allow using a shared connection pool, and avoid the cost of logging in and out.
    Are you using JPA or the native TopLink API? Are you using JTA?
    TopLink / EclipseLink have several features for user logins.
    You can use Oracle proxy connections, these allow a shared connection pool to be used, but allow setting a proxy user on the connection.
    See, org.eclipse.persistence.config.PersistenceUnitProperties.ORACLE_PROXY_TYPE
    You can also use real database logins with JPA (or ServerSession) through using a JPA EntityManager properties or a ConnectionPolicy.
    See, org.eclipse.persistence.config.EntityManagerProperties, org.eclipse.persistence.sessions.server.ConnectionPolicy.
    You also have the option of using a shared login for reads, and a user login for writes.
    If you are using the native API, you can also use DatabaseSessions.
    James : http://www.eclipselink.org

Maybe you are looking for

  • UNICODE: more than six languages

    Hello, we have a worldwide hr system with a portal and an abap system using ess/mss. The system is running with ECC 6.0. At the moment six languages are installed. System is running with unicode. We have a request to install serveral additional langu

  • What is the best NLS config to be near the ACCESS or SQL Server characters set

    Hi all, I am working with an Oracle for Windows. I have serious problems with my actual characters set. What is the best NLS config to be near the ms-Access or SQL Server characters set behavior ? For exemple : I have a table with city names I want t

  • MBLB Report functional spec

    Dear Friends, Client Required  MBLB Report his own format that is. Vendor Name : XXXXXXXX        ADDERS:   XXXXXX           City:  XXXXXX Material Name ,      Material description,     Plant,     Batch,    Unrestricted Qty,         In quality inspect

  • WHY CAN'T I COMBINE FILES WITH RIGHT CLICK ANY MORE? HOW LONG AM I EXPECTED TO WAIT BEFORE SWITCHING TO A COMPETITOR'S PRODUCT?

    I used to be able to select a set of documents in the Windows file explorer, right click these highlighted documents, and then right click-->Combine Files in Acrobat. This used to open the combine files page in Acrobat and I would be able to combine

  • /Library/StartupItems and Oracle

    I have just installed Oracle on an XServe running Snow Leopard. The last job is the auto-start. The script provided by Oracle runs okay for any user using the command "sudo /Library/StartupItems/Oracle/Oracle" But when it is run as part of the Startu