USE ROWID AS PRIMARY KEY OF ENTITY ON EJB3

When we launch the Create Entities from Tables wizard, and create JPA (Java Persistence API) entities from existing database tables, if the table has no primary key and unique key field, you will get a warning. When you run, you will get the following information:
Caused by: Exception [TOPLINK-7161] (Oracle TopLink Essentials - 2006.8 (Build 060829)): oracle.toplink.essentials.exceptions.ValidationException
Exception Description: Entity class [class model.Test] has no primary key specified. It should define either an @Id, @EmbeddedId or an @IdClass.
Actually, every row of oracle table has a ROWID field , I think it is a good “primary key field”. Add it into Entity Java bean file as following:
@Id
private ROWID rowid;
And generate accessors, ok, run……
GOOD, No problem.
But when you insert a new row, got an exception:
Exception [TOPLINK-4002] (Oracle TopLink Essentials - 2006.8 (Build 060829)): oracle.toplink.essentials.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: ORA-00928: missing SELECT keyword
Error Code: 928
Call:INSERT INTO TEST (ROWID, B, A) VALUES (?, ?, ?)
     bind => [null, 555, 555]
Query:InsertObjectQuery(model.Test@40979b)
555~~~, what happened?! Somebody builds a wrong SQL …
Don’t worry! I know (…) where is the “bug”.
Find out the class
oracle.toplink.essentials.internal.expressions. SQLInsertStatement
which is included in the toplink-essentials.jar,
decompile… , fix…, compile, and jar it back.
Fix
if(field.getTable().equals(getTable()) || !field.hasTableName())
to
if((field.getTable().equals(getTable()) || !field.hasTableName()) && !field.getName().equalsIgnoreCase("ROWID"))
OK, it is running well.
I suggest ORACLE fix it into his next version. Do you think it is a good idea?

Do you think it is a good idea? Not really, but that's just my two cents.

