JPA object binding should throw a 404 if object not found

Bug #637304 reported by niels
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
play framework
Invalid
Undecided
Unassigned

Bug Description

See discussion here: http://groups.google.de/group/play-framework/browse_thread/thread/936dd3698ae8747a/0d3bbcb803eacf50#0d3bbcb803eacf50

If an object is deleted during edit you get an Exception instead of an 404 if you use JPA-Object binding. This should be fixed.

The patch throws an NotFound with Message for code object_not_found_in_database (For example: The object with id %s couldn't be found in the database.) I don't know where to define a default message or where to document it, so this is still open :-/

Related branches

Revision history for this message
niels (opensource21) wrote :
Revision history for this message
niels (opensource21) wrote :

The patch is for play 1.1 r1038

Revision history for this message
niels (opensource21) wrote :

The patch will conflict with revision 1041!

Revision history for this message
niels (opensource21) wrote :

Created a branch which fixed the problem and adjusted test.

Revision history for this message
niels (opensource21) wrote :
Changed in play:
status: New → Invalid
Revision history for this message
niels (opensource21) wrote :

Why is it invalid? What should a developer do, to avoid to show the user an exception

Revision history for this message
Guillaume Bort (guillaume-bort) wrote : Re: [Bug 637304] Re: JPA object binding should throw a 404 if object not found

The JPA layer should not be responsible to handle an HTTP response.
Moreover if the framework internal directly throw an exception, it let
no chance to the application code to handle properly the issue, for
example by displaying a message like:

"The object has been deleted, do you want to create a new one?"

The issue is fixed in the CRUD where it now display a 404 page. But
for specific application, the developer has to check if the object is
persistent:

public static void update(Item item) {
     // Item should be a persistent object here since it is an update
     if(item.isPersistent()) {
          item.save();
          show(item.id);
     }
     // handle the error case
}

On Mon, Oct 4, 2010 at 2:43 PM, niels <email address hidden> wrote:
> Why is it invalid? What should a developer do, to avoid to show the user
> an exception
>
> --
> JPA object binding should throw a 404 if object not found
> https://bugs.launchpad.net/bugs/637304
> You received this bug notification because you are subscribed to play
> framework.
>

--
Guillaume Bort, http://guillaume.bort.fr

For anything work-related, use <email address hidden>; for everything else,
write <email address hidden>

Revision history for this message
niels (opensource21) wrote :

OK that's a fine solution. I had call it a fix but anyway. Will you adjust at line 250 of http://bazaar.launchpad.net/~play-developers/play/1.1-unstable/annotate/1097/documentation/manual/controllers.textile the documentation or shall I raise a separate bug?

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.