HOW TO  GET COUNT IN OF COMPOSITE PRIMARY KEYS USING ECLIPSELINK

Hi all,
We are currently migrating our application form oracle 10g to 11 g and hence migrating from toplink to eclipselink.
we are unable to fire the count query and getting the following exception ...
Error Code: 909
Call: SELECT COUNT() FROM T_USER_MESSAGE t0, T_USER t2, T_MESSAGE_RECIPIENT t1 WHERE ((((t2.PERSISTENT_ID = ?) AND (t2.SITE_CODE = ?)) AND (t1.DELETED_BY_RECIPIENT = ?)) AND (((t2.PERSISTENT_ID = t1.RECIPIENT_ID) AND (t2.SITE_CODE = t1.RECIPIENT_SITE)) AND ((t0.PERSISTENT_ID = t1.MESSAGE_ID) AND (t0.SITE_CODE = t1.MESSAGE_SITE))))
     bind => [13398610, 1, F]
please advise .
we suspect that this could be because of the composite primary key in one of the tables .
any pointers to specify how count(*) could be used in this scenario would be of great help ..
Thanks in advance

What is the query being used, include the JPQL/expression code.
What is the error message (I assume this is a database error?).
What version are you using, can you try the latest EclipseLink 2.1 release.
James : http://www.eclipselink.org

