Confused with Entity Beans

Hello:
I ve been trying to learn EJBs using Wrox's Professional EJB.
At page number 145 sequence diagram, it shows that ( for a bean
managed persistance Entity bean ) every find<METHOD>(args) invoked on
an EJBHome object will be delegated to a corresponding
ejbFind<METHOD>(args) method on the bean implementation object. I m a
bit confused here.
1. Since from the OO point of view, "find" is about finding, shouldn t
this have been a method on some kind of broker object, that should
have created/found the corresponding implementation objects and
returned the corresponding handles ( object references ). In the case
of findInRange() that returns multiple objects this becomes more
apparent, wherein one need to have an ejb implementation object to
start with in order to get the collection of objects he has been
looking for. Where did I 'didn t get it'
2. One of my friends says Container managed persistence ( CMP ) is not
at all popular due to the inefficiency compared to BMP, and that only
very few projects will be actually using it. Is there any truth in
this.
3. Is there a vendor neutral newsgroup ( and more specific that
comp.java.lang.help ) for posting ejb related discussions.
Thanks
--sony

Hi Sony,
"Sony Antony" <[email protected]> wrote in message
news:[email protected]..
Hello:
I ve been trying to learn EJBs using Wrox's Professional EJB.
At page number 145 sequence diagram, it shows that ( for a bean
managed persistance Entity bean ) every find<METHOD>(args) invoked on
an EJBHome object will be delegated to a corresponding
ejbFind<METHOD>(args) method on the bean implementation object. I m a
bit confused here.
1. Since from the OO point of view, "find" is about finding, shouldn t
this have been a method on some kind of broker object, that should
have created/found the corresponding implementation objects and
returned the corresponding handles ( object references ). In the case
of findInRange() that returns multiple objects this becomes more
apparent, wherein one need to have an ejb implementation object to
start with in order to get the collection of objects he has been
looking for. Where did I 'didn t get it'In fact, a bean serves as the "broker" object, though I don't like
the name that much. Finally, this is the Spec, and you have to
live with it.
2. One of my friends says Container managed persistence ( CMP ) is not
at all popular due to the inefficiency compared to BMP, and that only
very few projects will be actually using it. Is there any truth in
this.It depends on application requirements. CMP are perfect for writing
simple persistance objects with "one object per one DB table" pattern.
From efficiency point of view weblogic does it's best to optimize
bean's behaiviour. You shouldn't be concerned about it.
BMPs are good when you need to deal with coarse-grained persistance.
I'd recomend you to get hands on experience with CMPs and
BMPs. Practice is invaluable source of knowlege.
3. Is there a vendor neutral newsgroup ( and more specific that
comp.java.lang.help ) for posting ejb related discussions.weblogic.developer.interest.ejb is a perfect place for this type of
discussions.
Regards,
Slava Imeshev

