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