• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

FinderException

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I have a findBy method which takes in 3 parameters and returns a remote interface ( not a collection ). In DB there is exactly one record which matches the findBy methods 3 parameters. In this case i am able to retrieve record from DB. I also have a condition where if i get a FinderException, i create a new record or else i update the existing record. The problem now i am facing is when there are duplicate records in DB, i get a FinderException and so a new record is created in DB, now totally make it three records which match the findBy method condition. I hope my problem is clearly explained. Can anyone pls give me a solution. Thanks in advance.

Karthik
 
Ranch Hand
Posts: 1209
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the 3 parameters you are accepting in your finder do not constitute the primary key of your table, then indicate the same in the finder as well.Your finder should return a collection in this case.If you still choose to return the remote/local interface of the bean then make sure that you check for duplication when you do a create() and not allow for creation of duplicate records in the table.

If i remeber correctly a finder returning a Collection will not throw a finder exception if no records are returned as a result of the query.

So you have to check for the size of the collection before creating a new record in this case
I mean if coll.size() <= 0 then go ahead and create the record in the database
 
bksella sella
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks karthik for your suggestion...
bksella.
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
karthik could bksella also use DISTINCT in his EJB QL to only return one record?
 
bksella sella
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi David,
Here is the findBy code which returns multiple rows ( due to duplicated records in DB ).

<finder>
<method-name>findByEmpidTypeAddress</method-name>
<method-params>
<method-param>java.lang.Long</method-param>
<method-param>java.lang.Long</method-param>
<method-param>java.lang.Long</method-param>
</method-params>
<finder-query><![CDATA[(&(&(= empId $0)(= type $1))(= address $2))]]>
</finder-query>
</finder>

Now how do i use the distinct in the above piece of code ( as u suggested )...
 
reply
    Bookmark Topic Watch Topic
  • New Topic