1 Reply Latest reply on May 8, 2002 11:58 PM by marcilgen

    Primary Keys not created in mysql for compound CMP key

    stoffe

      Hi!

      I'm running jboss 2.4.4 and trying to deploy a CMP bean with a compound primary key.

      The JAWSPersistenceManager seems to be able to keep track of the compound primary key containing two string elements.
      So everything seems to be fine but the generated tables in the mysql database doesn't have the right fields as primary keys in the database.

      It will result in table scan searches and they are not acceptable if you have more then 100 rows.

      Is it something that isn't implemented in the JAWSPersistenceManager or do I have to map it in the ejb-jar.xml or jboss.xml?

      I tried to use the <primarykey-field> but it only allows one field. So how do i get my two String/varchar fields to be PK in the database?

      Thanks!,Kristoffer

        • 1. Re: Primary Keys not created in mysql for compound CMP key
          marcilgen

          Did you ever hear back about how to do this? I'm running into the same problem.
          I have an entity bean called RoomInfoBean and the primary key for this class is a class called RoomInfoPK. RoomInfoBean has several fields but two fields compose the primary key: String lobbyName and String roomName. RoomInfoPK just has the two fields lobbyName and roomName, which of course should map to the corresponding fields in the bean.
          I am confused as to how to specify the findByprimaryKey method in jaws.xml. For a simple primary key, you can set <primkey-field> in ejb-jar.xml to be the primary key field, so in that case there is no need to specify a findByPrimaryKey method in jaws.xml. There it is clear how JBOSS will map the appropriate column in my database table to the bean field. But for my compound primary key, I can't use <primkey-field> in ejb-jar.xml. I can only use <prim-key-class> to tell JBOSS that I am using a primary key class of RoomInfoPK. So how does JBOSS know which two columns within my roominfo table in the database must be mapped to the two fields I need in my primary key? Some of the documentation says that findByPrimaryKey is generated automatically. But I don't see how it can do this for compound primary keys like this unless I somehow tell jaws to use (for example) the first column for lobbyName and the second column for roomName to build my primary key class. I'm guessing that I need to do this somehow, but I don't know how.

          Anyone out there know the answer to this?