Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Cascading update over three entities with OpenJPA

 
Jochen Schnaidt
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everybody,

I hope for some assistance regarding an issue with a cascading update action in my application. The application uses Apache OpenJPA 2.0.1. There is a problem with the data model consisting of three entities.

I have an entity called hotel, having zero to many rooms and zero to many infos. A room can also have zero to many infos.

The table INFO consists (simplified) of a column for a generated id, a column for the id of a hotel, if the info belongs to a hotel. Also there is a column for a room id if the info belongs to a room and the info itself. A data set always consists of a hotel id and info OR room id and info.

The model looks like this



For reading access everything is working fine. When it comes to writing everything gets weird. I hoped to make changes in the infoList of a hotel or room object (add or remove entries) and OpenJPA manages to write the data in the db. But here starts the trouble.
In the configuration above I get the following error:


My guess is, that in the case of storing a hotel the room column is null, which is not allowed by the database. I tried generating a ‘dummy’ object with new Room() which ends in an error of a detached object.

I appreciate every idea what is wrong in my configuration.

Thanks a lot. Best regards.

Jochen
 
Jochen Schnaidt
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In follow up. I narrowed the error to the missing Room object. The column is wrong. It is not nullable but should be.
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jochen, welcome to CodeRanch and thank you for posting the solution.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic