Entity Bean on dataBase views

Hi forum,
I Have to migrate an existing application to JEE (with EJB3).
In this application there are a lot of dataBase views.
I'm new in EJB3 and I don't know how to structure cleanly entity beans (Specially when it are created from dataBase views).
My problem is that for each query made from the same dataBase view I almost have to create a new entity bean with a different @Id.
What can I do to to avoid it?
I had thought to genrate a new @Id (attribute not persistent) but I think is not possible. It's right ?
Someone can help me ?
Thanks

Hello Kenny,
The view can be treated the same as a table, it just needs to have some field or set of fields that can uniquely identify rows for it to be able to map to an Entity. Unless the view has rows that are exact duplicates, in the worst case you can use the entire row as the primary key.
Best Regards,
Chris

Similar Messages

  • CMP Entity Bean from dataBase views

    Hi forum,
    I Have to migrate an existing application to JEE (with EJB3).
    In this application there are a lot of dataBase views.
    I'm new in EJB3 and I don't know how to structure cleanly entity beans (Specially when it are created from dataBase views).
    My problem is that for each query made from the same dataBase view I almost have to create a new entity bean with a different @Id.
    What can I do to to avoid it?
    I had thought to genrate a new @Id (attribute not persistent) but I think is not possible. It's right ?
    Someone can help me ?
    Thanks

    "CMP provides you with database independence and less coding efforts."
    BMP is not database dependent, unless you invoke database specific things in your SQL (something I do not do). CMP on the otherhand is inherently appserver specific (which was it's goal when BEA, IBM, et al. came up with it), and still limits your design possibilities. See this thread for an example:
    http://forum.java.sun.com/thread.jsp?forum=13&thread=318785
    As for less coding effort, that is a relative statment. Yes a simple CMP bean requires less coding to develop the first time. I personally view a few lines of SQL to load and store the data as being fairly trivial. But that needs to be offset with the problems inherent in using appserver specific CMP implementations.
    As an example, try mapping WebSphere CMP to a pre-existing database without using IBM's IDE. It's an incredible pain in the ass since WebSphere does not come with a "meet-in-the-middle" solution. Any J2EE developer that has had the experience of working with different appservers (especially if they have had to port an app, as I have) can attest to the complications that arise with each implementation.
    A BMP bean, written with non-DB-specific SQL, is the most portable, most flexible approach to EntityBeans. Yes, it requires the developer to be able to write some SQL, which should not take a significant amout of time. WRT queries, you have to write them, either SQL, EQL, or some appserver specific format.
    As an aside, the use of code generators to simplify the creation of EJBs lends itself well to BMP. By using a (or writing your own) code generator, you can mitigate the annoying SQL bugs that creep up early in development.

  • Problem with mapping the Entity beans onto database tables

    Hi,
    I got a problem with mapping the Entity beans onto database tables. Here are what I did:
    First Step:
    asant capture-schema
    Second Step:
    capture-schema -driver com.pointbase.jdbc.jdbcUniversalDriver -dburl jdbc:pointbase:server://localhost/sun-appserv-samples -username pbPublic -password pbpublic -table APPLICANT -table APPLICANTSKILL -table CUSTOMER -table LOCATION -table job -table JOBSKILL -table SKILL -out build/agency.dbschema
    The first step was fine. But, in the second step, I got the error message as follow:
    using dburl:jdbc:pointbase:server://localhost/sun-appserv-samples
    using username:pbPublic
    using password:pbpublic
    using driver:com.pointbase.jdbc.jdbcUniversalDriver
    using schemaname:null
    using output file:build/agency.dbschema
    JDO71100: Failed to find a class. Verify that the class is available on your CLASSPATH
    java.lang.ClassNotFoundException: com.pointbase.jdbc.jdbcUniversalDriver
    at java.net.URLClassLoader$1.run(URLClassLoader.java:199)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:141)
    at com.sun.forte4j.modules.dbmodel.jdbcimpl.ConnectionProvider.<init>(Co
    nnectionProvider.java:38)
    at com.sun.jdo.api.persistence.mapping.ejb.CaptureSchema.main(CaptureSch
    ema.java:130)
    at com.sun.jdo.spi.persistence.support.ejb.util.CaptureSchemaWrapper.mai
    n(CaptureSchemaWrapper.java:29)
    Thanks for your help!

    You need to add the pbclient.jar or some similar name like that, in the CalssPath.

  • CMP Entity Bean with database specific features

    Hi there,
    I�m studying Entity Beans and I'm doing some experiences with SQL Server.
    At first, I built a CMP Bean and marked in deploytool to create the tables. Ok, it worked.
    Now, I'm trying to interact to an existent database. But, I got a problem: the primary key is defined by the Server. I can read it and I can remove entries. But, when I try to insert some entry, I can't pass the key in SQL statement. I edited the generated statement to do it, but it doesn't work. I get a RollbackException.
    My question is: is it possible to do what I'm intending to do with CMP? What am I doing wrong?
    Do you think that, to do this, I should use BMP Entity beans?
    Thanks in advance,
    Anicio

    "CMP provides you with database independence and less coding efforts."
    BMP is not database dependent, unless you invoke database specific things in your SQL (something I do not do). CMP on the otherhand is inherently appserver specific (which was it's goal when BEA, IBM, et al. came up with it), and still limits your design possibilities. See this thread for an example:
    http://forum.java.sun.com/thread.jsp?forum=13&thread=318785
    As for less coding effort, that is a relative statment. Yes a simple CMP bean requires less coding to develop the first time. I personally view a few lines of SQL to load and store the data as being fairly trivial. But that needs to be offset with the problems inherent in using appserver specific CMP implementations.
    As an example, try mapping WebSphere CMP to a pre-existing database without using IBM's IDE. It's an incredible pain in the ass since WebSphere does not come with a "meet-in-the-middle" solution. Any J2EE developer that has had the experience of working with different appservers (especially if they have had to port an app, as I have) can attest to the complications that arise with each implementation.
    A BMP bean, written with non-DB-specific SQL, is the most portable, most flexible approach to EntityBeans. Yes, it requires the developer to be able to write some SQL, which should not take a significant amout of time. WRT queries, you have to write them, either SQL, EQL, or some appserver specific format.
    As an aside, the use of code generators to simplify the creation of EJBs lends itself well to BMP. By using a (or writing your own) code generator, you can mitigate the annoying SQL bugs that creep up early in development.

  • CMP Entity Beans read database row twice?

    Here are two basic questions regarding container managed persistence Entity Beans:
    How many database read operations are performed when a remote reference to a CMP Entity Bean is obtained by a client?
    Is it correct, that each row is read twice?
    For example if a have one row in a database which I want to lookup, AFAIK first the findByPrimaryKey method perfoms a select to lookup the primary key, and then the (container-)ejbLoad method actually reads the row a second time to populate the CMP fields of the bean.
    And how often are UPDATE statements performed?
    Is a database UPDATE statement performed each time a setXX method is invoked?
    Thanks for any help,
    Robert

    How many database read operations are performed when a
    remote reference to a CMP Entity Bean is obtained by a
    client?
    Is it correct, that each row is read twice?It all depends on the CMP system. A simple system might well hit the database twice, once to validate the primary key and once to load the object's fields. A
    smarter system might try to cache the results from the first, so it didn't need to do the second (although this might be a bit dodgy from a transactional point of view).
    However, a couple of facts about databases come in here. Firstly, the query to check the primary key doesn't actually need to load any data from the table: it just needs to check that the key exists. Thus, it should be possible to handle this query just using the index, not touching the table itself at all. Secondly, databases do their own caching, so if a row was loaded in the first query, there is a good chance that it would still be around for the second.
    And how often are UPDATE statements performed?
    Is a database UPDATE statement performed each time a
    setXX method is invoked?Under CMP 1.1, UPDATES are typically done at the end of a transaction; if you use container-demarcated transactions, then yes, UPDATES will happen after every call. If the client code sets up its own transaction, then the UPDATE will only happen after several setXXX calls.
    This can be a performance problem. A common solution is the use of coarse-grained detail objects:
    http://java.sun.com/j2ee/blueprints/sample_application/model/ (section 10.4.1.2)

  • Polymorphic Entity Object on Database View ?

    Hi all,
    We want to implement polymorphism on business components (EO, VO). I have some questions :
    1) On the supertype-subtype, is it better to use ONE table for all subtypes , or using different tables with each subtype ?
    2) Is it recommended to use Entity Object on a Database View + Instead Of Trigger ?
    Thank you very much,
    xtanto

    Our recommendation is in the ADF Developer's Guide for Forms/4GL Developers, in section 26.6 "Using Inheritance in Your Business Domain Layer". A single table is the simplest and most functional.
    There's nothing wrong with using a view with instead-of triggers, as long as your not wasting your time to write PL/SQL that would be duplicating what ADF BC could automatically do for you using join view objects, with multiple entity usages, against multiple underlying tables. In general, you don't need to use views with instead-of triggers. See section 26.5 "Basing an Entity Object on a Join View or Remote DBLink" if you do.

  • Generate entity bean from Oracle view fails

    Hello,
    is it possible to create an Entity Bean (v3) from an Oracle View in jDev (Build JDEVADF_11.1.1.1.0_GENERIC_090615.0017.5407)?
    In the wizard I can see my view, select it, specify all the info/details about it, but when clicking 'Finish' I see the "EJB Log" window appearing empty and the entity bean is not created. Already tried it in two different PCs without success.
    thanks!

    You can rename EJB and EJB classes (refactor) by right-clicking on the EJB node in
    project navigagor and selecting "Rename EJB and EJB Classes"
    In the dialog box you would get an option to refactor classes.
    raghu
    JDev Team

  • Simple Entity Bean JWS fails: Connection has already been created in this tx context

    I am new to Weblogic Workshop 8.1, and trying to create an EntityBean from a pre-existing
    database table.
    I get an error that indicates the JWS is using the default cgPool rather then
    my new pool for some transaction.
    I added my database (DB2) pool and data source, and then created an entity bean
    using "New Entity Bean from database table.
    I then wrapped this Entity Bean in a control and generated a JWS.
    When I run the JWS and execute FindByPrimaryKey, I get the following error:
    Submitted at Friday, April 2, 2004 11:07:30 AM CST
    <error>
    <faultcode>JWSError</faultcode>
    <faultstring>Couldn't get connection:
    java.sql.SQLException: Connection has already been created in this tx context
    for pool named cgPool. Illegal attempt to create connection from another pool:
    ATGW_POOL
    java.sql.SQLException: Connection has already been created in this tx context
    for pool named cgPool. Illegal attempt to create connection from another pool:
    ATGW_POOL
    at weblogic.jdbc.jts.Driver.getExistingConnection(Driver.java:410)
    at weblogic.jdbc.jts.Driver.connect(Driver.java:141)

    I am new to Weblogic Workshop 8.1, and trying to create an EntityBean from a pre-existing
    database table.
    I get an error that indicates the JWS is using the default cgPool rather then
    my new pool for some transaction.
    I added my database (DB2) pool and data source, and then created an entity bean
    using "New Entity Bean from database table.
    I then wrapped this Entity Bean in a control and generated a JWS.
    When I run the JWS and execute FindByPrimaryKey, I get the following error:
    Submitted at Friday, April 2, 2004 11:07:30 AM CST
    <error>
    <faultcode>JWSError</faultcode>
    <faultstring>Couldn't get connection:
    java.sql.SQLException: Connection has already been created in this tx context
    for pool named cgPool. Illegal attempt to create connection from another pool:
    ATGW_POOL
    java.sql.SQLException: Connection has already been created in this tx context
    for pool named cgPool. Illegal attempt to create connection from another pool:
    ATGW_POOL
    at weblogic.jdbc.jts.Driver.getExistingConnection(Driver.java:410)
    at weblogic.jdbc.jts.Driver.connect(Driver.java:141)

  • Entity Beans Cache

    Hi,
    We are running our application on WL platform 7.0. We have a number of EntityBeans(about
    30-40) which are container managed and also use CMR.
    The max-beans-in-cache is at its default of 1000. We reach this limit of 1000
    for about 10-15 of these beans in a day or two after a restart of the server.
    (This is production server, we restart this occasionally for maintenance). The
    memory usage for the server keeps increasing and once the entity cache limit is
    reached we see that passivation keeps occurring and the heap usage is always at
    about 80%-95% of the maximum (Total heap size is 1.5GB). We assume this could
    be due to the EntityBeans that are cached by WebLogic. We also see performance
    problems occassionally that might be probably due to the GC or passivation.
    We want to lower our memory usage and also get rid of the occassional slow response
    time. For doing this, is there any way to flush out those Beans from EntityCache
    which are no more used ? WebLogic doesn't seem to flush the cache but only passivate
    them as and when new beans are required. Is there any setting to change this behaviour
    Cheers
    Raja V.

    Thanks Thorick,
    We are using Database concurrency and non-read only beans, hence i believe this
    patch must help us.
    secondly, are you aware of any way to find out the memory usage of the default
    WLS Entity Bean Cache ?
    Cheers
    Raja
    "thorick" <[email protected]> wrote:
    >
    Hi,
    If you are using 'Database' concurrency, then support for an idle-timeout-seconds
    on this cache will be coming in release 7.0sp5. This feature is intended
    to ease
    heap usage when Entity Beans using Database/Optimistic/ReadOnly (but
    NOT Exclusive
    or read-only !). One sets the max-beans-in-cache to be large enough
    to handle
    periodic
    or occasional peak loads and idle-timeout-seconds is set to free the
    cache of
    unused beans
    during periods of low demand.
    If you cannot wait for sp5 and are willing to run a patch, there are
    patches available
    for
    7.0sp2 and 7.0sp3. You'll have to contact your support representative
    about
    these.
    Refer to 'CR110440' courtesy of yours truly !
    Hope this helps
    -thorick

  • EJB 3.0: CMP Entity bean from view

    Hi,
    I have created an entity bean from a database view.
    I don't have a good filed to use as id in my view. So I want to generate the id in my entity bean.
    How can I do this ?
    Thanks

    Hi,
    I didn't get your question.
    CMP is something, which can be done by hand.
    So maybe it is better, to do it manually.
    Bea has some workaround, I am sure.
    Maybe it is something with deployment descriptors, which
    have to be configured to the underlying database.
    Sorry for my stupid first answer.
    Volker.

  • 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) ?

  • Generating an Entity Bean from a Database Table

    I am following the tutorial "How Do I: Generate an Entity Bean from a Database
    Table?" and in that process doing the "Configuring a Data Source". This is the
    message I get when I configure a data source per the tutorial and click OK. This
    data source exists and the information is correct that I have supplied.
    Do I need to put the MS jars somewhere to enable this?
    See attached file

    I've just figured it out. An input source also takes a Reader in its constructor. I was thinking that it only took an InputStream, and as the Serializer requires you to set a Writer on it, I was finding it impossible to convert between bytes and chars. Now, I have simply set a blank CharArrayWriter on the Serializer, got a char[] from it once the Serializer has written the Document to the stream, and then constructed a CharArrayReader with this char[]. It works fine now. Not that anyone read the problem anyway cos I solved it a few minutes after I posted it. Considering it first cropped up about 4 months ago and it has been niggling ever since, I am pleased!

  • How to delete a database record by using EJB entity beans

    Hi, All,
    Does anyone know how to use entity bean to delete a database record? I have all the EJB entity beans created, including access beans to each. I can successfully create records, find and update records, however, I haven't find a way to delete records yet.
    Your response is appreciated.
    Cathy

    Please see EJB Forums for continue discussion on this subject.
    Reference titile: "how to delete database record by using CMP entity beans "

  • Entity Bean Rollback fails: caches are out of synch with the database

    We are encountering a critical issue where the rollback of a session transaction rolls back any database changes, but doesn't roll back bean changes in memory. When we next access the bean, it returns information that should have been rolled back. The memory cache is out of synch with the database.
    We have a simple session bean S, using container managed transactions. We also have an entity bean E using bean managed persistence. E has a single member <name>.
    We implement a method s() in S with <trans-attribute> Required as follows:
    public void s() {
    Context lookupContext = getLookupContext();
    SHome shome = (SHome) lookupContext.lookup(SHome.NAME);
    S s = shome.findByPrimaryKey(thePrimaryKey);
    System.out.println("-- current name = " + s.getName());
    s.setName("IGNORE");
    EJBContext ejbContext = (EJBContext) getContext();
    ejbContext.setRollbackOnly();
    Since this is BMP, the setName call issues our SQL update against the S record. When the session transaction rolls back, the database changes are also rolled back. But the entity bean in memory shows the modified name. We can see this in the next call to s() since the getName() returns IGNORE rather than the original value. We have also gotten debugged into the underlying instance cache associated with the S bean descriptor. I.e.
    AbstractEJBHome ejbHome = (AbstractEJBHome) lookupContext.lookup(SHome.NAME);
    AlternateHashTable aht = ejbHome.getBeanDescriptor().getCache();
    Looking at this map of bean instances also shows that the bean instance for S is not rolled back.
    From previous conversations with the server technologies team, we understand that during the transaction, we should be working on a cloned copy of the S bean. Upon rollback, the copies should be discarded rather than merged back to the cached bean. They seem to be merged regardless of rollback state.
    We are using OC4J 10.1.3.0.0 (build 060119.1546.05277).

    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.

  • How to mapping Entity beans to existing database tables.

    dear all
    how can i mapping Entity beans to existing database tables and not to create new table in Orion.
    thanks for any input.
    seabin

    * You define the name of the table that an Entity EJB maps to in orion-ejb-jar.xml. For eg:<entity-deployment name="MyEntityEJB" data-source="MyDS" table="MY_DB_TABLE" ...>* If you don't want to let Orion create the tables for your EJBs, have the following entry in either of the files given below:<orion-application autocreate-tables="false" ...>1) <orion-home>/j2ee/home/config/application.xml (global effect)
    2) orion-application.xml file of that particular application (application specific)
    HTH.

Maybe you are looking for

  • Permission error

    I'm at a complete loss here. I cannot get the TS finish properly. I get this error after it finishing applying the WIM: Installation of image 1 in package PS100117 failed to complete.. Permissions on the requested may be configured incorrectly.Access

  • Contact Pictures not displaying in texts...

    At some point yesterday my contact pictures has stopped showing up in text messages. They still appear when calls are placed and in the actual contact information, but no longer are in texts. I have restarted my phone and also shut it off for over an

  • How to implement custom Model Class in Oracle ADF?

    I am using Oracle ADF for one of my project and i am using Query component of ADF. For given tables the query component creates view objects and maps the relations. ADF uses its own custom model class for this component and it should understand the D

  • Greyed out songs show in itunes from ipad?

    I have itunes match enabled, I have no songs on my ipad, (I have deleted songs via Settings>Storage>Music>Clear all music) also tried turning itunes match on and off. So Im sure there are no songs on my ipad, yet when I connect my ipad to itunes, the

  • 1080p looks blur and unsharp

    I have a Samsung full-HD LCD together with my AppleTV on HDMI. When I switch to 1080p in AppleTV the picture looks much less sharp than with 1080i and 720p. When watching pictures synced from iPhoto, the quality even look better in 720p. When connect