Similar Messages

  • Composite Primary Key using  cmp

    How can an Entity Bean with Composite Primary Key using Container Managed Persistance (CMP) be Deployed using in WebLogic Server 8.1
    pls help me

    Your text is a bit confusing, but I think the answer is yes (it can be used).  However, it would help to see the DDL that you are using (or that you propose to use) to avoid any misunderstandings. And please be specific about whether you are referring
    to COLUMNS that are part of a primary key versus the primary key itself (whether it is composed of one column or multiple columns).
    Lastly, why not just try it and see.

  • How to persist an entity with Composite primary key

    Problem Statement:-
    Entity A have many to one relation with Entity C
    Entity B have many to one relation with Entity C
    Entity C have a composite primary key of (Entity A PK & Entity B PK)
    A --< C
    B --< C
    the entites are automatic generated by Dali tool
    @Entity
    public class C implements Serializable
         @EmbeddedId
         private C.PK pk;
         private int attribute;
         //Code
         @Embeddable
         public static class PK implements Serializable
              public int A_Id;
              public int B_Id;
              //Code
    @Entity
    public class A implements Serializable
         @Id
         private int AId;
         @OneToMany
         private Set<C> C_Collection;
         //Code
    @Entity
    public class B implements Serializable
         @Id
         private int BId;
         @OneToMany
         private Set<C> C_Collection;
         //Code
    i made a session Bean which add a new entity C
    Session
         A a = em.find(A.class, AId);
         B b = em.find(B.class, BId);
         C c = new C();
         C.PK pk = new C.PK();
         pk.AId(a.getID());
         pk.BId(b.getID());
         c.setPk(pk);
         c.setA(a);
         c.setB(b);
         c.setAttribute(12);
         em.persist(c);
    when running this code an exception is raised
    Exception [TOPLINK-4002] (Oracle TopLink Essentials - 2006.8 (Build 060830)): oracle.toplink.essentials.exceptions.DatabaseException
    Internal Exception: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Unknown column 'A_ID' in 'field list'Error Code: 1054
    Call:INSERT INTO C (attribute, Aid, A_ID, B_ID, Bid) VALUES (?, ?, ?, ?, ?)
         bind => [2, 6, 6, 1, 1]
    this is logic as Table "C" has only 3 coloumns only "attribute" , "Aid" , "Bid"
    but the mapping is different as it adds the composite PK attributes to the insert statement
    if there is a sample code or how to solve this issue it would be great

    Hello Juwen,
    The problem is you are registering an object, assigning it a null pk, and then commiting the uow/transaction. TopLink uses registered objects to keep track of changes you make inorder to persist those changes on commit. So the simple fix is to not commit the UnitOfWork - call release() on it instead.
    Another solution is to use the session copyObject api. The simple form that only takes an object will work similar to registering the object as it will copy all persistent attributes but it will leave the primary key null. You can also use this method to specify a copyPolicy to customize the process. Using this method will be a bit more efficient, since a UOW makes both a working copy and a back up copy of objects registered, inorder to keep track of changes. Using the copyObject api will only make a single copy.
    Best Regards,
    Chris

  • How to get the auto increment integer primary key value of a new record

    I have a DB table that has a auto increment integer primary key, if I insert a new record into it by SQL statement "INSERT INTO...", how can I get the integer primary key value of that newly created record?

    Well maybe someone knows a better method, but one workaround would be to add a dummy field to your table. When a new record is inserted this dummy field will be null. Then you can select your record with SELECT keyField FROM yourTable WHERE dummyField IS NULL. Once you've got the key number, you then update the record with a non-null value in the dummyField. Bit of a bodge, but it should work...
    Another alternative is, instead of using an Autonumbered key field, you could assign your own number by getting the MAX value of the existing keys (with SELECT MAX(keyField) FROM yourTable) and using that number + 1 for your new key. Might be a problem if you have lots of records and frequent deletions though.

  • How to Work with Composite Primary Key

    Hi All,
    I'm working with Toplink JPA. Here I have A problem with inserting into database table which have composite Primary Key.
    What I'm doing is, I have two tables. to maintain many to many relation between these two tables I created another intermediate table which consists of foreign Keys (reference) of above two tables.
    Now these two foreign Keys in the Intermediate table made as composite Primary Keys.
    When I'm trying to the data in the Intermediate table I'm getting the foreign Keys values are null..
    could anyone suggest me how to work with composite Primary Keys
    Thanks,
    Satish

    I have the same problem, I have 3 tables with a join table joining them all. I have created an intermediate table entity. When I go to create a an entry, it says that I cannot enter null into "ID". Here is the SQl toplink generates:
    INSERT INTO Z_AUTH_USER_AUTHORIZATION (CONTEXT_ID, AUTHORIZATION_ID, USER_ID) VALUES (?, ?, ?)
    bind => [null, null, null]
    Here are the classes:
    -----------------------Join Table-----------------------------------------------
    @Entity()
    @Table(name = "Z_AUTH_USER_AUTHORIZATION")
    public class AuthUserAuthorization implements Serializable{
    @EmbeddedId
    private AuthUserAuthorizationPK compId;
    // bi-directional many-to-one association to AuthAuthorization
    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "AUTHORIZATION_ID", referencedColumnName = "ID", nullable = false, insertable = false, updatable = false)
    private AuthAuthorization authAuthorization;
    // bi-directional many-to-one association to AuthContext
    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "CONTEXT_ID", referencedColumnName = "ID", nullable = false, insertable = false, updatable = false)
    private AuthContext authContext;
    // bi-directional many-to-one association to AuthUser
    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "USER_ID", referencedColumnName = "ID", nullable = false, insertable = false, updatable = false)
    private AuthUser authUser;
    ---------------------------------------User table--------------------------------------------------------------
    @Entity()
    @Table(name = "Z_AUTH_USER")
    public class AuthUser implements Serializable, IUser{
    @Id()
    @SequenceGenerator(name = "AUTH_USER_ID_SEQ", sequenceName = "Z_AUTH_USER_ID_SEQ")
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "AUTH_USER_ID_SEQ")
    @Column(name = "ID", unique = true, nullable = false, precision = 10)
    private Integer id;
    // bi-directional many-to-one association to AuthUserAuthorization
    @OneToMany(mappedBy = "authUser", fetch = FetchType.EAGER)
    private java.util.Set<AuthUserAuthorization> authUserAuthorizations;
    -----------------------------------Context table-----------------------------------------------------------------
    @Entity()
    @Table(name = "Z_AUTH_CONTEXT")
    public class AuthContext implements Serializable, IContext{
    @Id()
    @SequenceGenerator(name = "AUTH_CONTEXT_ID_SEQ", sequenceName = "Z_AUTH_CONTEXT_ID_SEQ")
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "AUTH_CONTEXT_ID_SEQ")
    @Column(name = "ID", unique = true, nullable = false, precision = 8)
    private Integer id;
    // bi-directional many-to-one association to AuthUserAuthorization
    @OneToMany(mappedBy = "authContext", fetch = FetchType.EAGER)
    private java.util.Set<AuthUserAuthorization> authUserAuthorizations;
    ----------------------------Authorization table-------------------------------------------------
    @Entity()
    @Table(name = "Z_AUTH_AUTHORIZATION")
    public class AuthAuthorization implements Serializable, IAuthorization{
    @Id()
    @SequenceGenerator(name = "AUTH_AUTHORIZATION_ID_SEQ", sequenceName = "Z_AUTH_AUTHORIZATION_ID_SEQ")
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "AUTH_AUTHORIZATION_ID_SEQ")
    @Column(name = "ID", unique = true, nullable = false, precision = 8)
    private Integer id;
    // bi-directional many-to-one association to AuthUserAuthorization
    @OneToMany(mappedBy = "authAuthorization", fetch = FetchType.EAGER)
    private java.util.Set<AuthUserAuthorization> authUserAuthorizations;
    I have tried to create the new entity several ways. I have tried to create one with the default constructor then set this entity on each of the other entities, I have also tried to pass in the entities to the join entity and set them there, but this doesn't work. Any help would be very appreciated!
    Thanks,
    Bill

  • How to define Composite primary key for a Table

    Hi ,
    I am basically more into Java Programming , with little bit knowledge on Oracle as DataBase .so please excuse for my silly doubts .
    Can anybody please tell me how to define a Composite Primary Key on a Table .
    Thanks in advance .
    Edited by: user672373773 on Sep 25, 2009 8:54 AM

    Here is an example right out of the Oracle documentation and the syntax for adding PK since you mention adding a composite PK.
    Example creating composite index
    http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14251/adfns_indexing.htm#sthref594
    Syntax for adding a PK (composite or not)
    alter table oooooooo.tttttttt
    add constraint tttttttt_PK
    primary key (sample_column2,
    sample_column1)
    using index
    tablespace IDXSPC
    pctfree 05
    initrans 04
    maxtrans 08
    storage (initial 16k
    next 16k
    maxextents 32
    pctincrease 0);
    -- dictionary management with restricted storage, change as desired.
    HTH -- Mark D Powell --

  • How to get count of rows for a table?

    Hi,
    How to get count of rows for a table and secondly, how can i have access to a particular cell in a table?
    Regards,
    Devashish

    Hi Devashish,
    WdContext.node<Your_node_name>().size() will give you the no: of rows.
    This should be the node that is bound to the table's datasource property.
    WdContext.node<Your_node_name>().get<node_name>ElementAt(index_value); will select the row at that particular index.
    You can access an attribute of a particular row as
    WdContext.node<Your_node_name>().get<node_name>ElementAt(index_value).get<attribute_name>();
    Hope this helps,
    Best Regards,
    Nibu.
    Message was edited by: Nibu Wilson

  • How to get count,index and compare to arraylists

    hi
    how to get count,index and comparing of 2 arraylist.... plz suggest me asap...

    How is your question related to JDBC? And what have you done so far with your code?

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

  • Querying on the basis of some attribute of composite primary key

    Hello,
    I am looking for suggestion about querying just on the basis of one attribute of the composite primary key.
    TO exemplify,
    I have a 6 attributes example A1,A2,A3,A4,A5,A6.
    A1,A2 and A3 together, serve as composite primary key.Now,because of the need of the project,I want to do querying on the basis of any A1,A2 or A3.One way I could think of is to have secondary indices on each of A1,A2,A3.
    Can some one explain me roughly how to go about it?
    I am a new user of BerkeleyDB Java Edition,hence not sure what would be a good way to do it.I understand one way to do it,would be to keep A1,A2,A3 in the Key class and A1,A2,A3,A4,A5,A6 in the value class as well.Then create secondary indices on the A1,A2 and A3 individually.
    Can someone suggest a more efficient way?
    Thanks,
    Will appreciate any suggestions.
    Prateek

    Exactly as you said. Create secondary indices on each attribute you want to index off of. I don't use the Java interface, but what you pretty much need to do is form your secondary key like so:
    skey: pkey_individual_attribute
    skeysize: pkey_individual_attribute_sizeHow to do this is documented in the BDB Java API docs:
    For example:
        class MyKeyCreator implements SecondaryKeyCreator {
            public boolean createSecondaryKey(SecondaryDatabase secondary,
                                                DatabaseEntry key,
                                                DatabaseEntry data,
                                                DatabaseEntry result)
                throws DatabaseException {
                // DO HERE: Extract the secondary key from the primary key and
                // data, and set the secondary key into the result parameter.
                return true;
        SecondaryConfig secConfig = new SecondaryConfig();
        secConfig.setKeyCreator(new MyKeyCreator());
        // Now pass secConfig to Environment.openSecondaryDatabaseThe extractor function used to construct the secondary index is passed the primary key and primary data - therefore all the data is available to you with no need to duplicate the key within the data itself. While the standard example is to use some part of the primary data to form a secondary key - there's absolutely nothing against using only a part of the primary key to form a secondary key instead. The only thing you have to do is slice up said primary key and construct the "result" parameter to be a single attribute. The backend API already knows which composite key this secondary entry will be associated with and as such will implicitly form the data (or as you called it "value") section of the index (which will be the composite primary key passed to it).
    The primary key/data should consist of the composite A1,A2,A3 with only A4,A5,A6 as data.
    The secondary->get() call (within the Java API) takes a key and provides back the primary key and primary data (basically the same as the db->pget() call in the C API). Since you've already indexed individual attributes, based off of the composite key, into their own respective databases - you just query from one of your secondary indexes with whatever specific attribute as the key. You then use the filled in primary key and primary data to work off of.

  • Composite Primary key & Primary key questions

    Background:
    1.5 TB data warehouse. All tables use at least a 3 column composite Primary key. Most use 3. col1||col2||col3 to achieve uniqueness.
    col1= very low cardinality. 99% of the values are '0'
    col2 = high cardinality. (SSN's, loaded monthly)
    col3 = low cardinality. (monthly sequence number used for partitioning)
    From what I've read, the first column used in a composite primary key also receives its own index. If that is correct, then the primary key being used is losing its effectiveness by putting a very low cardinality column as the first column of the Primary key. By moving col2 to the first position of the composite key, I would be obtaining an index on SSN which would be much more useful. (Please correct me if I'm wrong) Or since the index would be so large anyway, the CBO would just do full table scans which is what I'm trying to get away from.
    This Primary key is used to ensure uniqueness during loads. Other than that, it really has no purpose and is never queried by the user. (WHERE col1||col2||col3 = xxxxxxxxx)
    As a DBA, I see this massive tablespace for holding the primary keys now reaching in excess of 157 GB and it seems like such a waste of space. The problem I'm running across is how to ensure uniqueness during the loads w/o having to store the unique values. (the 157 GB) If I drop the PK's, then create unique indexes just for the loads, then the unique index would be generated against the entire table, which would take forever.
    If you create a local index (what I want in the end) it still has to create the index for all previous partitions (250+ partitions). You can't create a specific 'local' index on a partition. You create a local index on the table and when a new partition is added, the index is then added as well. That's what I want to do with some of my fields like SSN but for loading purposes, this isn't going to help me.
    I need a way to ensure uniqueness during a monthly load of a new partition (col1||col2||col3) but w/o having to store these values for eternity. Right now it's the primary key, so it has to be stored. I hope I'm making sense here. Any ideas?

    I think you need some clarification about the index supporting the primary key.
    The primary key is unique - the database will enforce this for you.
    All of the columns in the primary key are in the index that enforces the key (not just the first column).
    Usually this index is a unique index, but you can have a non-unique index supporting a primary key.
    I'm a little confused with some of your other statements
    how to ensure uniqueness during the loads w/o having to store the unique valuesIf you don't store the value how do you know it is unique?
    Did you mean that you don't want to store the key values in both the table and the index?
    You may want to consider making col3 (the partition key) the leading column of the index, so you can create a local (instead of global) PK index.
    I wouldn't worry too much about col1 (the column full of mostly zeros) - numbers are stored variable length. A NUMBER(38) that holds a zero takes no more space than a NUMBER(1) that holds a zero.

  • Deployment Tool Problem (J2EE -Composite primary Key Class)

    Hi !!
    e.g. I have an entiybean which has composite primary key class. So while deploying in J2EE tool u need to specify the Primary key class and the primary key field. well in case of a composite primary key class(if u have more than one field)...how do u declare all the fields for primary key class....
    if u r not getting me please tell me... See in J2EE deployment tool there is on section called Entity..in that see the Primary Key class (there u specify the Primary key class) and the Primary Key Field Name (the field name) Here u can just give only one Field name..if you have mulitple fields, then where you will specify... Please let me know..
    if anybody wants the code I will give the code...Please try to help..(how to deploy this kind of entity bean in J2EE deployment tool)
    -Bhumika

    Hi Bhumika,
    in case you have more than one field you need to write a Primary key class where the fields you want to be the key are member variables.
    your p.key class could look like this (it has to implement hash() and equals() ):
    public class PersonPK implements java.io.Serializable
    public int person_ID;
    public PersonPK()
    public PersonPK(int aPersonId)
    person_ID = aPersonId;
    public int hashCode()
    return person_ID;
    public boolean equals(Object ob)
    if (ob == this) return true;
    if (!(ob instanceof PersonPK)) return false;
    PersonPK other = (PersonPK) ob;
    if (person_ID != other.person_ID) return false;
    return true;
    -Hope this helps a bit,
    Anke

  • Reconciling composite primary key tables in 9.0.1.4 DB app connector

    Hi
    I am trying to get the reconciliation in the 9.0.1.4 db app connector to work on a view that has a composite primary key (one user_id field and one group_id field)
    There are no examples on how to do this and my "trial-and-error" efforts have not been fruitful this far. Anyone that has any experience of how to solve this problem?
    Best regards
    /Martin

    Hi Martin, our customer is also very sensitive to changes in his HR system, it is a custom oracle development. He provide us a read only view every day with all changes on their identities. We have developed a custom pl/sql proccess to fill a custom local table with the right information . Then we use this table locally with dbtable connector but with some custom addons.
    So i believe that using a second table and keep in synch it is the best approach.
    We have detect some problem with 9.0.1.4 DB app connector, it is using internally only one db connection for all its operations, in a huge load condition its can produce errors and race condition problems. We have a custom connector now and it is using connection pool from application server so we will have not this problem.
    I believe that oracle should release source for their connectors, i am very sure that partners and customers can improve it.

  • Error While Deploying A CMP Entity Bean With A Composite Primary Key

    Hello all,
    I have a problem deploying CMP Entity beans with composite primary keys. I have a CMP Entity Bean, which contains a composite primary key composed of two local stubs. If you know more about this please respond to my post on the EJB forum (subject: CMP Bean Local Stub as a Field of a Primary Key Class).
    In the mean time, can you please tell me what following error message means and how to resolve it? From what I understand it might be a problem with Sun ONE AS 7, but I would like to make sure it's not me doing something wrong.
    [05/Jan/2005:12:49:03] WARNING ( 1896):      Validation error in bean CustomerSubscription: The type of non-static field customer of the key class
    test.subscription.CustomerSubscriptionCMP_1530383317_JDOState$Oid must be primitive or must implement java.io.Serializable.
         Update the type of the key class field.
         Warning: All primary key columns in primary table CustomerSubscription of the bean corresponding to the generated class test.subscription.CustomerSubscriptionCMP_1530383317_JDOState must be mapped to key fields.
         Map the following primary key columns to key fields: CustomerSubscription.CustomerEmail,CustomerSubscription.SubscriptionType. If you already have fields mapped to these columns, verify that they are key fields.Is it enough that a primary key class be serializable or all fields have to implement Serializable or be a primitive?
    Please let me know if you need more information to answer my question.
    Thanks.
    Nikola

    Hi Nikola,
    There are several problems with your CMP bean.
    1. Fields of a Primary Key Class must be a subset of CMP fields, so yes, they must be either a primitive or a Serializable type.
    2. Sun Application Server does not support Primary Key fields of an arbitrary Serializable type (i.e. those that will be stored
    as BLOB in the database), but only primitives, Java wrappers, String, and Date/Time types.
    Do you try to use stubs instead of relationships or for some other reason?
    If it's the former - look at the CMR fields.
    If it's the latter, I suggest to store these fields as regular CMP fields and use some other value as the PK. If you prefer that
    the CMP container generates the PK values, use the Unknown
    PrimaryKey feature.
    Regards,
    -marina

  • Composite Primary Key Error

    I am using Sun One App Server PE8.
    I have a class with a composite primary key field. When I place the following method in my Home interface:
    public MyEjb findByPrimaryKey(MyEjbPrimaryKey pk) throws FinderException, RemoteException;I get the following error when deploying:
    ejbFindByPrimaryKey(EjbPrimaryKey) is already defined in MyEjb1368202910_ConcreteImpl
        public MyEjbPrimaryKey ejbFindByPrimaryKey (MyEjbPrimaryKey key)However, If i remove this method from the Home interface, i get the following error when running the verification tool:
    Error: No single arg findByPrimaryKey(PrimaryKeyClass) method was found in home interface class [ MyEjb ].However, I can still deploy the EAR successfully.
    Another related symptom of this problem, is if I include the following method in my Home interface:
    public MyEjb findByPrimaryKey(String pkField1, String pkField2) throws FinderException, RemoteException;And call this method, I get the following exception at runtime:
    java.rmi.RemoteException: Bean class for ejb [MyEjb] does not define a method corresponding to [Home] interface method [public abstract MyEjb MyEjbHome.findByPrimaryKey(java.lang.String,java
    .lang.String) throws javax.ejb.FinderException,java.rmi.RemoteException]I get these same problems with all EJB's that use composite keys. Has anyone else had this problem?
    Thanks
    toby

    This is a CMP bean, with no ejbFindByPrimaryKey in the Bean class. Below, i have included the Home interface and the Bean class (with unneccessary code removed)
    Thanks for looking at this for me.
    BEAN CLASS
    package lands.mc.bus.prod;
    import java.rmi.*;
    import java.util.*;
    import javax.ejb.*;
    public abstract class TopoMapBean implements EntityBean
      private EntityContext entity;
      public TopoMapBean()
      public void setEntityContext(EntityContext ctx)
        entity = ctx;
      public void unsetEntityContext()
        entity = null;
      public TopoMapPrimaryKey ejbCreate(String mapName, String mapNumber, String mnemonic,String edition, String scale)
      throws CreateException
        // call setters...
        return null;
      public void ejbPostCreate( String mapName,
                                                   String mapNumber,
                                             String mnemonic,
                                             String edition,
                                             String scale )
      removed set/get methods
      public void ejbStore() {}
      public void ejbLoad() {}
      public void ejbActivate() {}
      public void ejbPassivate() {}
      public void ejbRemove() {}
    }HOME INTERFACE
    package lands.mc.bus.prod;
    import java.rmi.*;
    import java.util.*;
    import javax.ejb.*;
    public interface TopoMapHome extends EJBHome
      public TopoMap create(String mapName,
                            String mapNumber,
                            String mnemonic,
                            String edition,
                            String scale
      throws CreateException, RemoteException;
      public TopoMap findByPrimaryKey(String mapNumber, String edition) throws FinderException, RemoteException;
    // doesnt deploy with this signature
    //  public TopoMap findByPrimaryKey(TopoMapPrimaryKey pkey) throws FinderException;
    // have to use this method instead of findByPrimaryKey(String, String) above
      public TopoMap findTopoMap(String mapNumber, String edition) throws FinderException, RemoteException;

Maybe you are looking for