org.hibernate.PersistentObjectException: detached entity passed to persist: models.car

718 views
Skip to first unread message

cronix

unread,
Nov 6, 2010, 11:21:53 AM11/6/10
to play-framework
Hi everybody,

I have a strange persistance problem that i can't explain to my self,
I hope you can help.


Example:

A controller method that recieves values from a post as a list of
objects.

form:

<form action="@{Cars.canHas()}" method="POST" enctype="multipart/form-
data">
<input type="hidden"name="cars[0].id" id="cars[0].id" value="1" />
<--- an object with this ID is in the database
<input type="hidden"name="cars[1].id" id="cars[1].id" value="2" />
<--- an object with this ID is in the database
</form>
method:
public static void canHas( List<Car> cars){

car.save(); -> org.hibernate.PersistentObjectException: detached
entity passed to persist: models.car
}

GrailsDeveloper

unread,
Nov 6, 2010, 12:32:09 PM11/6/10
to play-framework
This can happens if the car don't exists anymore in the database. Try
to catch the ids and check if they are really exists in the database.
Niels

cronix

unread,
Nov 6, 2010, 12:38:58 PM11/6/10
to play-framework
It does exist in the database, that is my problem. if merge it first
an then save it, it works.

Before saving the object every other attribute of the car is null,
even if it has attributes stored in the database.

On Nov 6, 5:32 pm, GrailsDeveloper <opensourc...@googlemail.com>
wrote:

Guillaume Bort

unread,
Nov 6, 2010, 3:04:02 PM11/6/10
to play-fr...@googlegroups.com
Have specified a cascade property on your relation?

> --
> You received this message because you are subscribed to the Google Groups "play-framework" group.
> To post to this group, send email to play-fr...@googlegroups.com.
> To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.
>
>

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

For anything work-related, use g...@zenexity.fr; for everything else,
write guillau...@gmail.com

cronix

unread,
Nov 6, 2010, 3:14:43 PM11/6/10
to play-framework
what makes you think that there is any relation involved? It is only a
list cars and a car has no relation to any other model.
> Guillaume Bort,http://guillaume.bort.fr
>
> For anything work-related, use g...@zenexity.fr; for everything else,
> write guillaume.b...@gmail.com
Reply all
Reply to author
Forward
0 new messages