Similar Messages

  • Caching data with Entity Bean

    Hello,
    I am performing some tests concerning the benefit of caching data with Entity Bean.
    Here is the case :
    I have an Entity Bean with a business method getName() to retrieve a name field in the EJB.
    I understand that in order to cach data, I have to set the NOT_SUPPORTED transaction attr for this method. In this way, when this method is called, the ejbReload() is not called and the data is retreived from the EJB ready instance (and not from the database).
    Is it true and is it the good way to use the cach mechanism ?
    Now if we consider that this instance is the only one in the ready stage, and it is never pooled (it seems so !), what about a modification of the database from a tier (or from an other EB instance)? The Entity Bean is not able to see this modification seence it does not call the ejbLoad method.
    Is there a way to force an Entity Bean to be periodically polled in order to recover data from the data store when activated ?
    Thanks in advance,
    Thierry

    No, This is wrong way of doing what you want. Most of the application servers provide various configuration settings for this. Eg. caching mechanism, interval on when to call ejbLoad and ejbStore, read only beans. You have to check the documentation for this.
    --Ashwani

  • Report with entity beans - BIG performance problem

    I have several EJBs (CMP entity beans).
    I need to build a report using linked EJBs and show this report
    to a user (so, updates are not needed - report is only for web page demonstration).
    the problem is: such report is generated too slow.
    I have ~100 records in table 'TestResult' and ~500 records in table 'TestObject'.
    these tables are linked like this:
    one testobject <--> many testresults
    for each testresult I need to show a line with some info which should be retrieved
    from bound EJBs (e.g. testresult-testobject-assigneduser-prioritylevel)
    how to optimize such report generation?
    I have heard something about session beans with Value Objects.
    do I need to use such session beans here?
    what is a general solution for generating reports using linked EJBs?
    I tried to solve the problem by using DB View, but it didn't help.
    I have used 'TestResultView' - info is retrieved fast enough from this view
    (several msecs), but displaying this info is still very costly.
    please, help!
    Oracle 8.1.7,
    WebLogic 6.1

    Hi,
    because I have checked the time required to
    1) retrieve EJBS (several msec)Let me share some of my views with you.Once you retrieve the EJBS ie ie the collection of remote interface from the finder method the container is firing single "select " query and gets all the primary keys back.
    2) cycle through it - get fields and display them
    (~4000 msec)Now the cycle of getting the value you are getting the bean from the PooledState to ready state which will get the fields by firing the "select" query (ejbload()). Now in the instance you are invoking the multiple methods and at the end it will remain there in ready till you call the remove which u are not doing so the time out will bring it back to the pooledstate.
    And if you are calling the bean very frequently then all the instances will go to the ready state and the activation & passivation will start developing ......
    So at the end when the bean moves back to the pooled state after timeout the ejbStore() fires the "update " query!!!!
    Let us consider the activation/passivation not appearing for simple understanding !!!!!!!!
    So for each iteration you are firing 2 queries to the database.So if you have 500 records then the queries generatted will be 1(select from finder)+2(1 by select(ejbload)+1 by update(ejbStore))*500. So the flow is calling 1001 queries ...Thus quering about 1000 queries will definetly take some time...
    So what is the solution????
    Any way you dont require to fire the update query as you are just viewing the data...So u can stop calling the ejbStore().
    Hence you queries will drop to half.Now how we can do this is by using the BMP.....
    The other solution is using the Sessionbean and store the data all 500 records in the Object which can be called across the n/w. This object should implements the Serializable interface and this tech is the Transfer Object feature.....
    Hope you find this useful..
    regards
    Vicky

  • Deployment problem sdk 1.4 with entity bean

    hallo!
    i have a big problem with the j2ee sdk 1.4. when i want to add an entity bean to my ear-file, everything goes good, but when i put the sql-ql for the finder-method and save the file i got an error like this
    xxxxxxx.ear is corrupt or cannot be read
    when i dont save and will show the descriptor it generates an empty descriptor for this entity bean.
    the problem is, that the deployment tool cannot generate the deployment desciptor for entity beans. with session bean there was no problems.
    hope somebody can help me.
    thanks

    There's bug in non-U.S. locales. The workaround is described in this thread:
    http://forum.java.sun.com/thread.jsp?forum=136&thread=472692&tstart=15&trange=15
    -Ian Evans
    Sun Microsystems
    J2EE Tutorial team

  • Strange behavior with entity beans and servlets in a cluster

    We have 2 WebLogic 4.5.1 servers in a cluster with none of the Service
              Packs installed. When a client uses the deployed entity beans or
              servlets they work every other time. The times they do not work nothing
              happens. No exceptions, no responses to the client ( i.e. HTTP 404s ),
              nothing. I suspect something in the cluster setup since we do not have
              these same problems on non-clustered entity beans or servlets. We have
              made sure all the entity beans have the Shared Database flag set on and
              added the delayUpdatesUntilEndOfTx false to the enviroment of the DD.
              That didn't fix the problem. Any ideas?
              Thanks in advance,
              Dallas Dempsey
              DEM - Houston, TX
              

    Do you have log files?
              - Prasad
              Chris Dempsey wrote:
              > We have 2 WebLogic 4.5.1 servers in a cluster with none of the Service
              > Packs installed. When a client uses the deployed entity beans or
              > servlets they work every other time. The times they do not work nothing
              > happens. No exceptions, no responses to the client ( i.e. HTTP 404s ),
              > nothing. I suspect something in the cluster setup since we do not have
              > these same problems on non-clustered entity beans or servlets. We have
              > made sure all the entity beans have the Shared Database flag set on and
              > added the delayUpdatesUntilEndOfTx false to the enviroment of the DD.
              > That didn't fix the problem. Any ideas?
              >
              > Thanks in advance,
              > Dallas Dempsey
              > DEM - Houston, TX
              

  • Problem with transaction with Entity Beans in R2

    I had a transaction (initiated by a session bean (requires new)) that takes two entity beans (two bank accounts) and trasfer funds from one to another. It looks like the container is waiting for the transaction, i don't know, here comes the exception I get (this code used to work with a lot of simultaneous clients with R1) :
    com.evermind.server.ejb.TimeoutExpiredException: timeout expired waiting for an instance
    at com.evermind.server.ejb.DBEntityWrapperPool.getWrapperInstance(DBEntityWrapperPool.java:189)
    at com.evermind.server.ejb.DBEntityEJBHome.getWrapperInstance(DBEntityEJBHome.java:135)
    error: Remote: Database error, IO failure: com.evermind.server.rmi.OrionRemoteException: Error enlisting connection resource: javax.transaction.RollbackException: The transaction has been marked for rollback (timed out); nested exception is:
    javax.transaction.RollbackException: The transaction has been marked for rollback (timed out); nested exception is:
    com.evermind.server.rmi.OrionRemoteException: Error enlisting connection resource: javax.transaction.RollbackException: The transaction has been marked for rollback (timed out); nested exception is:
    javax.transaction.RollbackException: The transaction has been marked for rollback (timed out)
    above goes the ejb-jar.xml
    <?xml version="1.0"?>
    <!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.2//EN" "http://java.sun.com/j2ee/dtds/ejb-jar_1_2.dtd">
    <ejb-jar>
    <description>
    </description>
    <enterprise-beans>
    <session>
    <description>
    </description>
    <ejb-name>ContaFacadeEJB</ejb-name>
    <home>contacorrente.ContaFacadeHome</home>
    <remote>contacorrente.ContaFacade</remote>
    <ejb-class>contacorrente.ContaFacadeBean</ejb-class>
    <ejb-ref>
    <ejb-ref-name>ContaCorrenteEJB</ejb-ref-name>
    <ejb-ref-type>Entity</ejb-ref-type>
    <home>contacorrente.ContaCorrenteHome</home>
    <remote>contacorrente.ContaCorrente</remote>
    </ejb-ref>
    </session>
    <entity>
    <description>
    </description>
    <ejb-name>ContaCorrenteEJB</ejb-name>
    <home>contacorrente.ContaCorrenteHome</home>
    <remote>contacorrente.ContaCorrente</remote>
    <ejb-class>contacorrente.ContaCorrenteBean</ejb-class>
    <primkey-class>java.lang.String</primkey-class>
    <reentrant>True</reentrant>
    <persistence-type>Container</persistence-type>
    <cmp-field><field-name>id_conta</field-name></cmp-field>
    <cmp-field><field-name>saldo</field-name></cmp-field>
    <cmp-field><field-name>senha</field-name></cmp-field>
    <primkey-field>id_conta</primkey-field>
    </entity>
    </enterprise-beans>
    <assembly-descriptor>
    <container-transaction>
    <method>
    <ejb-name>ContaFacadeEJB</ejb-name>
    <method-name>*</method-name>
    </method>
    <trans-attribute>RequiresNew</trans-attribute>
    </container-transaction>
    <container-transaction>
    <method>
    <ejb-name>ContaCorrenteEJB</ejb-name>
    <method-name>*</method-name>
    </method>
    <trans-attribute>Mandatory</trans-attribute>
    </container-transaction>
    </assembly-descriptor>
    </ejb-jar>
    and the code of the beans (just the method used)
    Entity (account)
    public void debita(double valor) throws ContaCorrenteException
    double saldoOld=saldo;
    saldo=saldo-valor;
    if (saldo<0)
    throw new ContaCorrenteException("Saldo insuficiente:"+saldoOld);
    Session :
    public void transfere(String idConta1, String idConta2, double valor, String senha) throws ContaCorrenteException
         try
    Context cx=new InitialContext();
    Object homeObject=cx.lookup("java:comp/env/ContaCorrenteEJB");
    ContaCorrenteHome home=(ContaCorrenteHome) PortableRemoteObject.narrow(homeObject,ContaCorrenteHome.class);
    ContaCorrente c1=null;
    ContaCorrente c2=null;
    try
    c1=home.findByPrimaryKey(idConta1);
    c2=home.findByPrimaryKey(idConta2);
    if (!c1.getSenha().equals(senha)) { throw new ContaCorrenteException("Senha incorreta");}
    catch(FinderException e)
    System.out.println("erro ao localizar conta :"+e.getMessage());
    context.setRollbackOnly();
    throw new ContaCorrenteException("Conta inexistente");
    catch(java.rmi.RemoteException e)
    System.out.println("erro Remote: "+e.getMessage());
    context.setRollbackOnly();
    throw new ContaCorrenteException("Erro ao conectar objeto remoto");
    try
    c1.debita(valor);
    c2.credita(valor);
    catch(ContaCorrenteException e)
    context.setRollbackOnly();
    throw new ContaCorrenteException(e.getMessage());
    catch(java.rmi.RemoteException e)
    throw new ContaCorrenteException("Erro de conexco");
         catch (NamingException e)
    System.out.println("erro de localizagco:"+e.getMessage());
    throw new ContaCorrenteException("Erro de acesso remoto na localizacao da conta");
    please, someone help me...
    Thanks in advance

    I forgot : when i try to shut the server down i get the message :
    Shutting down...
    Error serializing bean: Deadlock detected, timing out call after 15 seconds wait for transaction [Transaction d9:fa:4f:b6:ff:ff:ff:ff:4a:0:0:0:0:0:0:0:0:4b:0:ec:6d:ce:c0:16]
    Error serializing bean: Deadlock detected, timing out call after 15 seconds wait for transaction [Transaction d9:fa:4f:b6:ff:ff:ff:ff:4c:0:0:0:0:0:0:0:0:4d:0:ec:6d:d2:d9:d2]
    Error serializing bean: Deadlock detected, timing out call after 15 seconds wait for transaction [Transaction d9:fa:4f:b6:ff:ff:ff:ff:4e:0:0:0:0:0:0:0:0:4f:0:ec:6d:d4:21:a3]
    and it doesn't shutdown.

  • Creating Webservice with entity bean

    I am trying to create a webservice(using entity bean). Using ANT i am building
    up the .ear file. My source files are placed in a directory (c:\test) . I have
    set the path and invoked ANT .In the build.xml file , when it is trying to compile
    the ejb classes , it gives me the following error:
    ERROR: Error from ejbc: Could not locate bean with ejb-name 'EBankEJBean'
    in weblogic-ejb-jar.xml
    Can anybody pls help me out !
    thanx
    arthi

    WLS 7.0 only supports stateless session bean or a plain java
    class as web service.
    From your post it seems you have trouble doing ejbc.
    You will get better answer if you post this in the ejb
    newsgroup.
    regards,
    -manoj
    "arthi" <[email protected]> wrote in message
    news:[email protected]..
    I am trying to create a webservice(using entity bean). Using ANT i am building
    up the .ear file. My source files are placed in a directory (c:\test) . I have
    set the path and invoked ANT .In the build.xml file , when it is trying to
    compile
    the ejb classes , it gives me the following error:
    ERROR: Error from ejbc: Could not locate bean with ejb-name 'EBankEJBean'
    in weblogic-ejb-jar.xml
    Can anybody pls help me out !
    thanx
    arthi
    [att1.html]

  • Jprobe Memory Debugger with Entity Bean

    hi,
    I m testing an EJB application(Bean Managed) using Jprobe Memory debugger.
    While testing it gives me that objects referred by entity bean are loitering . for eg if somewhere in my code i created an integer using new Integer and if I m letting it passed to ejbCreate .then that object is pointed as loitering while debugging. further it happens with srtring and data access Objects and otheres as well.
    so is there a memory Leak or The debugger is handling the entity bean in such a way.
    version of jprobe used is 5.2.3 on windows
    Please provide me help regarding the same

    Actually, what one or the developers in my group found out is two things:
    1) The clone is a shallow copy.They copy the references but not objects themselves. This has been causing problems for us.
    2) It seems that you don't work on a copy and you work on the original and they keep a copy. Now, this is fine IF you don't have multiple threads working on the same Entity bean and we moved our application from Weblogic where it throws an exception if that Entity bean is in use to OC4J which is suppose to copy the bean and doesn't so you have multiple threads possibly modifying the same object.

  • Performance with entity bean... What am i doing wrong??

    hello,
    My configuration:
    Development = OC4J 10g 9.0.4.0.0 standalone
    Production = Oracle IAS 10g 9.0.4
    JBoss version = 4.0.3 SP1
    I have an application using CMP Entity beans. My architecture uses Stateless session bean to access to the entities and values objects to transfer the data.
    One of this entity beans has the following parameters:
    id : NUMBER(20)
    name : VARCHAR(255)
    data : BLOB
    2 values objects are used to access the entity bean:
    MyLightValueObject with parameters: id and name
    MyValueObject with parameters: id, name and data
    The method findAll of my stateless session bean takes about 255 ms when there are 50 objects in the database under JBoss, but takes more than 10 seconds when deployed on OC4J.
    <pre>
         public java.util.Collection findAll() throws javax.ejb.FinderException,
                   javax.naming.NamingException {
              // This statement takes about 200 millisonds on either server.
              java.util.Collection selected = getLocalHome().findAll();
    // The access to light value object took 10 seconds under OC4J !
              ArrayList retval = new ArrayList(selected.size());
              for (Iterator i = selected.iterator(); i.hasNext();) {
                   retval.add(((ClauseLocal) i.next()).getClauseLightValue());
              return retval;
    </pre>
    I tried the following link already :
    http://download-west.oracle.com/docs/cd/B10464_02/core.904/b10379/optj2ee.htm#sthref529
    However, when I redeploy my ear on the server, whatever the options specified on the entity-deployement tag, the server reset his default options. Moreover, the locking_mode attribute is not specified in the DTD.
    Could you please help me.... Thanks for your comprehension.

    To install Firefox from the Android Market web site, you must be logged in to the web site and your phone using the same Google account. If that doesn't work, you can follow the instructions here for other ways to install Firefox for Android: https://wiki.mozilla.org/Mobile/Platforms/Android

  • Problem woking with entity beans on WL 8.1

    Hi,
    I'm evaluating WL8.1.I'm able to deploy session beans & MDBs & test successfully.Similarly
    , I' m able to deploy entity beans but, not able to test it successfully.It says
    there was a problem in identifying the bean using the specified JNDI name.The
    underlying table name contains '_'(underscorre).Does this create problem.Is there
    any patch for this from bea?
    It 'll be greate if some one respond with the details.
    Thanks
    Raja

    Thanks for ur info.Is this 'CR122524_81sp1.jar' available from bea site?
    Regards
    Raja
    "Deepak Vohra" <[email protected]> wrote:
    >
    >
    CR122524_81sp1.jar
    is required if a table has a underscore(_).
    "raja" <[email protected]> wrote:
    Hi,
    I'm evaluating WL8.1.I'm able to deploy session beans & MDBs & testsuccessfully.Similarly
    , I' m able to deploy entity beans but, not able to test it successfully.It
    says
    there was a problem in identifying the bean using the specified JNDI
    name.The
    underlying table name contains '_'(underscorre).Does this create problem.Is
    there
    any patch for this from bea?
    It 'll be greate if some one respond with the details.
    Thanks
    Raja

  • Force read with entity beans

    Hi,
    is there a way to force the container to reload an Entity EJB (not read-only), something like read-timeout-seconds?
    Thx,
    A.

    So you mean you're changing the data in the database and the entity bean isn't picking up these changes?
    If you call ejbLoad() the container will instruct the instance to synchronize its state by loading its state from the underlying database (so reload the ejb basically)
    Depending on what app server you're using - you can tell the container to call ejbLoad(), even if the data is already in cache, by default. This will probably be a setting in some .xml file.

  • How can I control the EJB's Transaction with entity bean

    If I use entity bean, the Transaction is managed by container.and I want to create JDBC Connection by myselft ,not the Datasource,how is the transaction is controlled by the container,if transaction is not controlled ,how can I control it??

    Hi,
    If you want to control the transaction your self then you need to use javax.transaction.UserTransaction interface and methods defined by it.
    Hope this helps
    Vishal

  • Problem with entity bean

    Hi friends, i am using cmp entity bean to access my relational data base. In my table i am using a sequence (oracle) to generate a sequentiel number as a unique identifier so in my entity bean i am not inserting a primery key. The problem is that i need to get the primary key of the bean after creating and storing it to use the key for other treatment. Any idea, thank a lot

    Hi,
    It seems you just need to move all "after creation" stuff (including getId()) into ejbPostCreate method.
    If I don't miss anything, think that's all.
    Good luck

  • Question on Persistence (Entity Beans, Hibernate, JDBC)

    Hi everybody!
    Until now, I have read a lot about persistence in the J2EE-sector, but I am still confused about which technology to used in my case.
    I hope, that maybe you can give me some hints, by telling me which technology is good or bad regarding my requirements:
    I want to build a customer- and order-management system fullfilling the following requirements:
    1. The client is a Java application, the server is a JBOSS 4.0.1
    2. The databasa scheme exists already and I'm not allowed to change it.
    Some data, that logically belongs together and which shall be presented together to the client is distributed over 2 database tables.
    3. The user cannot just create new and view data, but will also edit existing data quite often.
    4. The user can assign products to an order. Often, there will be more than 1000 products assigned to an order, which will be presented to the user as a table (e.g. JTable). The user can then edit each cell of that 1000-row table, which of course will lead to an update in the db.
    5. The user can also assign customers to a specific role in an order-process. On the other hand, each customer can make many orders.
    So, we have a n:m relation here with the db-tables Customer, Order, OrderCustomer.
    6. A complex search functionality has to be implemented, where the db-query is created dynamically at runtime.
    7. The application is a multi-user application (about 10 users). It will be very rare, that users will work on the same data at the same time, but it might happen.
    8. The database type (SAP DB) will not be changed in the near future.
    With these 8 requirements in mind, I dealed a lot with EntityBeans, Hibernate and JDBC with SesseionBeans during the last 2 weeks.
    Until now, I came to the following conclusions.
    Hibernate is too slow. That'S bad, for data is edited very often and sometimes I want to edit just a single cell in 1000-row table.
    Hibernate's biggest advantage - that it makes your application independent of the database type - is not even required (see point 8).
    JDBC with SessioBeans: Very fast (I tried a simple query and it was about 10 times faster than Hibernate).
    The disadvantage is, that I have to take care about all the transaction, concurrency control etc. things.
    If I use JDBC, I want to do it that way: A SessionFacade accesses a DAO-object which executes the DB-query and returns the result to the SessionFacade which in the last step will pass the result to the client.
    Entity Beans: I am completely confused with Entity Beans.
    I read a lot about the CompositeEntity-Pattern for BMP. But on sun's J2EE Pattern page (http://java.sun.com/blueprints/corej2eepatterns/Patterns/CompositeEntity.html)
    they said, that it's just useful when using the EJB 1.1 specification, because from EJB 2.0. the container or whatever will take care about lazy loading and store optimization.
    So, from EJB 2.0. you should prefer using CMP-Beans with Container Managed Relationships (CMR), but as I heard, the dependent objects cannot be accessed and changed by the client when using CMPBeans with CMR.
    However, a simple DB/Entity-mapping will not work in my case, because as mentioned above, there are thousands of products from the db to be managed at the same time. So here, I thought, the Composite pattern with its lazy loading strategy would be useful.
    Furthermore, I have an n:m relationship in my database scheme, which is not trivial to map to entity beans. And don't forget that some related data is spread over 2 databse tables.
    To sum it up, it would be very nice if some of you could clarify this perisistence nightmare, especially some clarification about if and how to use EntityBeans when having n:m relationships, editing data a lot, managing lots of table rows at once and having related data distributed over 2 database tables.
    So, which technology would you prefer with the 8 requirements in mind? Hibernate, Entity Beans or JDBC with SessionBeans? Or would you prefer a mixed solution?
    Thanx for every hint.
    Regards,
    egon

    Here the requested information about the test:
    Goal:
    Find all customers, who's branches have the String "Branch" in their name.
    Both times, a simple client accesses the same SessionBean in a JBOSS-Container.
    This Bean has 2 methods. One accesses the DB via Hibernate (executeCriteria), the other one via JDBC (executeCriteriaJDBC).
    The code to count the seconds of computation is as follows:
    long startTime = System.currentTimeMillis();
    List customerList = bean.executeCriteria(dc);
    System.out.println("Hibernate: "+((System.currentTimeMillis()-startTime)/1000.0f)+" sek");
    startTime = System.currentTimeMillis();
    List customerListJDBC = bean.executeCriteriaJDBC(query);
    System.out.println("JDBC: "+((System.currentTimeMillis()-startTime)/1000.0f)+" sek");
    HIBERNATE:
    CODE:
    Branch Branch = new Branch();
    Branch.setName("%Branch%");
    Example example = Example.create(Branch);     
    DetachedCriteria dc = DetachedCriteria.forClass(Customer.class)
    .createCriteria("branches").add(example.enableLike()).setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    QUERY:
    select
            this_.UUID as UUID1_1_,
            this_.NAME as NAME1_1_,
            this_.CUSTOMERNO as CUSTOMERNO1_1_,
            this_.SHORTDESC as SHORTDESC1_1_,
            this_.LONGDESC as LONGDESC1_1_,
            this_.TAXNUMBER as TAXNUMBER1_1_,
            this_.SALESTAXID as SALESTAXID1_1_,
            this_.ACCOUNTHOLDER as ACCOUNTH8_1_1_,
            this_.BANKACCOUNT as BANKACCO9_1_1_,
            this_.BANKCODE as BANKCODE1_1_,
            this_.BANKNAME as BANKNAME1_1_,
            this_.AREA1TEXT as AREA12_1_1_,
            this_.AREA2TEXT as AREA13_1_1_,
            this_.AREA3TEXT as AREA14_1_1_,
            this_.AREA4TEXT as AREA15_1_1_,
            this_.AREA5TEXT as AREA16_1_1_,
            this_.CH_UUID as CH17_1_1_,
            this_.REFTEXT1 as REFTEXT18_1_1_,
            this_.REFTEXT2 as REFTEXT19_1_1_,
            this_.REFTEXT3 as REFTEXT20_1_1_,
            branch1_.UUID as UUID0_0_,
            branch1_.NAME as NAME0_0_,
            branch1_.ILN as ILN0_0_,
            branch1_.BRANCHID as BRANCHID0_0_,
            branch1_.SHORTDESC as SHORTDESC0_0_,
            branch1_.LONGDESC as LONGDESC0_0_,
            branch1_.BAGSRECEIVED as BAGSRECE7_0_0_,
            branch1_.CUSTOMER_UUID as CUSTOMER8_0_0_
        from
            CUSTOMER this_,
            BRANCH branch1_
        where
            this_.UUID=branch1_.CUSTOMER_UUID
            and (
                branch1_.NAME like ?
    RESULT:
    Customername: Customer_A
    Customername: Customer_F
    Customername: Customer_D
    Customername: Customer_R
    Customername: Customer_S
    TIME:
    Hibernate: 1.343 sek
    JDBC:
    QUERY:
    Select distinct c.* from Customer c, Branch b where b.id=b.Customer_id and b.name like '%Branch%'
    // After getting the result of the query: Create a list of Customer-objects. Set all attributes of each Customer-object.
    RESULT:
    Customername: Customer_R
    Customername: Customer_A
    Customername: Customer_S
    Customername: Customer_D
    Customername: Customer_F
    TIME:
    JDBC: 0.125 sek
    The Customer.hbm.xml (auto-generated in Eclipse with Middlegen)
    <?xml version="1.0"?>
    <!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
    <hibernate-mapping>
    <!--
        Created by the Middlegen Hibernate plugin 2.2
        http://boss.bekk.no/boss/middlegen/
        http://www.hibernate.org/
    -->
    <class
        name="hibernate.hibernate.Customer"
        table="CUSTOMER"
        lazy="false"
    >
        <id
            name="uuid"
            type="java.lang.String"
            column="UUID"
        >
            <generator class="assigned" />
        </id>
        <property
            name="name"
            type="java.lang.String"
            column="NAME"
            length="100"
        />
        <property
            name="customerno"
            type="java.lang.Integer"
            column="CUSTOMERNO"
            length="5"
        />
        <property
            name="shortdesc"
            type="java.lang.String"
            column="SHORTDESC"
            length="50"
        />
        <property
            name="longdesc"
            type="java.lang.String"
            column="LONGDESC"
            length="100"
        />
        <property
            name="taxnumber"
            type="java.lang.String"
            column="TAXNUMBER"
            length="50"
        />
        <property
            name="salestaxid"
            type="java.lang.String"
            column="SALESTAXID"
            length="50"
        />
        <property
            name="accountholder"
            type="java.lang.String"
            column="ACCOUNTHOLDER"
            length="50"
        />
        <property
            name="bankaccount"
            type="java.lang.String"
            column="BANKACCOUNT"
            length="50"
        />
        <property
            name="bankcode"
            type="java.lang.String"
            column="BANKCODE"
            length="50"
        />
        <property
            name="bankname"
            type="java.lang.String"
            column="BANKNAME"
            length="50"
        />
        <property
            name="area1text"
            type="java.lang.String"
            column="AREA1TEXT"
            length="50"
        />
        <property
            name="area2text"
            type="java.lang.String"
            column="AREA2TEXT"
            length="50"
        />
        <property
            name="area3text"
            type="java.lang.String"
            column="AREA3TEXT"
            length="50"
        />
        <property
            name="area4text"
            type="java.lang.String"
            column="AREA4TEXT"
            length="50"
        />
        <property
            name="area5text"
            type="java.lang.String"
            column="AREA5TEXT"
            length="50"
        />
        <property
            name="chUuid"
            type="java.lang.String"
            column="CH_UUID"
            length="50"
        />
        <property
            name="reftext1"
            type="java.lang.String"
            column="REFTEXT1"
            length="50"
        />
        <property
            name="reftext2"
            type="java.lang.String"
            column="REFTEXT2"
            length="50"
        />
        <property
            name="reftext3"
            type="java.lang.String"
            column="REFTEXT3"
            length="50"
        />
        <!-- Associations -->
        <!-- bi-directional one-to-many association to Branch -->
        <set
            name="branches"
            lazy="true"
            inverse="true"
           cascade="all"
        >
            <key>
                <column name="CUSTOMER_UUID" />
            </key>
            <one-to-many
                class="hibernate.hibernate.Branch"
            />
        </set>
    </class>
    </hibernate-mapping>So, seems to me like Hibernate is also getting the data from the Branch-Table related to each Customer. Maybe this is the reason, why Hibernate is slower.
    But as you can see in the mapping-File of the customer, I wanted Branches to be lazy loaded.
    Do you have any ideas, why Hibernate is so much slower? Any hints for optimizing that code?
    Do you have any further tricks to optimize Hibernate? Unfortunately I am not allowed to make changes at the database, so I cannot e.g. set indices for optimization.
    However, I�m a Hibernate-Newbie. In fact, I just made this test and was very disappointed about its result, so I didn�t keep on working with Hibernate.
    But maybe you can proof me, that Hibernate is a good choice. If so, do you have any good resources (links, books) that help working with Hibernate in connection with JBOSS, describe how to map n:m relationships, show how to work with large results and so forth?
    Thanx for help,
    egon

  • Problems accessing tables in oracle database with ejb entity bean

    I have created a simple server application that uses an entity bean (version 2.0) for an existing table in oracle database, and a session bean that is used as an outside interface for performing operations on that table.
    after deploying the server and client application the client attempts to perform an operation with the session bean remote interface it obtained.
    The session bean uses a locale interface to communicate with the entity bean, but when it tries to use its methods (create, findByXXX) it always get the following Exception: java.sql.SQLException: ORA-00942: table or view does not exist.
    the table of course exists, and the username password I'm using has all the permissions needed for this table.
    note - I'm using the Forte enterprise edition 4.0 as developer tool.
    I'll be glad to get some help.
    Here is the full stack trace of the exception:
    javax.ejb.TransactionRolledbackLocalException: Exception thrown from bean; nested exception is: javax.ejb.EJBException: nested exception is: java.sql.SQLException: ORA-00942: table or view does not exist
    javax.ejb.EJBException: nested exception is: java.sql.SQLException: ORA-00942: table or view does not exist
    java.sql.SQLException: ORA-00942: table or view does not exist
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:168)
    at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:208)
    at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:543)
    at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1405)
    at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteDescribe(TTC7Protocol.java:643)
    at oracle.jdbc.driver.OracleStatement.doExecuteQuery(OracleStatement.java:1674)
    at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1870)
    at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:363)
    at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:314)
    at com.sun.ejb.persistence.SQLEngine.ejb20Finder(SQLEngine.java:226)
    at com.sun.ejb.persistence.PartitionImpl.ejbFinder(PartitionImpl.java:736)
    at com.cti2.telco.core.ejb.entity.userInfo.UserInfoEJB_PM.ejbFindByEmail(UserInfoEJB_PM.java:393)
    at com.cti2.telco.core.ejb.entity.userInfo.UserInfoEJB_PM_LocalHomeImpl.findByEmail(UserInfoEJB_PM_LocalHomeImpl.java:64)
    at com.cti2.telco.core.ejb.UserManagerEJB.authenticate(UserManagerEJB.java:77)
    at com.cti2.telco.core.ejb.UserManagerEJB.authenticate(UserManagerEJB.java:68)
    at com.cti2.telco.core.ejb.UserManagerEJB_EJBLocalObjectImpl.authenticate(UserManagerEJB_EJB
    LocalObjectImpl.java:63)
    at com.cti2.telco.core.ejb.dispatch.TelcoFacadeEJB.userLogin(TelcoFacadeEJB.java:80)
    at com.cti2.telco.core.ejb.dispatch.TelcoFacadeEJB_EJBObjectImpl.userLogin(TelcoFacadeEJB_EJBObjectImpl.java:24)
    at com.cti2.telco.core.ejb.dispatch._TelcoFacadeEJB_EJBObjectImpl_Tie._invoke(Unknown Source)
    at com.sun.corba.ee.internal.POA.GenericPOAServerSC.dispatchToServant(GenericPOAServerSC.java:519)
    at com.sun.corba.ee.internal.POA.GenericPOAServerSC.internalDispatch(GenericPOAServerSC.java:204)
    at com.sun.corba.ee.internal.POA.GenericPOAServerSC.dispatch(GenericPOAServerSC.java:112)
    at com.sun.corba.ee.internal.iiop.ORB.process(ORB.java:273)
    at com.sun.corba.ee.internal.iiop.RequestProcessor.process(RequestProcessor.java:84)
    at com.sun.corba.ee.internal.orbutil.ThreadPool$PooledThread.run(ThreadPool.java:99)
    ...

    Well it seems like the problems has a simple explanation. The Forte assigns a default table name (<entityName>EJBTable) when creating an entity bean from an existsing table in DB (which is not the same as the one it was created from !!!). Also, for reason unknown, when you deploy these entity beans, it doesn't even create the new table under its new name (even if instructed to).
    So using the Forte we managed to use successfuly only entity beans that were created "from scretch" (when deployed their tables are created).
    Does anyone know how to change the default name the Forte uses, and make it work properly with entity beans created from an existsing table (without going over the xml's) ?

Maybe you are looking for