Similar Messages

  • Compund primary key in entity bean

    hi,
    can somebody please explain how to use the compound primary key in entity beans? i have got a database table, the key of which consists of three fields, which I assign as PK when setting up the entity bean. In turn I get a compoundPK class, but without get/set-methods - is it necessary to write own get/set-methods within this class?
    In the bean class itself I get a compundPK-create() method - but what is the use of it? actually, in my findByPK-method I need the PK already.
    Hints appreciated - btw, help.sap.com is not very helpful in this case...
    regards, matthias

    WebLogic Server supports mapping a cmr field to the primary key.

  • Primary key in Entity Objects. How?

    Hi!
    I'm using Jdeveloper 9.0.3.3. I have a table with primary keys: CliId and Id. I make an entity object and choose primary key option for Cliid and Id in the entity. Now i make an viewObject from the entity object. In the viewObject, there are 2 key attribute: Cliid and Id. Now i'm generating with Jdeveloper 9.0.3.3 a standard uix page and i want to update a record, but it doesn't works. I become a bc4j error message: 'begin insert into....'.
    In the UIX code i made the rowDef autocreate="true":
    <bc4j:viewObjectDef name="CnedViewUsage" rangeSize="1">
    <bc4j:rowDef autoCreate="true" "CurrentCnedViewUsage">
    <bc4j:propertyKey name="key">
    </bc4j:propertyKey>
    </bc4j:rowDef>
    </bc4j:viewObjectDef>
    so
    if the propertyKey can't catch bc4j rowkey form url, it makes a new row. There is the problem...why doesn't catch the the propertyKey the bc4j key form the url? If i check out CliId primary key from entity and key attribute from ViewObject, it begins to work.. But in the database they together are primray keys.. Has anyone an idea?
    Thanks: Gabz

    Does your ViewObject use more than one entity? If so, then the Key that you are using in the ViewObject probably contains the key attributes of each Entity. You can go to the attributes section of the ViewObject Wizard and click off any "Key" checkboxes for attributes that aren't a part of your "primary" Entity.
    Mark

  • Primary keys in entity beans

    I am creating an assignment for an EJB class that I am teaching. The assignment will ask students to create an entity bean to represent messages posted to an internet bulletin board. The fields in the entity bean are ID number, topic, user name, date, and the message. This bean will use container-managed persistence.
    The ID number of each message will be used for the primary key.
    The client will present the user with a simple menu (at the DOS prompt) with options to list all messages, search for messages, add messages, etc.
    When a new message is added, I don't want the user to have to enter a unique ID - it should be generated in the code somewhere.
    What I'm looking for is the absolute simplest way to get an ID for each new message. (I'm planning a series of assignments, each getting more complex, and this is the simplest one).
    I was thinking of having the client get a list of all the messages, make a list of all the IDs used, find the largest ID, and add 1.
    Can anyone suggest any other techniques? Thanks!
    -J

    Two approaches:
    you could initialize the db with one row and use some (any) number as the primary key
    then when adding a new row, access the last row in the db to get it's primary key and add 1 to it.
    You could also use date+time as a string, and assuming no one adds messages at the exact date+time, then it will work.
    To work around the problem of having two messages with identical date+time (assuming lots of messages coming through), you can catch the DB exception and resubmit the entry with an updated date+time. With very heavy traffic this will eventually fail. But for what you are doing it should work fine.
    Finally, you should not run into the identical problem unless you are using asynchronous message beans. I doubt you are, so the EJB container will handle it I suspect.

  • Identify columns to use as a primary key

    Good Afternoon,
    Is there a way using dynamic SQL to scan a table to identify the columns to use as the primary key?.
    Thank you in advance.
    Steve

    I converted
    Prashanth's query to dynamic sql:
    DECLARE @SQLString nvarchar(500)
    DECLARE @YourTableName nvarchar(128)
    SET @YourTableName = 'YourTableName'
    SET @SQLString =
    SELECT
    TAb.TABLE_NAME,
    Col.Column_Name,
    Constraint_Type
    from
    INFORMATION_SCHEMA.TABLE_CONSTRAINTS Tab,
    INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE Col
    WHERE
    Col.Constraint_Name = Tab.Constraint_Name
    AND Col.Table_Name = Tab.Table_Name
    AND Constraint_Type = ''PRIMARY KEY''
    AND Tab.Table_Name = ''' + @YourTableName + '''
    --PRINT @SQLString
    EXECUTE sp_executesql @SQLString
    GO
    A Fan of SSIS, SSRS and SSAS
    Didnt understand why you need to make it dynamic here
    There's nothing which requires the query to be dynamic as per the above
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • Using CMR field as Primary Key in Entity Bean

    Hi, all!
    Can somebody tell me, is it possible to use CMR field as Primary Key field in Entity Bean?
    Thanks

    WebLogic Server supports mapping a cmr field to the primary key.

  • Primary key in Entity beans

    Hi
    If my database doesn't have primary key, then how can I define ejbFindByPrimarykey
    method in Entity Beans. ? or in that case can't I use Entity beans. ?
    Pls clear my doubt.
    Thanks in advance

    Ashish,
    If my database doesn't have primary key, then how can I defineejbFindByPrimarykey
    method in Entity Beans. ? or in that case can't I use Entity beans. ?An entity bean instance needs to be uniquely identifiable. That doesn't
    necessarily mean that you have a PK in the database, but those two things do
    usually go together.
    Peace,
    Cameron Purdy
    Tangosol, Inc.
    Clustering Weblogic? You're either using Coherence, or you should be!
    Download a Tangosol Coherence eval today at http://www.tangosol.com/
    "Ashish Mangla" <[email protected]> wrote in message
    news:3cf5b304$[email protected]..
    >

  • Fast Refresh using two non-primary key tables

    Hi,
    I have a materialized view based on two tables with an outer join clause. Both the tables do not have a primary key so I had created materialized view log with row-id on each of them but still I am not able to bring out the fast refresh option for the materialized view. My question is can I have a fast refresh option for materialized view built from two tables without primary keys and having an outer join clause????. If possible please send me some sample scripts for quicker understanding.
    Thanks and Regards,
    Sudhakar

    I was able to create a fast-refreshable MV, on tables without any PK. Unfortunately, I can't complete all the steps since my setup is a multi-master advanced replication (which ABSOLUTELY requires the tables to have PK's). Here are anyway the steps I took. Note that ORA102 is my (definition) master site, and MVDB is my MV site. The tables were created under user HR, and my master group is called "hr_repg". Here are my steps:
    HR on ora102 >create table countries_no_pk as select * from countries;
    Table created.
    HR on ora102 >create table regions_no_pk as select * from regions;
    Table created.
    HR on ora102 >create materialized view log on countries_no_pk with rowid;
    Materialized view log created.
    HR on ora102 >create materialized view log on regions_no_pk with rowid;
    Materialized view log created.
    REPADMIN on ora102 >exec dbms_repcat.suspend_master_activity('hr_repg')
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:02.68
    REPADMIN on ora102 >BEGIN
    2 DBMS_REPCAT.CREATE_MASTER_REPOBJECT (
    3 gname => 'hr_repg',
    4 type => 'TABLE',
    5 oname => 'countries_no_pk',
    6 sname => 'hr',
    7 use_existing_object => TRUE,
    8 copy_rows => FALSE);
    9 END;
    10 /
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:05.19
    REPADMIN on ora102 >set timing off
    REPADMIN on ora102 >BEGIN
    2 DBMS_REPCAT.CREATE_MASTER_REPOBJECT (
    3 gname => 'hr_repg',
    4 type => 'TABLE',
    5 oname => 'regions_no_pk',
    6 sname => 'hr',
    7 use_existing_object => TRUE,
    8 copy_rows => FALSE);
    9 END;
    10 /
    PL/SQL procedure successfully completed.
    (note that you ABSOLUTELY need the rowid's in your select statement for an MV with joins):
    MVIEWADMIN on mvdb >CREATE MATERIALIZED VIEW hr.complex_mv refresh fast as
    2 select c.rowid "C_ROW_ID", r.rowid "R_ROW_ID", c.COUNTRY_ID, c.COUNTRY_NAME,
    3 c.REGION_ID, r.REGION_NAME from hr.regions_no_pk@ora102 r, hr.countries_no_pk@ora102 c
    4 where c.region_id = r.region_id (+);
    Materialized view created.
    MVIEWADMIN on mvdb >BEGIN
    2 DBMS_REPCAT.CREATE_MVIEW_REPOBJECT (
    3 gname => 'hr_repg',
    4 sname => 'hr',
    5 oname => 'complex_mv',
    6 type => 'SNAPSHOT',
    7 min_communication => TRUE);
    8 END;
    9 /
    PL/SQL procedure successfully completed.
    REPADMIN on ora102 >BEGIN
    2 DBMS_REPCAT.GENERATE_REPLICATION_SUPPORT (
    3 sname => 'hr',
    4 oname => 'countries_no_pk',
    5 type => 'TABLE',
    6 min_communication => TRUE);
    7 END;
    8 /
    PL/SQL procedure successfully completed.
    (wait when the entries in DBA_REPCATLOG is empty)
    REPADMIN on ora102 >exec dbms_repcat.resume_master_activity('hr_repg')
    Hope that can help you. If that doesn't work, tell us where it bombs.
    Daniel

  • Use of custom primary key using OSM Activation Tasks

    Hi,
    We are using OSM Activations Task to interact with ASAP. By default it uses OSM_ORDER_ID.HIST_ID as the corelation key and same as primary key while sending the request to ASAP. Is there a way we can customize this logic so as to send a custom value as the primary key to ASAP.

    Navid,
    A dropdown list can have only one value, so this is not possible. As a (dirty) work around you could introduce a transient attribute that concatenates the two PK values with for example a dash separating the two values, and base your drop down list on this transient attribute. In the setter method of this attribute you can then extract the two values and call the setters of the two PK attrs.
    Steven Davelaar,
    JHeadstart Team.

  • Retrieving auto inc primary key from entity bean (MySQL DB)

    Hello,
    I searched the forum intensively, but did not find an answer for the following problem.
    I've set up an MySQL database "Location" with two fields (ID, Description), ID is my primary key and I've added the AUTO_INCREMENT flag to this field. This works fine, i can add a row in the table with my entity bean "Location" from my session bean :
    Location l = new Location();
    l.setDescription("at home");
    em.persist(l);
    and even when I ask this location back from the DB, there is no problem :
    Location l = em.find(Location.class,1);
    return l.getDescription();
    The rows in the table increment nicely. The problem however is, that you don't allways know the ID. So I would like to do the following from my session bean:
    Location l = new Location();
    l.setDescription("at home");
    em.persist(l);
    int id = l.getId();
    the getID method allways returns a null object. The row is added in the DB, but the auto incremented ID is not returned to the entity bean!
    I know I could solve this by generating the ID's myself, but one of the strengths of autoincrement should be not to have to do this, no?
    If anyone has a clue how to solve this issue, I would very much appreciate it !
    Michiel
    Edited by: Michiel82 on Dec 6, 2007 6:01 AM

    No reactions so far ... this is a work-around for the issue :
    I've created an additional table sequence with two fields: gen_key and gen_value. Then, in my Location entity bean I can add the following:
    @TableGenerator(
    name="locationGen",
    table="sequence",
    pkColumnName="gen_key",
    valueColumnName="gen_value",
    pkColumnValue="location",
    allocationSize=1
    @Id
    @GeneratedValue(strategy=GenerationType.TABLE,generator="locationGen")
    @Column(name = "id", nullable=false)
    private Short id;
    This generates the primary key in the bussiness logic, but I would like to get the autogenerated key from my MySQL database (see previous post). Is this perhaps not supported by EJB3.0?
    Michiel

  • Primary Key on Entity Object

    Hello
    I create an entity object based on a view manually (not via the wizard)BC$J. I choose a primary key to complete the operation. I created a UIX page which display 5 records at a time. It turned out that the Primary key a chose was not a primary key and the page displayed with an error indicating that there are duplicate matches. Does this mean that the BC4J is checking the entire table for duplication? In my Page, i was about to invoke the search page as the first page to force the user to enter a criteria which when entered will cause only one record to be retrieved. BC4J seems to be executing the query and checking for the duplication before even allowing the search page to appear. The Search page is the first page that appears in my application (managed to skip forcing the initial table to be rendered with rows)
    Is there a way to stop OC4J from executing and checking before i display the Search Page.
    Thanks
    Ammar

    BC4J do not check the entire table for duplication. We retrieve rows as requested by the client app and if a duplicate PK is found as rows are retrieved, we will throw an exception.
    Thanks.
    Sung

  • Query not using remote table primary key.

    Hello all,
    My following query is not using the PK of remote database. vem_business_event_attribute is having a PK on ATTRIBUTE_TYPE_ID and business_event_id. The table is last analyzed on 04-dec-2010. It has around 5 milloin rows.
    select /*+ DRIVING_SITE(ve) */
    ve.ATTRIBUTE_TYPE_ID ,
    ve.BUSINESS_EVENT_ID ,
    ve.ATTRIBUTE_VALUE ,
    ve.ATTRIBUTE_AS_NUMBER
    from
    vem_business_event_attribute@hello ve,
    vem_attribute_types@hello va,
    delta_insert_businessevent de
    where
         ve.ATTRIBUTE_TYPE_ID = va.ATTRIBUTE_TYPE_ID
    ve.business_event_id = de.business_event_id
         and de.business_event_id < 90000000;
    Pls help.
    Regards

    If you need to move 150 million rows from one database to another, it is going to take some time, and a full scan would definitely be the most efficient sql way to do it. I would be surprised if 15 inserts of 10 million rows each would be faster than a single insert of 150 million rows.
    Depending on your exact requirements, it might be faster to use datapump to export the rows from the remote database and import them on the local database, but you will still be moving those 150 million rows across the network. You might get some advantage from the export/ftp/import option if you compress the dump file before the ftp, and uncompress it on the target, but that would depend on the additional time required to compress and uncompress.
    John

  • Unable to Create Insert page in OAF Using ROWID as primaryKey

    I have Taken RowID as primary Key in Entity Creation.I written following Code as follow in Process Request method
    OAViewObject vo=(OAViewObject)am.findviewObject("VONAME');
    if(!vo.ispreparedforexecution)
    vo.executequery();
    Row row=vo.createRow();
    vo.insertRow(row);
    row.setNewRowstate(Row.STATUS_ INITIALIZED);
    but
    i am getting an error like Entity Create Row Exception

    Hi,
    sorry, wrong forum. This is all about Oracle JDeveloper. OAF related questions are handled on the OAF forum
    Frank

  • How do I use Primary Key and RowID in Materialized View Logs and MVs

    How do I use Primary Key and RowID in Materialized View Logs and Materialized Views????
    I don’t understand in the Materalized View Logs the diference between Primary Key and RowID. Besides, I could choose both Primary Key and RowID.
    When I have to use RowID?? Why?? And Primary Key??? And both, Primary Key and RowID????
    Thank you very much!

    Yes, I have already read it...
    But for example I don’t Understand:
    This is the example 8-1
    CREATE MATERIALIZED VIEW LOG ON products
    WITH SEQUENCE, ROWID
    (prod_id, prod_name, prod_desc, prod_subcategory, prod_subcat_desc, prod_
    category, prod_cat_desc, prod_weight_class, prod_unit_of_measure, prod_pack_
    size, supplier_id, prod_status, prod_list_price, prod_min_price)
    INCLUDING NEW VALUES;
    But if I create a Materialized View with TOAD if I choose a KEY field I receive the error:
    ORA-12026: invalid filter column detected
    Then I have to take out the Key (in the above example prod_id)
    And then the script is
    CREATE MATERIALIZED VIEW LOG ON products
    WITH ROWID, SEQUENCE, PRIMARY KEY!!!!!!!!!!!!!!!!!!!!
    (prod_id, prod_name, prod_desc, prod_subcategory, prod_subcat_desc, prod_
    category, prod_cat_desc, prod_weight_class, prod_unit_of_measure, prod_pack_
    size, supplier_id, prod_status, prod_list_price, prod_min_price)
    INCLUDING NEW VALUES;
    I have PRIMARY KEY in the definition (I don’t choose it) and I don’t have the prod_id field
    Why is it????
    Note: If I execute the script to create the MV Log manually the PRIMARY KEY option NO IS in the script and the prod_id field either is in the script.
    And on the other hand,
    What is this:
    CREATE MATERIALIZED VIEW LOG ON sales
    WITH ROWID;
    CREATE MATERIALIZED VIEW LOG ON times
    WITH ROWID;
    CREATE MATERIALIZED VIEW LOG ON customers
    WITH ROWID;
    These MATERIALIZED VIEW LOG contain any fields????
    Or it contain the primary key fields of this tables (sales, times and customers)??? Then, Why is it ROWID instead of PRIMARY KEY????
    Thanks!

  • CMP entity bean with compound primary key

    I'm trying to use a compound primary key in a CMP entity bean. I've created the custom primary key class okay, and I have the prim-key-class set in ejb-jar.xml. My client app gets the home reference okay, but when it tries to find an entity, I get the exception "SQLException: Incorrect syntax near '/'."
    I think I'm having trouble deploying this in OC4J. Is there a sample orion-ejb-jar.xml deployment for a custom, compound primary key somewhere?
    Many thanks for any help.
    Ernie

    Never mind. I solved my problem. Thanks.

Maybe you are looking for

  • Cleared Items Interest Calculation on Customers

    Hi, Following is the Requirement. On 01.04.08 1. Creating a Credit Memo in FB75.                    Misc Deposit A/c Dr..                               To Customer A/c 2. Clearing Customer in f-31                    Customer A/c -Dr ..               

  • Bug with speakers

    I just bought my Z3 and there's a problem with the speakers, when I get a notification the volume gets lower and when I'm a on whatsapp while I have music playing the volume gets lower too and I dont know **bleep** to fix it, any suggestions?

  • Setting Namespace for Xalan

    I'm using JAXP 1.2 I have a custom sax parser (implements XMLReader) that reads csv files then sends SAX events to a stylesheet for translation. My problem is that Xalan requires a namespace-aware SAX parser. The SAXParserFactory has a method (setNam

  • Deadlocking issue with sshfs and nfs

    Okay, I've used both sshfs and nfs for remotely accessing the home partition on my fileserver, but I have been having a problem where the networking on the server suddenly cuts out.  Any processes that are accessing the folder I mounted nfs/sshfs wit

  • Mac Pro RAID 5 not rebuilding after replacing a failed drive?

    I have a Raid 5 on a Mac Pro and one of the three drives failed. The RAID set was degraded so I replaced the drive and made it a global spare. At this point the Raid Utility is supposed to try and rebuild the RAID array but nothing happens. Any help?