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.

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 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.

  • 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]..
    >

  • 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

  • Order of fields in Primary key in where clause

    Hello,
    Does order of fields(complete primary key) in where condition matters with the performance or using of index ?
    Here is an example -
    BKPF has primary key - bukrs, gjahr, belnr.
    1. select single awkey into lv_awkey
      from bkpf where bukrs = p_bukrs
                  and gjahr = p_gjahr
                  and belnr = p_belnr.
    2. select single awkey into lv_awkey from bkpf
                                  where bukrs = p_bukrs and
                                            belnr = p_belnr and
                                            gjahr = p_gjahr.
    Does it make any difference in performance point of view with above two kinds ? Is that same applicable when accessing based on secondary index ?
    Thanks,
    Nagarjuna

    Hi Nagarjuna,
    the order of the fields does not influence the performance of the execution of the statements. This is true for primary key and secondary key accesses. In the statement cache (SAP and DB) two different statemens have to be maintained (parsing, space, ...) but their execution time is the same.
    Kind regards,
    Hermann

  • 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

  • Adding 2 new fields as Primary Key field in a Z Table which is existing PRD

    Hi Friends,
    I have to add two new fields as primary key fields in a Z TABLE, which is existing in Quality and Production Systems with Data.
    If I incorporate these two new fields (Primary Key fields) in development and if the TR is moved to Quality and Production sytems, is there any possibility of loss in data will happen at Quality and Prd systems?
    At present, Table is having 20 fields with 2 primary key fields and i have to add 2 more primary key fields.
    I have checked in SCN and not find relevant threads.
    Please help me out.
    Regards,
    Suresh.

    NO . It wont be a problem .
    For ex :
    If you have VBELN  , POSNR are key fields now , you have an unique reord with that combination .
    If you add one other field in it  fo ex  VKBUR  then records will be like this
    VBELN     POSNR     VKBUR   MATERIAL   QTY
    10020      10                            abcxyz      1
    10020      10            1234        abcxyz     1
    So your previous records before adding new primary keys , will have new fields balnk , and the new records will have data filled up in all primary key fields .
    However , if you try to update the existing records that will be in existing PRIMARYKEY combination only .
    for example if you try update record 1 above with VKBUR value 85858 , it creates a new record , it wont be updated in existing record.
    Hope this helps , Pls let me know if u have any more doubts.

  • How to Alter any table to make some fields Composite Primary Key

    I need to Alter Table to make some fields Composite Primary Key.
    Is it possible to do this ?
    Please give any example.
    Regards,
    AgrawalV

    Agrawal
    If you are looking for an example to create a composite primary key, here you are.
    sql> Alter Table myTable add constraint pk_myTable primary key(col1, col2, ...coln) ;
    where
    pk_myTable is the name of the primary key constraint,
    myTable is the name of the table that you want to create a constraint on and
    col1...coln are the column names in the table <myTable)

  • 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

  • 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.

  • Using Composite keys in Entity Beans

    Hi, I am trying to develop a test application with two entity beans, (1) OrderBean (key is a string called order_no) and (2) LineBean (key is order_no and an integer line_no) using CMP 2.0. Relationship between OrderBean to LineBean is 1 to many. I created a primary key class for LineBean called, LinePK with both order_no and line_no as the public members. My home interface for LineBean has the following three finder methods:
    public java.lang.Object findByPrimaryKey(LinePK lkey);
    public Collection findByOrder(String order_no);
    public Collection findByProduct(String product_id);
    I could provide sql for the OrderBean which has only one field(order_no) as primary key, but I don't know how to code appropriate SQL for the finder methods of LineBean involving a user defined primary key class (in my case LinePK with order_no and line_no). I am trying to deploy this application in J2EE RI server, but getting deployment errors saying invalid return types for the finder methods. In the deploytool I provided the primary key class for LineBean as java.lang.Object with no primary key field name. Any help in this matter with sample sql code is greatly appreciated. Thanks !!!

    Some things to consider:
    - Your findByPrimaryKey in the Remote interface needs to have the remote interface as return type
    - The implementation of the finder needs to have your primary key class as return type
    - If you're using CMP 2.0, you need to specify the search criteria as EJB QL
    Using CMP 2.0, you don't code findByPrimaryKey at all, all you need is the EJB QL for findByOrder/findByProduct in the deployment descriptor. The EJB QL for findByOrder would look like:
    select Object o from Line where o.order_no = ?1If you use BMP, you would code the findByPrimaryKey implementation like this:
    public LinePK ejbFindByPrimaryKey(LinePK pk) throws FinderException {
      String sql = "select order_no from line_table where line_no=? and order_no=?";
      InitialContext ic = new InitialContext();
      Object obj = ic.lookup("datasourcename");
      DataSource ds = (DataSource)PortableRemoteObject.narrow(obj, DataSource.class);
      Connection conn = ds.getConnection();
      try {
        PreparedStatement stmt = conn.prepareStatement(sql);
        try {
          stmt.setInteger(1, pk.line_no);
          stmt.setInteger(2, pk.order_no);
          ResultSet rs = stmt.executeQuery();
          if (!rs.next())
            throw new ObjectNotFoundException("not found: " + order_no + "." + line_no);
          return pk;
        finally {
          stmt.close();
      finally {
        conn.close();

  • Utilizing auto-increment/identity fields for primary key with "application" identity

    Is it possible to utilise an auto-increment (identity in MS SQL Server)
    field for the primary key field when using "application" identity?

    To the best of my knowledge, you cannot use auto-increment. Due to the
    differences in the way that identities are generated at the datastore
    (upon insert) vs. JDO (upon makePersistent), this feature of SQLServer is
    not supported yet.
    However, we do provide a variety of other ways of generating identity
    which may provide a closer fit to what you want, and
    our users may have some experience in solving your problem.
    On Tue, 28 Jan 2003 09:56:08 +0000, Sean Ryan wrote:
    Is it possible to utilise an auto-increment (identity in MS SQL Server)
    field for the primary key field when using "application" identity?--
    Stephen Kim
    [email protected]
    SolarMetric, Inc.
    http://www.solarmetric.com

  • How do you insert new records into multiple tables using the same unique primary key?

    I’ve created a PHP site and MySQL server using a free app called XAMPP.  I have successfully created a form in Dreamweaver that will write data to a (name) table in the SQL database.  Here’s my question: How do you write to two (or more) tables in the same database and pass the same primary key to both tables?  In the SQL database, I defined the first field as ID and set it as the primary key with auto update.  So, when you insert a new record, it creates a unique primary key for that record.  In my form, I’m capturing info that needs to be stored to two tables at the same time; a Name table and Address table. Since the Name and Address tables use the ID field as the primary key, I believe I will need to pass the ID value from the Name table to the insert of the Address table to insure they both have the same primary key, right?

    No. You probably need the primary key from one table to be a foreign key in the other tables. In any case, I believe you can use two methods to obtain the auto generated key. First with SQL:
    http://dev.mysql.com/doc/refman/5.0/en/getting-unique-id.html
    And the other using a PHP function:
    http://us3.php.net/mysql_insert_id

  • OC4J 9.0.4 Deadlock: CMR with composite primary key

    Hi,
    I just encountered a Deadlock in a CMR/CMP application involving a session bean and two entity beans, one of which (Item) has a composite primary key, comprising a foreign key to the second entity bean. The exception is thrown after ejbPostCreate() completes succesfully and the new row is committed to the ITEM table. I have provided the trace (verbosity = 10) below. The EJB Dev Guide does not offer too much detail on Deadlock conditions, so any input and suggestions are most welcome.
    regards and thanks
    George
    javax.ejb.EJBException: Deadlock detected: thread 8 thread 8state
    = thread 8
    id = 8
    thread = RMICallHandler-5
    user = [JAZNUserAdaptor: user=jazn.com/admin]
    runAsUser = null
    waitingState = null
    waitingForState = thread 8
    waitingForResource = Item server.ItemPK@bdc9b3
    notified = false
    interruptMessage = null
    rmiHandler = com.evermind.server.rmi.RMICallHandler@97617
    cmtConnections = null
    cmtConnectionCount = 0
    inDataSourceSensitiveRegion = false
    applicationThread.httpHandler = null
    contextContainer = OrderSB EJBHome
    transaction = null
    is waiting for resource entity Item server.ItemPK@bdc9b3 held by thread 8 thread 8state
    = thread 8
    id = 8
    thread = RMICallHandler-5
    user = [JAZNUserAdaptor: user=jazn.com/admin]
    runAsUser = null
    waitingState = null
    waitingForState = thread 8
    waitingForResource = Item server.ItemPK@bdc9b3
    notified = false
    interruptMessage = null
    rmiHandler = com.evermind.server.rmi.RMICallHandler@97617
    cmtConnections = null
    cmtConnectionCount = 0
    inDataSourceSensitiveRegion = false
    applicationThread.httpHandler = null
    contextContainer = OrderSB EJBHome
    transaction = null
    at com.evermind.server.ejb.AbstractEJBObject.startCallLocal(AbstractEJBObject.java:110)
    at ItemLocal_EntityBeanWrapper18.setNomen(ItemLocal_EntityBeanWrapper18.java:1912)
    at server.OrderSBBean.addItems(OrderSBBean.java:380)
    at OrderSB_StatelessSessionBeanWrapper2.addItems(OrderSB_StatelessSessionBeanWrapper2.java:1983)
    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:324)
    at com.evermind.server.rmi.RMICallHandler.run(RMICallHandler.java:124)
    at com.evermind.server.rmi.RMICallHandler.run(RMICallHandler.java:48)
    at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:192)
    at java.lang.Thread.run(Thread.java:536)

    Hi,
    I just encountered a Deadlock in a CMR/CMP application involving a session bean and two entity beans, one of which (Item) has a composite primary key, comprising a foreign key to the second entity bean. The exception is thrown after ejbPostCreate() completes succesfully and the new row is committed to the ITEM table. I have provided the trace (verbosity = 10) below. The EJB Dev Guide does not offer too much detail on Deadlock conditions, so any input and suggestions are most welcome.
    regards and thanks
    George
    javax.ejb.EJBException: Deadlock detected: thread 8 thread 8state
    = thread 8
    id = 8
    thread = RMICallHandler-5
    user = [JAZNUserAdaptor: user=jazn.com/admin]
    runAsUser = null
    waitingState = null
    waitingForState = thread 8
    waitingForResource = Item server.ItemPK@bdc9b3
    notified = false
    interruptMessage = null
    rmiHandler = com.evermind.server.rmi.RMICallHandler@97617
    cmtConnections = null
    cmtConnectionCount = 0
    inDataSourceSensitiveRegion = false
    applicationThread.httpHandler = null
    contextContainer = OrderSB EJBHome
    transaction = null
    is waiting for resource entity Item server.ItemPK@bdc9b3 held by thread 8 thread 8state
    = thread 8
    id = 8
    thread = RMICallHandler-5
    user = [JAZNUserAdaptor: user=jazn.com/admin]
    runAsUser = null
    waitingState = null
    waitingForState = thread 8
    waitingForResource = Item server.ItemPK@bdc9b3
    notified = false
    interruptMessage = null
    rmiHandler = com.evermind.server.rmi.RMICallHandler@97617
    cmtConnections = null
    cmtConnectionCount = 0
    inDataSourceSensitiveRegion = false
    applicationThread.httpHandler = null
    contextContainer = OrderSB EJBHome
    transaction = null
    at com.evermind.server.ejb.AbstractEJBObject.startCallLocal(AbstractEJBObject.java:110)
    at ItemLocal_EntityBeanWrapper18.setNomen(ItemLocal_EntityBeanWrapper18.java:1912)
    at server.OrderSBBean.addItems(OrderSBBean.java:380)
    at OrderSB_StatelessSessionBeanWrapper2.addItems(OrderSB_StatelessSessionBeanWrapper2.java:1983)
    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:324)
    at com.evermind.server.rmi.RMICallHandler.run(RMICallHandler.java:124)
    at com.evermind.server.rmi.RMICallHandler.run(RMICallHandler.java:48)
    at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:192)
    at java.lang.Thread.run(Thread.java:536)

Maybe you are looking for

  • Ora-3136 then ksvcreate: Process(m000) creation failed and db hangs

    Recently upgraded a large database from 10.2.0.4.0 to 10.2.0.5.0. The database recevies many thousand short-lived connections per minute. Since the upgrade we're repeatedly running into this problem Symptoms are that the incoming sessions will start

  • Days between job raised and completed variable

    Hi, im new to this website and semi new to Desktop intelligence. i have created a report that returns data by job number (i work at a housing association). the job number has 2 lots of data i am trying to interrogate, one is the time the job number w

  • Is there a way for merging a same apple ID with different store region

    Hi, I have a problem of seeing my previous purchased as I used 2 different stores under the same apple id. I was using a US credit card and address until my credit card expired and after that I have been using my local Indonesian credit card with a l

  • Print prview for goods issue

    hi all, how can i see the print preview for goods issue? regards, satheesh

  • I can't open video and picures files from cammera

    i can't open video and pictures files from PowerShot SD 780 IS DIGITAL ELPH Cammera how can i open video and pictures files from my Cammera, i need help!!!!! == This happened == Every time Firefox opened == Everytime