• Post Reply Bookmark Topic Watch Topic
  • New Topic

Cannot add or update a child row when using @EmbeddedId  RSS feed

 
daphna deutsch
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have the following objects:

User Object:


UserReason Object:


And UserReasonPK object:


I want to be able to add userReason to the list, and that Hibernate will automatically update the reference between the parent & child object.

When using the above code, when trying to start the server, i'm getting the error message:


Please notice that i mapped the userId in UserReasonPK with insertable = false, updatable = false.

If i change it, and add this on the User property in UserReason object, server is up, but when trying to insert new User i'm getting the following error:


 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Posts: 2906
198
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Daphna,

The problem is that you have the userId in both the EmbeddedId as in the relationship to the User Entity. If I remember it well you can use the @MapsId annotation to indicate that the userId is mapped to the User Entity:

Regards,
Frits
 
daphna deutsch
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Frits,
thanks for you help.
it did fix the problem!

Daphna
 
daphna deutsch
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
daphna deutsch wrote:Hello,

I have the following objects:

User Object:


UserReason Object:


And UserReasonPK object:


I want to be able to add userReason to the list, and that Hibernate will automatically update the reference between the parent & child object.

When using the above code, when trying to start the server, i'm getting the error message:


Please notice that i mapped the userId in UserReasonPK with insertable = false, updatable = false.

If i change it, and add this on the User property in UserReason object, server is up, but when trying to insert new User i'm getting the following error:


 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!