Newbie question - Saving causes ORA error, but it's hidden/swallowed

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Newbie question - Saving causes ORA error, but it's hidden/swallowed

Luch
I'm new to and experimenting w/Grails... I was following some online tutorials for building a REST service. It involved taking xml and then saving it to the database. I'm saving to a particular table that has a certain unique constraint on it, where the unique constraint is not the Primary Key. The PK is the "ID" field and uses the sequence HIBERNATE_SEQUENCE. The saving of a new record usually works fine, but I noticed this issue... when the save fails because of a violation of the unique constraint that is on the table... Although I see the ORA error being echoed via the Grails IDE (i'm running with SpringSource)... the invoker of the REST function does not get an error back. In fact, he gets the same result as if it the function call and save to the DB had succeeded. I'd like to know how I can make it so the invoker of the REST function gets an exception or knows somehow that the save failed. I don't mind that the hiberate_sequence value is assigned , but I would expect it would still throw an error back to the invoker of the REST service. Below is the code i'm playing with. BTW, this is using an Oracle DB.



        def save = {
                def xml = request.XML;
                def p = new PilotDefect();
               
                p.defectType = xml.defectType.text()
                p.defect = xml.defect.text()
                p.defectItem = 55;
                p.defectDescription = xml.defectDescription.text();
       
                if (p.validate()) {
                        if(p.save()) {
                                response.status = 201;
                                render p as XML // This still happens even when the save causes an ORA error to be thrown.
                        }
                        else {
                                def errors = p.errors.allErrors.collect { g.message(error:it) }
                                render(contentType:"text/xml") {
                                        error {
                                                for(err in errors) {
                                                        message(error:err)
                                                }
                                        }
                                }
                        }
                } else {
                sendValidationFailedResponse(p, 403)
          }
        }

The save on the domain object is not overridden.
Reply | Threaded
Open this post in threaded view
|

Re: Newbie question - Saving causes ORA error, but it's hidden/swallowed

micke_
Hi

try using .save(failOnError:true)


On 2 January 2012 03:05, Luch <[hidden email]> wrote:
I'm new to and experimenting w/Grails... I was following some online
tutorials for building a REST service. It involved taking xml and then
saving it to the database. I'm saving to a particular table that has a
certain unique constraint on it, where the unique constraint is not the
Primary Key. The PK is the "ID" field and uses the sequence
HIBERNATE_SEQUENCE. The saving of a new record usually works fine, but I
noticed this issue... when the save fails because of a violation of the
unique constraint that is on the table... Although I see the ORA error being
echoed via the Grails IDE (i'm running with SpringSource)... the invoker of
the REST function does not get an error back. In fact, he gets the same
result as if it the function call and save to the DB had succeeded. I'd like
to know how I can make it so the invoker of the REST function gets an
exception or knows somehow that the save failed. I don't mind that the
hiberate_sequence value is assigned , but I would expect it would still
throw an error back to the invoker of the REST service. Below is the code
i'm playing with. BTW, this is using an Oracle DB.



       def save = {
               def xml = request.XML;
               def p = new PilotDefect();

               p.defectType = xml.defectType.text()
               p.defect = xml.defect.text()
               p.defectItem = 55;
               p.defectDescription = xml.defectDescription.text();

               if (p.validate()) {
                       if(p.save()) {
                               response.status = 201;
                               render p as XML // This still happens even when the save causes an ORA
error to be thrown.
                       }
                       else {
                               def errors = p.errors.allErrors.collect { g.message(error:it) }
                               render(contentType:"text/xml") {
                                       error {
                                               for(err in errors) {
                                                       message(error:err)
                                               }
                                       }
                               }
                       }
               } else {
               sendValidationFailedResponse(p, 403)
         }
       }

The save on the domain object is not overridden.

--
View this message in context: http://grails.1312388.n4.nabble.com/Newbie-question-Saving-causes-ORA-error-but-it-s-hidden-swallowed-tp4252282p4252282.html
Sent from the Grails - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|

Re: Newbie question - Saving causes ORA error, but it's hidden/swallowed

Luch
Hello,
I should've mentioned that I had tried that.... It doesn't seem to catch/throw the error either. I also tried adding the below to the Config.groovy file, and it doesn't do it either:

grails.gorm.failOnError=true



<quote author="micke_">
Hi

try using .save(failOnError:true)

Reply | Threaded
Open this post in threaded view
|

Re: Newbie question - Saving causes ORA error, but it's hidden/swallowed

micke_
Then I have no idea I'm afraid.

Perhaps a bit more info like the stack trace, domain object code, how to reproduce etc. will enable some of the more grails savvy folks on the list to spot something.

Good luck ;)
 Micke

On 2 January 2012 16:20, Luch <[hidden email]> wrote:
Hello,
I should've mentioned that I had tried that.... It doesn't seem to
catch/throw the error either. I also tried adding the below to the
Config.groovy file, and it doesn't do it either:

grails.gorm.failOnError=true




Hi

try using .save(failOnError:true)



--
View this message in context: http://grails.1312388.n4.nabble.com/Newbie-question-Saving-causes-ORA-error-but-it-s-hidden-swallowed-tp4252282p4253718.html
Sent from the Grails - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|

Re: Newbie question - Saving causes ORA error, but it's hidden/swallowed

Lauro Becker
In reply to this post by Luch
Hi Luch,

Have you used the unique constraint in PilotDefect? Probably you can avoid this exception by mapping properly your entity.

Lauro L. V. Becker
---------------------------
Blog: http://laurobecker.wordpress.com


2012/1/2 Luch <[hidden email]>
Hello,
I should've mentioned that I had tried that.... It doesn't seem to
catch/throw the error either. I also tried adding the below to the
Config.groovy file, and it doesn't do it either:

grails.gorm.failOnError=true




Hi

try using .save(failOnError:true)



--
View this message in context: http://grails.1312388.n4.nabble.com/Newbie-question-Saving-causes-ORA-error-but-it-s-hidden-swallowed-tp4252282p4253718.html
Sent from the Grails - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|

Re: Newbie question - Saving causes ORA error, but it's hidden/swallowed

Luch
Oi Lauro,
What I'm really trying to get at is how I would catch an un-expected error. I think I see what you're saying, in how I could fix/avoid this error... But what if I didn't, and the error does happen... I don't want the invoker of the REST function to believe his call to the function saved the data, when it really did not.



Lauro Becker wrote
Hi Luch,

Have you used the unique constraint in PilotDefect? Probably you can avoid
this exception by mapping properly your entity.

Lauro L. V. Becker
---------------------------
Blog: http://laurobecker.wordpress.com


2012/1/2 Luch <[hidden email]>

> Hello,
> I should've mentioned that I had tried that.... It doesn't seem to
> catch/throw the error either. I also tried adding the below to the
> Config.groovy file, and it doesn't do it either:
>
> grails.gorm.failOnError=true
>
>
>
>
> Hi
>
> try using .save(failOnError:true)
>
>
>
> --
> View this message in context:
> http://grails.1312388.n4.nabble.com/Newbie-question-Saving-causes-ORA-error-but-it-s-hidden-swallowed-tp4252282p4253718.html
> Sent from the Grails - user mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Newbie question - Saving causes ORA error, but it's hidden/swallowed

Lauro Becker
Hmm, understood.

Try using flush : true. For example: p.save(failOnError:true, flush:true).

Lauro L. V. Becker
---------------------------
Blog: http://laurobecker.wordpress.com


2012/1/2 Luch <[hidden email]>
Oi Lauro,
What I'm really trying to get at is how I would catch an un-expected error.
I think I see what you're saying, in how I could fix/avoid this error... But
what if I didn't, and the error does happen... I don't want the invoker of
the REST function to believe his call to the function saved the data, when
it really did not.




Lauro Becker wrote
>
> Hi Luch,
>
> Have you used the unique constraint in PilotDefect? Probably you can avoid
> this exception by mapping properly your entity.
>
> Lauro L. V. Becker
> ---------------------------
> Blog: http://laurobecker.wordpress.com
>
>
> 2012/1/2 Luch &lt;darthluch@&gt;
>
>> Hello,
>> I should've mentioned that I had tried that.... It doesn't seem to
>> catch/throw the error either. I also tried adding the below to the
>> Config.groovy file, and it doesn't do it either:
>>
>> grails.gorm.failOnError=true
>>
>>
>>
>>
>> Hi
>>
>> try using .save(failOnError:true)
>>
>>
>>
>> --
>> View this message in context:
>> http://grails.1312388.n4.nabble.com/Newbie-question-Saving-causes-ORA-error-but-it-s-hidden-swallowed-tp4252282p4253718.html
>> Sent from the Grails - user mailing list archive at Nabble.com.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>>
>>    http://xircles.codehaus.org/manage_email
>>
>>
>>
>


--
View this message in context: http://grails.1312388.n4.nabble.com/Newbie-question-Saving-causes-ORA-error-but-it-s-hidden-swallowed-tp4252282p4253847.html
Sent from the Grails - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email