0 Replies Latest reply on Jun 30, 2004 5:37 PM by shacka

    selecting next key value from db using ejb-ql max

    shacka

      Hi, all..

      I got this 80% done project developed on Novell ExteNd App Server,
      trying to port it to jboss + mysql + winxp environment..

      My question is if it is possible to use finder method to get max key value
      from db (e.g. max(someID)) and use it as part of the primary key for the new record that is being created..

      Previously, the code does direct JDBC connection to get max(someID) then use it for the PK class to create an entitiy record..

      I tried defining "SELECT MAX(o.ID) FROM xxxTable AS o WHERE..." in ejb-ql section of the ejb-jar.xml and have the abstract def in LocalHome interface with Collection as the return type..

      In my session bean, I iterated the returned Collection and casting it to local interface of the bean but got class cast exception with msg saying "expecting xxxLocal but it was Integer (value: 110005)"..

      Of course, when I tried the whole thing with xxxLocal return type instead of Collection, it didn't work either because when I used getters of the local object, it said something like "incomplete object" or something..

      I know there is ejbSelectXXX to return any type but I can't use it since I need to find out max key to create entity's local reference, I can't make
      select method exposed to localHome interface, can I..?

      I also cannot use auto-generated key feature.. it is just not possible with the current table structures.. the max ID that I want to get is part of the compound (or composite) primary key..

      So in nutshell, what I am asking here is this:
      how to get a max value of a column which will be incremented and used as a part of the key to create a record..??

      Excuse me for my long and off-focused explaination.. it is my first time posting a question here and I do not know how elaborate nicely..

      Please shine some light on me... ;)Any help on this matter would be greatly appriciated...