Setting composite key in Container Managed Entity Bean

In my database table i set primary key to two columns making them as composite key. how do i set that in my container managed entity bean home interface findByPrimaryKey() method and in deployment descriptor file.

1. create another class (say CompositePK) that will embed the two fields keyA and keyB corresponding to the two pk of your table (declare them public) .
2. in your Bean declare keyA and keyB public.
3. in the dd declare your bean primary-key-class as CompositePK and the primary-key-field as keyA and keyB.
this is the method i use (with BAS) even if the key is simple (such as Integer).

Similar Messages

  • Container Managed Entity Beans and Client Identifier in Oracle

    Is it possible to use Container Managed Entity Beans (EJB with CMP)
    in a way that the Oracle database sessions still know the
    individual Client Identifiers of the actual users
    (not just the Identifier of the proxy user defined in the
    Connection Pool)?
    If Yes: How?
    If No: The consequence would be that the
    technologies EJB with CMP cannot be user together with
    Oracle Virtual Private Databases (VPN) because VPN requires
    some kind of Client Identifier.
    I am grateful for any hint.
    Regards,
    Martin Siepmann
    +49 (0)163 / 7765328

    Not quite an auto-incrementing PK, but it is managed by the container. the following is from the turorial
    Generating Primary Key Values
    For some entity beans, the value of a primary key has a meaning for the business entity. For example, in an entity bean that represents a phone call to a support center, the primary key might include a time stamp that indicates when the call was received. But for other beans, the key's value is arbitrary--provided that it's unique. With container-managed persistence, these key values can be generated automatically by the EJB container. To take advantage of this feature, an entity bean must meet these requirements:
    * In the deployment descriptor, the primary key class is defined as a java.lang.Object. The primary key field is not specified.
    * In the home interface, the argument of the findByPrimaryKey method must be a java.lang.Object.
    * In the entity bean class, the return type of the ejbCreate method must be a java.lang.Object.
    In these entity beans, the primary key values are in an internal field that only the EJB container can access. You cannot associate the primary key with a persistent field or any other instance variable. However, you can fetch the bean's primary key by invoking the getPrimaryKey method, and you can locate the bean by invoking its findByPrimaryKey method.
    Maybe that is good enough
    christina

  • Finder method in container-managed entity bean

    Finder method of a container entity bean is taking the primary key class object of another entity bean. How to map this in the xml descriptor file weblogic-cmp-rdbms.xml for this type of beans.
    I am trying to deploy the jasmine computer store of Mastering EJB by EdRoman.
    I couldn't write the deployment file weblogic-cmp-rdbms.xml for Order Entity bean which uses CustomerPK as an argument in its finder method.
    Please tell me how to write this. I am trying on weblogic 5.1
    Thanx in advance
    Srivatsa

    hello,
    in container managed persistence, you specify on your xml file the name of your table. so the primary key you want to use have to be a foreign key in your table. otherwise i don't think that you can use a container managed persistence.
    Najib.

  • Unable to call Container Managed Entity Bean

    Hi
    I am developing a JMS application using NetBeans 5.5.1 and Sun Java Application Server 9.0 and J2EE 1.4.When I run the application client it throws me following EXCEPTION:
    {color:#ff0000}Sep 9, 2010 1:43:43 PM com.sun.enterprise.appclient.MainWithModuleSupport <init>
    WARNING: ACC003: Application threw an exception.
    javax.naming.NameNotFoundException: No object bound to name java:comp/env/jms/MDBDestinationFactory
    at com.sun.enterprise.naming.NamingManagerImpl.lookup(NamingManagerImpl.java:751)
    at com.sun.enterprise.naming.java.javaURLContext.lookup(javaURLContext.java:156)
    at com.sun.enterprise.naming.SerialContext.lookup(SerialContext.java:307)
    at javax.naming.InitialContext.lookup(InitialContext.java:392)
    at jmsdemo.Main.main(Main.java:30)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.sun.enterprise.util.Utility.invokeApplicationMain(Utility.java:232)
    at com.sun.enterprise.appclient.MainWithModuleSupport.<init>(MainWithModuleSupport.java:329)
    at com.sun.enterprise.appclient.Main.main(Main.java:180)
    Exception in thread "main" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    at com.sun.enterprise.appclient.MainWithModuleSupport.<init>(MainWithModuleSupport.java:340)
    at com.sun.enterprise.appclient.Main.main(Main.java:180)
    Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.sun.enterprise.util.Utility.invokeApplicationMain(Utility.java:232)
    at com.sun.enterprise.appclient.MainWithModuleSupport.<init>(MainWithModuleSupport.java:329)
    ... 1 more
    Caused by: javax.naming.NameNotFoundException: No object bound to name java:comp/env/jms/MDBDestinationFactory
    at com.sun.enterprise.naming.NamingManagerImpl.lookup(NamingManagerImpl.java:751)
    at com.sun.enterprise.naming.java.javaURLContext.lookup(javaURLContext.java:156)
    at com.sun.enterprise.naming.SerialContext.lookup(SerialContext.java:307)
    at javax.naming.InitialContext.lookup(InitialContext.java:392)
    at jmsdemo.Main.main(Main.java:30)
    ... 7 more
    {color}{color:#000000}Source Code for Message Driven Bean:
    package jmsdemo;
    import javax.ejb.*;*
    import javax.jms.Message;
    import javax.jms.MessageListener;
    import javax.jms.TextMessage;
    *public class MDBBean implements MessageDrivenBean, MessageListener {*
    private MessageDrivenContext context;
    *public void setMessageDrivenContext(MessageDrivenContext aContext) {context = aContext;}*
    public void ejbCreate() {}
    public void ejbRemove() {}
    *public void onMessage(Message aMessage) {*
    if(aMessage instanceof TextMessage)
    TextMessage t = (TextMessage)aMessage;
    try
    System.out.println("Received message : " + t.getText());
    *}catch(Exception e) {e.printStackTrace();}*
    Source code for JMS Client:
    package jmsdemo;*
    import javax.jms.;
    import javax.naming.*;*
    *public class Main {*
    *public Main() {*
    public static void main(String[] args) throws Exception
    *// TODO code application logic here*
    InitialContext ic = new InitialContext();
    ConnectionFactory cf = (ConnectionFactory)ic.lookup("java:comp/env/jms/MDBDestinationFactory");
    Destination dest = (Queue) ic.lookup("java:comp/env/jms/MDBBean");
    Connection con = cf.createConnection();
    Session session = con.createSession(false,Session.AUTO_ACKNOWLEDGE);
    MessageProducer mp = session.createProducer(dest);
    TextMessage tm = session.createTextMessage();
    tm.setText("Hello world .,.");
    System.out.println("Sending message ...");
    mp.send(tm);
    con.close();
    Generating code for ejb-jar.xml
    <?xmlversion="1.0"encoding="UTF-8"?>*
    *<ejb-jarversion="2.1"xmlns="[http://java.sun.com/xml/ns/j2ee%22xmlns:xsi=%22http://www.w3.org/2001/XMLSchema-instance%22xsi:schemaLocation=%22http://java.sun.com/xml/ns/j2eehttp://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd]">*
    *<display-name>JMSDemo-ejb</display-name>*
    *<enterprise-beans>*
    *<message-driven>*
    *<display-name>MDBMDB</display-name>*
    *<ejb-name>MDBBean</ejb-name>*
    *<ejb-class>jmsdemo.MDBBean</ejb-class>*
    *<transaction-type>Container</transaction-type>*
    *<message-destination-type>javax.jms.Queue</message-destination-type>*
    *<message-destination-link>MDBDestination</message-destination-link>*
    *<activation-config>*
    *<activation-config-property>*
    *<activation-config-property-name>acknowledgeMode</activation-config-property-name>*
    *<activation-config-property-value>Auto-acknowledge</activation-config-property-value>*
    *</activation-config-property>*
    *<activation-config-property>*
    *<activation-config-property-name>destinationType</activation-config-property-name>*
    *<activation-config-property-value>javax.jms.Queue</activation-config-property-value>*
    *</activation-config-property>*
    *</activation-config>*
    *</message-driven>*
    *</enterprise-beans>*
    *<assembly-descriptor>*
    *<container-transaction>*
    *<method>*
    *<ejb-name>MDBBean</ejb-name>*
    *<method-name>*</method-name>
    </method>
    <trans-attribute>Required</trans-attribute>
    </container-transaction>
    <message-destination>
    <display-name>DestinationforMDB</display-name>
    <message-destination-name>MDBDestination</message-destination-name>
    </message-destination>
    </assembly-descriptor>
    </ejb-jar>
    Please let me when I am going wrong.
    Thanks in advance
    Senthil{color}

    Hi
    I am using sun java application server 9.0 and netbeans 5.5.1. For your information the Netbeans 5.5.1 has created already Queue in the sun java application server 9.0 when I created Message driven bean and I am able to see the queue connection in the Sun application server admin console. Even then I getting the same exception displayed below:
    {color:#ff0000}Sep 11, 2010 11:45:17 AM com.sun.enterprise.appclient.MainWithModuleSupport <init>
    WARNING: ACC003: Application threw an exception.
    javax.naming.NameNotFoundException: No object bound to name java:comp/env/jms/MDBDestinationFactory
    at com.sun.enterprise.naming.NamingManagerImpl.lookup(NamingManagerImpl.java:751)
    at com.sun.enterprise.naming.java.javaURLContext.lookup(javaURLContext.java:156)
    at com.sun.enterprise.naming.SerialContext.lookup(SerialContext.java:307)
    at javax.naming.InitialContext.lookup(InitialContext.java:392)
    at jmsdemo.Main.main(Main.java:30)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.sun.enterprise.util.Utility.invokeApplicationMain(Utility.java:232)
    at com.sun.enterprise.appclient.MainWithModuleSupport.<init>(MainWithModuleSupport.java:329)
    at com.sun.enterprise.appclient.Main.main(Main.java:180)
    Exception in thread "main" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    at com.sun.enterprise.appclient.MainWithModuleSupport.<init>(MainWithModuleSupport.java:340)
    at com.sun.enterprise.appclient.Main.main(Main.java:180)
    Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.sun.enterprise.util.Utility.invokeApplicationMain(Utility.java:232)
    at com.sun.enterprise.appclient.MainWithModuleSupport.<init>(MainWithModuleSupport.java:329)
    ... 1 more
    Caused by: javax.naming.NameNotFoundException: No object bound to name java:comp/env/jms/MDBDestinationFactory
    at com.sun.enterprise.naming.NamingManagerImpl.lookup(NamingManagerImpl.java:751)
    at com.sun.enterprise.naming.java.javaURLContext.lookup(javaURLContext.java:156)
    at com.sun.enterprise.naming.SerialContext.lookup(SerialContext.java:307)
    at javax.naming.InitialContext.lookup(InitialContext.java:392)
    at jmsdemo.Main.main(Main.java:30)
    ... 7 more
    Java Result: 1
    {color}
    The following connection properties {color:#0000ff}*jmsCF-jms_MDBBean.sun-resource_*{color} file:
    <?xml version="1.0" encoding="UTF-8"?>
    <resources>
    <connector-resource enabled="true" jndi-name="jms/MDBDestinationFactory" object-type="user" pool-name="jms/MDBDestinationFactory">
    <description/>
    </connector-resource>
    <connector-connection-pool connection-definition-name="javax.jms.QueueConnectionFactory" fail-all-connections="false" idle-timeout-in-seconds="300" is-connection-validation-required="false" max-pool-size="32" max-wait-time-in-millis="60000" name="jms/MDBDestinationFactory" pool-resize-quantity="2" resource-adapter-name="jmsra" steady-pool-size="8"/>
    </resources>
    The following connection properties {color:#0000ff}_jms-jms_MDBBean.sun-resource_{color} file:
    <?xml version="1.0" encoding="UTF-8"?>
    <resources>
    <admin-object-resource enabled="true" jndi-name="jms/MDBBean" object-type="user" res-adapter="jmsra" res-type="javax.jms.Queue">
    <description/>
    <property name="Name" value="MDBBean"/>
    </admin-object-resource>
    </resources>
    Please help.
    Thanks in advance
    Senthil

  • Does WLS 6.1 sp2 allow (bean managed) entity beans to have transaction mode NOTSUPPORTED?

    Hi,
    I have created two bean managed entity beans, User and Role, abstracting users
    and groups in a ldap base. A User may have more than one Role. This is represented
    by a (bean managed) 1:many relationship directed from User to Role. For some weird
    reasons I get a transaction rollback when reading data, when transactions are
    turned on (REQUIRED).
    While we where running WLS 6.1 sp1 we had no problems with this as we could set
    transaction to NOTSUPPORTED for these two EJBs. Due to other hickups we had to
    upgrade to sp2 and suddenly the error reappears leading me to believe that NOTSUPPORTED
    isn't allowed anymore by the WLS. I know that NOTSUPPORTED isn't required by the
    EJB spec, but containers may support it and obviously WLS used to do just that.
    I have not seen any change in the release notes of sp2 that indicates that this
    behaviour has changed.
    Does anybody know if WLS really doesn't support NOTSUPPORTED for enity beans anymore
    in sp2?
    If anybody are curiuos or have any good ideas, the stacktrace I get is:
    javax.ejb.TransactionRolledbackLocalException: EJB Exception:
    - with nested exception:
    [javax.ejb.EJBException
    - with nested exception:
    [weblogic.transaction.RollbackException: Unexpected exception in beforeCompletion:
    sync=weblogic.ejb20.internal.TxManager$TxListener@1c2906 - with nested exception:
    [java.util.ConcurrentModificationException]]]
    Start server side stack trace:
    java.rmi.RemoteException: EJB Exception: ; nested exception is:
         javax.ejb.TransactionRolledbackLocalException: EJB Exception:
    - with nested exception:
    [javax.ejb.EJBException
    - with nested exception:
    [weblogic.transaction.RollbackException: Unexpected exception in beforeCompletion:
    sync=weblogic.ejb20.internal.TxManager$TxListener@1c2906 - with nested exception:
    [java.util.ConcurrentModificationException]]]
    java.util.ConcurrentModificationException
         at java.util.LinkedList$ListItr.checkForComodification(LinkedList.java:535)
         at java.util.LinkedList$ListItr.next(LinkedList.java:476)
         at weblogic.ejb20.manager.DBManager.beforeCompletion(DBManager.java:370)
         at weblogic.ejb20.internal.TxManager$TxListener.beforeCompletion(TxManager.java:481)
         at weblogic.transaction.internal.ServerSCInfo.callBeforeCompletions(ServerSCInfo.java:551)
         at weblogic.transaction.internal.ServerSCInfo.startPrePrepareAndChain(ServerSCInfo.java:88)
         at weblogic.transaction.internal.ServerTransactionImpl.localPrePrepareAndChain(ServerTransactionImpl.java:980)
         at weblogic.transaction.internal.ServerTransactionImpl.globalPrePrepare(ServerTransactionImpl.java:1504)
         at weblogic.transaction.internal.ServerTransactionImpl.internalCommit(ServerTransactionImpl.java:216)
         at weblogic.transaction.internal.ServerTransactionImpl.commit(ServerTransactionImpl.java:190)
         at weblogic.ejb20.internal.BaseEJBLocalObject.postInvoke(BaseEJBLocalObject.java:207)
         at com.takecargo.domainentities.role.RoleBean_1ipw6_ELOImpl.getName(RoleBean_1ipw6_ELOImpl.java:86)
         at com.takecargo.domainentities.role.RoleConverter.getVOforRoleLocal(RoleConverter.java:51)
    Any kind of help would be appreciated:)
    Regards,
    Brynjar Glesnes

    WLS support NotSupported on Entity Beans.
    It looks like you've hit a bug in the EJB container where an internal Collection class has been modified while the
    container is running through an iterator on it.
    You should open a case with [email protected]
    -- Rob
    Brynjar Glesnes wrote:
    Hi,
    I have created two bean managed entity beans, User and Role, abstracting users
    and groups in a ldap base. A User may have more than one Role. This is represented
    by a (bean managed) 1:many relationship directed from User to Role. For some weird
    reasons I get a transaction rollback when reading data, when transactions are
    turned on (REQUIRED).
    While we where running WLS 6.1 sp1 we had no problems with this as we could set
    transaction to NOTSUPPORTED for these two EJBs. Due to other hickups we had to
    upgrade to sp2 and suddenly the error reappears leading me to believe that NOTSUPPORTED
    isn't allowed anymore by the WLS. I know that NOTSUPPORTED isn't required by the
    EJB spec, but containers may support it and obviously WLS used to do just that.
    I have not seen any change in the release notes of sp2 that indicates that this
    behaviour has changed.
    Does anybody know if WLS really doesn't support NOTSUPPORTED for enity beans anymore
    in sp2?
    If anybody are curiuos or have any good ideas, the stacktrace I get is:
    javax.ejb.TransactionRolledbackLocalException: EJB Exception:
    - with nested exception:
    [javax.ejb.EJBException
    - with nested exception:
    [weblogic.transaction.RollbackException: Unexpected exception in beforeCompletion:
    sync=weblogic.ejb20.internal.TxManager$TxListener@1c2906 - with nested exception:
    [java.util.ConcurrentModificationException]]]
    Start server side stack trace:
    java.rmi.RemoteException: EJB Exception: ; nested exception is:
    javax.ejb.TransactionRolledbackLocalException: EJB Exception:
    - with nested exception:
    [javax.ejb.EJBException
    - with nested exception:
    [weblogic.transaction.RollbackException: Unexpected exception in beforeCompletion:
    sync=weblogic.ejb20.internal.TxManager$TxListener@1c2906 - with nested exception:
    [java.util.ConcurrentModificationException]]]
    java.util.ConcurrentModificationException
    at java.util.LinkedList$ListItr.checkForComodification(LinkedList.java:535)
    at java.util.LinkedList$ListItr.next(LinkedList.java:476)
    at weblogic.ejb20.manager.DBManager.beforeCompletion(DBManager.java:370)
    at weblogic.ejb20.internal.TxManager$TxListener.beforeCompletion(TxManager.java:481)
    at weblogic.transaction.internal.ServerSCInfo.callBeforeCompletions(ServerSCInfo.java:551)
    at weblogic.transaction.internal.ServerSCInfo.startPrePrepareAndChain(ServerSCInfo.java:88)
    at weblogic.transaction.internal.ServerTransactionImpl.localPrePrepareAndChain(ServerTransactionImpl.java:980)
    at weblogic.transaction.internal.ServerTransactionImpl.globalPrePrepare(ServerTransactionImpl.java:1504)
    at weblogic.transaction.internal.ServerTransactionImpl.internalCommit(ServerTransactionImpl.java:216)
    at weblogic.transaction.internal.ServerTransactionImpl.commit(ServerTransactionImpl.java:190)
    at weblogic.ejb20.internal.BaseEJBLocalObject.postInvoke(BaseEJBLocalObject.java:207)
    at com.takecargo.domainentities.role.RoleBean_1ipw6_ELOImpl.getName(RoleBean_1ipw6_ELOImpl.java:86)
    at com.takecargo.domainentities.role.RoleConverter.getVOforRoleLocal(RoleConverter.java:51)
    Any kind of help would be appreciated:)
    Regards,
    Brynjar Glesnes

  • Problem with non-container managed entity manager

    i am working on a project, in which i am using entity beans.i use netbeans, glassfish as application server and toplink as persistence provider .
    i created a java class that handles all the operations with the entitys, which means i using non-container managed entity manager.
    in the constructor
    try{
                EntityManagerFactory emf = Persistence.createEntityManagerFactory("voidPU");
                entityManager = emf.createEntityManager();
            catch(Exception ex){
                throw new EJBException(ex.getMessage());
            }then i call a function in this class from a servlet
    the code of the function
    List users = null;
            try {
                ProgLanguages progLanguage = entityManager.find(ProgLanguages.class, languageId);
                users = (List) progLanguage.getUserIdCollection();
            catch(IllegalStateException illegalStateException){
                throw new EJBException(illegalStateException.getMessage());
            catch(IllegalArgumentException illegalArgumentException) {
                throw new EJBException(illegalArgumentException.getMessage());
            }i got an IllegalArgumentException saying Unknown entity bean class: class vanguard.server.entity.ProgLanguages, please verify that this class has been marked with the @Entity annotation
    what confuses me is that sometimes it works and most of the time it does not work, have i made anything wrong?, or there is a problem with any of the tools netbeans, glassfish, or toplink?

    Is it always the same entity that is reported as 'unknown' ? You mention that it works sometimes but is it the same deployment and the same code that works? The first thing I would verify is that the ear is being created as expected by netbeans. Check the persistence.xml file and verify that all of the classes are listed that will be used as entities.
    --Gordon                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Bean Managed Entity Beans(EJB) using Tangosol.

    I am trying to use Bean Managed Entity Beans using Tangosol Coherence.
    The entity bean is currently configured in the weblogic-ejb-jar.xml with:
    <max-beans-in-cache>200</max-beans-in-cache>
    In the public void ejbLoad() method, I am calling the Tangosol Cache to load the entity bean.
    If we have have more that 200 request coming at the same time, we get an OutOfMemoryError exception.
    Is there anyway to overcome this limitation by somehow having the ejb cache to use the tangosol cache?
    Thanks for any help in advance.
    Krishan

    So far, it's not immediately obvious to us what the exact problem is that you are seeing. It sounds like the VM would be using at least 200MB just for the application server's own internal cache, for example, and that you are also using Coherence within the application server to provide additional caching.
    If possible, we should set up a phone call with you and your team, and we could get an engineer from our end to walk through your specific use case with you, so that we could understand what the exact technical challenge(s) is(are) in this particular application.
    Peace.
    p.s. You can email [email protected] directly to schedule a call.

  • Can i user UserTransaction  in a Container-managed transaction Bean

    can i use UserTransaction to control transaction boundaries in a container-managed transaction bean method?
    below is the method:
    there is one-to-many between Employees and SalaryItem
    @TransactionAttribute(value = TransactionAttributeType.REQUIRED)
    private void initEmployeesSalary(Long salarySumId) {
    for(Employees employees: liEmployees){
    for (int i = 0; i < 20; i++) {                                                           
    SalaryItem item = new SalaryDetailItem();
    employees.addSalaryItem(item);
    when there are about 1000 employees,the method run very slow.
    What do you think I should do?
    null

    Hi again,
    The EJB specs say that a stateful Session Bean with CMT is NOT allowed to use the UserTransaction; see page 361 of the EJB2.0 specification. So combining them will not (or should not) work.
    I suggest CMT+SessionSynchronization combined with using a flag to indicate whether notify should be called or not. Otherwise, you could try splitting up the bean into two beans: one with CMT and another one without. The one without CMT could use the UserTransaction and notify.
    Also, you might want to check http://www.onjava.com/pub/a/onjava/2001/10/02/ejb.html
    Hope that helps a bit,
    Guy
    http://www.atomikos.com

  • Primary Key for Read Only Entity Beans In EJB 3.0

    Hi,
    I have checked the spec for ejb 3.0 which mentions that, there is no common standard for the vendor to implement the Read only Entity Beans.
    My question over here is how it is implemented in OC4J??
    Do we need to specify a primary key attribute in the read-only entity bean?
    w.r.t BC4J(ADF) i remember, we used to create a read-only View Object with out specifying a primary key.
    Just want to check is that the way it works in EJB 3.0 (Implemented by OC4J).
    Thanks for your help in advance.
    Shiva

    Hi,
    Try using the JBoss embedded container:
    http://docs.codehaus.org/display/MAVENUSER/How+to+use+the+JBoss+Embedded+EJB3+Container+for+Unit+testing
    /klejs

  • EJB 3.0 question - saving an entity bean containing another entity bean

    Hi,
    First, I want to store an entity bean. Secondly, I want to store another entity bean - containing the first entity bean.
    I have the following code in a session bean for this:
    public void saveFeedScheduling(FeedScheduling feedScheduling, FeedSource feedSource) {
    FeedSource feeds = em.merge(feedSource);
    em.flush();
    feedScheduling.setFeedSource(feeds);
    FeedScheduling feedSched = em.merge(feedScheduling);
    em.flush();
    This seems to work fine - still, is this the proper way to do it?

    Hello,
    This kind of parameter can be specified using the relationship annotation.
    I'm not 100% sure, but, lok at the "cascade element".
    Regards,
    Sebastien Degardin

  • Accessing collection field in container managed persistence bean

    Hello!
    How can i get 1:m relatioship, collection fields value?
    What is the purpose of ejbSelect-method, in bean business class?

    Please ask your EJB questions within the Enterprise JavaBeans section of this forum.
    The ejbSelect Method is a query method (like the finder mehtod) but it is not directly exposed to the client in the home interfacce or component interface. Rather, ejbSelect() is used internally within an entity bean as a helper method to accesss a storage. ejbSelect() is useful when you have entity beans in relationships with external data, such as other entity beans.
    look at http://www.theserverside.com/articles/content/ApplyingEJB/matena8.pdf for an example

  • Client Program accessing J2EE entity Bean

    I have trouble find my Course J2EE bean from a client. (The client
    runs on the same computer but a different VM from the bean.)
    In Glassfish (Sun Application Server Nine), I set up a simple
    Container-Managed Entity Bean. I tried to access it from an external
    client as described in the glassfish EJB
    FAQ https://glassfish.dev.java.net/javaee5/ejb/EJB-FAQ.html
    Here is the client program:
    package RS;
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import javax.xml.parsers.*;
    import org.apache.xml.serialize.*;
    import org.w3c.dom.*;
    import org.xml.sax.*;
    import RS.CourseHome;
    import RS.CoursePK;
    import javax.naming.InitialContext;
    import javax.naming.Context;
    import javax.naming.NamingException;
    import java.rmi.RemoteException;
    import javax.rmi.*;
    import java.util.Properties;
    import Debug.*;
    public class Client {
    public static void main (String arg[]) throws IOException {
    try {
    InitialContext jndiContext = new InitialContext ();
    Debug.P("jndic ongtext" + jndiContext);
    Object o = jndiContext.lookup("RS.CourseHome");
    Debug.P("looked up object "+o + "|"+o.getClass().getName());
    RS.CourseHome home =
        (RS.CourseHome)PortableRemoteObject.narrow(o,RS.CourseHome.class);
    Debug.P("got home "+home);
    Course C = home.create(1);
    C.setName("blah");
    CoursePK PK = new CoursePK();
    PK.number=1;
    C = home.findByPrimaryKey(PK);
    Debug.P(C.getName());
    catch (java.rmi.RemoteException re) {Debug.P("Remote Exception" + re.getMessage());}
    catch (javax.naming.NamingException ne){Debug.P("Naming Exception"+ne.getMessage());}
    catch (javax.ejb.CreateException ce){Debug.P("Create Exception"+ce.getMessage());}
    catch (javax.ejb.FinderException fe){Debug.P("Finder Exception"+fe.getMessage());}
    }Here is the error message:
    Exception in thread "main" java.lang.ClassCastException
    at com.sun.corba.ee.impl.javax.rmi.PortableRemoteObject.narrow
                       (PortableRemoteObject.java:294)
      at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:137)
      at RS.Client.main(Client.java:26)The debugging indicates that I got the Initial Context
    and got the object but the PortableObject.narrow failed:
    jndic ongtextjavax.naming.InitialContext@1d85f79
    looked up object IOR: (huge number deleted)
    com.sun.corba.ee.impl.corba.CORBAObjectImplEarlier, I tried the version below, but based on the suggestion by Mr. Ebbert
    in the forum started "Error When running the Client Program" by sree_devi,
    I checked
    the following. I went to "Jndi Tree Browsing" from the Administrative Console
    and I found a "RS.CourseHome" entry under "ejb" I found RS.CourseHome there
    but did not see the "Course" tghat I expected to see
    Thus, I tried the version above:
    package RS;
       --- imports deleted for conciseness
    import Debug.*;
    public class Client {
    public static void main (String arg[]) throws IOException {
    try {
    InitialContext jndiContext = new InitialContext ();
    Object o = jndiContext.lookup("Course");
    CourseHome home =
        (CourseHome)PortableRemoteObject.narrow(o,CourseHome.class);
    Course C = home.create(1);
    C.setName("blah");
    CoursePK PK = new CoursePK();
    PK.number=1;
    C = home.findByPrimaryKey(PK);
    Debug.P(C.getName());
    catch (java.rmi.RemoteException re) {Debug.P("Remote Exception" + re.getMessage());}
    catch (javax.naming.NamingException ne){Debug.P("Naming Exception"+ne.getMessage());}
    catch (javax.ejb.CreateException ce){Debug.P("Create Exception"+ce.getMessage());}
    catch (javax.ejb.FinderException fe){Debug.P("Finder Exception"+fe.getMessage());}
    }When I run it, I get the following Naming Exception: Course not found
    I confirmed at the administrative console, that I have "Course" listed
    under Enterprise Applications:
    As per the ejb FAQ, I set up my $CLASSPATH so it starts as follows:
    /opt/j2ee/SUNWappserver/lib/appserv-rt.jar:
    /opt/j2ee/SUNWappserver/lib/javaee.jar:I also verifed in my domain.xml that the orb-listener-1, the default
    naming service port was at 3700.
    Here is the info on the Bean that I have running for both of the tries
    at my Client code.
    ejb-jar.xml
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <ejb-jar xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
    http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd"
    version="2.1">
      <enterprise-beans>
        <entity>
           <description>Course</description>
           <display-name>CourseBean</display-name>
           <ejb-name>CourseBean</ejb-name>
           <home>RS.CourseHome</home>
           <remote>RS.Course</remote>
           <ejb-class>RS.CourseBean</ejb-class>
           <persistence-type>Container</persistence-type>
           <prim-key-class>RS.CoursePK</prim-key-class>
           <reentrant>false</reentrant>
           <abstract-schema-name>Course</abstract-schema-name>
           <cmp-field><field-name>number</field-name></cmp-field>
           <cmp-field><field-name>name</field-name></cmp-field>
        </entity>
      </enterprise-beans>
      <assembly-descriptor>
         <security-role>
            <description>Everyone</description>
           <role-name>everyone</role-name>
         </security-role>
         <method-permission>
            <unchecked/>
            <method>
               <ejb-name>CourseBean</ejb-name>
               <method-name>*</method-name>
            </method>
          </method-permission>
         <container-transaction>
            <method>
               <ejb-name>CourseBean</ejb-name>
               <method-name>*</method-name>
            </method>
            <trans-attribute>Required</trans-attribute>
         </container-transaction>
      </assembly-descriptor>
    </ejb-jar>
    Sun-ejb-jar.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE sun-ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 8.1 EJB 2.1//EN"
    "http://www.sun.com/software/appserver/dtds/sun-ejb-jar_2_1-1.dtd">
    <sun-ejb-jar>
      <enterprise-beans>
         <name>CourseBean</name>
         <ejb>
           <ejb-name>CourseBean</ejb-name>
           <jndi-name>Course</jndi-name>
         </ejb>
      <cmp-resource>
         <jndi-name>jdbc/__default</jndi-name>
         <create-tables-at-deploy>true</create-tables-at-deploy>
         <drop-tables-at-undeploy>true</drop-tables-at-undeploy>
      </cmp-resource>
      </enterprise-beans>
    </sun-ejb-jar>
    Course.java
    package RS;
    import java.rmi.RemoteException;
    public interface Course extends javax.ejb.EJBObject {
      public String getName() throws RemoteException;
      public void setName (String Str) throws RemoteException;
      public int getNumber() throws RemoteException;
      public void setNumber (int n) throws RemoteException;
    CourseHome.java
    package RS;
    import java.rmi.RemoteException;
    import javax.ejb.CreateException;
    import javax.ejb.FinderException;
    public interface CourseHome extends javax.ejb.EJBHome {
    public Course create(int id) throws
    CreateException,RemoteException;
    public Course findByPrimaryKey(CoursePK pk)
    throws FinderException,RemoteException;
    CourseBean.java
    package RS;
    import javax.ejb.EntityContext;
    public abstract class CourseBean implements javax.ejb.EntityBean {
    public CoursePK ejbCreate (int number) throws javax.ejb.CreateException{
      this.setNumber(number);
      return null;
    public void ejbPostCreate (int number) {
    public abstract String getName();
    public abstract void setName (String str);
    public abstract int getNumber ();
    public abstract void setNumber (int number);
    public void setEntityContext (EntityContext ctx) {}
    public void unsetEntityContext() {}
    public void ejbActivate () {}
    public void ejbPassivate () {}
    public void ejbLoad () {}
    public void ejbStore () {}
    public void ejbRemove() {}
    }Laurence L. Leff, Ph.D. Associate Professor of Computer Science
    Western Illinois University, 1 University Circle 61455, Pager: 309 367 0787
    FAX 309 298 2302

    hi s-mcgowan,
    "some other processing" comprises of printing of debug lines and publishing to the message queue using JMS. I added more debug lines so that i could see whats really happening... here is the result
    myTableHome.create(...); <----------- no exception was thrown and it returned LocalMyTable object
    print out "Insert successful"
    print out "publishing message"
    ... publish message to message queue using JMS...
    print out "Publish done"
    ... after few milliseconds...
    java.sql.BatchUpdateException: Data exception -- row already exist in index PK_MYTABLE on table MYTABLE.
    From the exception it seems like its doing a batch insert. So that seems to explain why the java.sql.BatchUpdateException is thrown few milliseconds after my call to myTableHome.create(...);
    Is it possible to disable batch update / insert? how?
    thanks in advance,
    leigh

  • Problem with foreign key in entity bean in WSED..Plzzzzz help!!!!!

    hi all,
    m very new to ejb...m crerating container managed entity bean in wsed..The steps I have followed r as follows,
    i) created 2 tables in database,one is PARENT with fields ID(Primary Key) and NAME and another is CHILD with fields ID1(Foreign Key) and NAME.
    ii)created 2 entity beans... 1st is parent with fields id(key field) and name(promote getter & setter methods to local interface)...2nd is child
    (choosed parent as bean super type) with fields id1 (promote getter & setter methods to local interface) and name (promote getter & setter methods to local interface)...
    iii)Generated EJB to RDB mapping(choosed crreate new backend folder->meet in the middle->use existing connection->choosed the tables parent & child in the database->match by name->finish)
    now m getting an error in Map.mapxmi--->"The table PARENT does not have a discriminator column"...and a warning--->"A primary key does not exist for table: CHILD in file: platform:/resource/NewFK/ejbModule/META-INF/backends/DB2UDBNT_V8_1/Map.mapxmi.     Map.mapxmi     NewFK/ejbModule/META-INF/backends/DB2UDBNT_V8_1     L/NewFK/ejbModule/META-INF/backends/DB2UDBNT_V8_1/Map.mapxmi"

    Hi Sandra,
    Many thanks for your response and providing time of yours.
    Now, I have done exactly the same thing, but still it is the same.
    I have created two new tables as below:
    ZAAVREF (Check table)
    MANDT (PK)
    COUNTRY (PK) Domain:ZAACOUNT (CHAR 10)
    ZAAV1 (Foreign key table)
    MANDT (PK)
    COUNTRY (PK) Domain:ZAACOUNT (CHAR 10)
    Then I have created FK on country of foreign key table ZAAV1 and then SE16 (for table ZAAVREF)->Create Entries-> Entered values for Country only->Save....Records entered with valid Country values.
    After that SE16 (for table ZAAV1)->Create Entries-->Entered an Invalid country->Save->Still the record entered to the Database successfully....
    Could you please let me know where I am going wrong.
    I am using SAP R/3 4.7 and creating tables using Tools->ABAP Workbench->Development->ABAP dictionary

  • How to add a finder method in the container manager Bean in the weblogic6.1

    in the environment jbuilder6 andweblogic6.1,use container manager entity Bean,it can automatic generate the findAll() method,I want to add a new method to find an element in the home interface,such as findByName(),name is a element of a table of the database.in the weblogic-cmp-rdbms-jar.xml,this is part of the fiile:
    <finder>
    <finder-name>findAll</finder-name>
    <finder-query><![CDATA[ (= 1 1) ]]></finder-query>
    </finder>
    <finder>
    <finder-name>findByName</finder-name>
    <finder-param>java.lang.String</finder-param>
    <finder-query><![CDATA[ (=name $name) ]]></finder-query>
    </finder>
    It can successfully compile the findAll(),but it is wrong when compile the findByName(),as follows
    "www.ejbgrpx": Method Name: findByName
    "www.ejbgrpx": Invalid specifications for a WebLogic RDBMS CMP EJB.
    "www.ejbgrpx": ERROR: Error from ejbc: weblogic.ejb20.cmp11.rdbms.finders.IllegalExpressionException:
    "www.ejbgrpx": While trying to process Finder
    "www.ejbgrpx": Parameter Types: (java.lang.String)
    "www.ejbgrpx": WebLogic Query: (= name $name)
    "www.ejbgrpx": Finder Expressions: ()
    "www.ejbgrpx": Could not parse WLQL expression: (= name $name) null
    "www.ejbgrpx": ERROR: ejbc found errors
    thank you

    The finder methods that you are referring to are only simple finder methods. If you would like to add specialized finder methods, you can make your entity bean with bean managed persistence and not container managed. If you are using EJB 2.0, your entity bean with container managed persistence can use EJB QL for finder methods. You can search for this topic and/or download the EJB 2.0 specifications
    Hope this helps

  • EJB Entity Beans

    "Entity Beans are suitable for read/write database access when transaction control
    is important. Container managed Entity beans should be suitable for simple entity
    relationships and offer much easier maintenance and development."
    Tell me why or why not you agree with the above statement.
    This is one of the most talked about issues, and I like to see this group's view
    point, regardless of what Sun says in their blueprint.
    On a unrelated note, i like to see what you think about this:
    What are the benefits and disadvantages of using Inner Classes?

    I agree. How are you gonna find the marks without primary key? Sequential seek??
    What you should do is having student_id as primary key of the marks table and create a 1-* relationship between them by student_id.
    Cheers.

Maybe you are looking for

  • NVidia card not receiving interupts

    I like Arch so far but I decided to set up a window manager on it but I can't seem to get X working with anything other than the vesa driver. When X crashes on the nVidia drive, I get this: (**) NVIDIA(0): Depth 16, (--) framebuffer bpp 16 (==) NVIDI

  • Cannot create a new podcast episode!!!!!

    out of the blue, after reading HT's suggestion to create a software instrument via creating a new podcast episode, if i click on the bottom option Create new podcast episode, i get a Box that says new project from template and asks me to name and loc

  • Crystal Reports grouping limits different then tree or tab menu limits...

    <p>Hi,</p><p>This may not be the forum for this, but I figured that if I am trying to make a treemenu function as a replacement for the group tree in CR that it is somewhat relevant...</p><p>I got a production system to run a test and it seems that t

  • VO CreateandInit Row for exisiting rows

    Using: Jdev11.1.1.7 I am working a generic CSV data uploader utility, however I am running into a problem with existing rows. I have a dynamic EO and VO based on configurations defined in a db table, and when I upload data, I am populating the VO wit

  • How to minimize the gap between two regions in a page

    Hi All, How to minimize two regions in a page ? I have two regions in page but I need to minimize the (default) space gap between these regions as it looks too large. Thanks for the answer. Jeffry