Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JPA Question : Deletion w.r.t One-to-many relation

 
G Priya
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Am a newbie to Java Persistence API. In our database, we have a one-to-many relationship between 2 tables, say t1 & t2 i.e. one record of t1 can be associated with multiple records in table t2. Is it possible to delete a row in t2 without doing anything to the associated row in t1? Is this allowed in JPA? I heard that an error saying "parent is null' is thrown in such a case?

Thanks.
 
Oliver Kamps
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

it depends, mostly on what your tables actually look like.

Assuming you have a column on t2 linking the row to the 'parent' row in t1, you should be able to delete the t2 row. You'll want to consider any other ongoing activities / transactions on the database, of course.

When working with object persistence technologies, you'll typically want to modify your persistent objects through the application (and, therefore, your persistence technology) rather than directly through the database. In this case, you'd probably want to talk about deleting or removing an object rather than deleting a row in the database.

Cheers,
Oliver
 
my overalls have superpowers - they repel people who think fashion is important. Tiny ad:
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!