Does JPA support annotations (or xml tags declarations) for declaring a constraint like ON DELETE (set null, cascade, ...)?
I've used JPA to create a database, more exactly the hibernate implementation of JPA. But anyway, at first, my question is related to JPA. Let's do a scenario. I have two tables A, B and need to create a relationship from A to B (ie. one to many) by a foreign key. So table B has the column A_id. I want to make possible to cascade my actions done on A records. For example: if I delete an A's tuple, all B's tuples related to deleted A's tuple will be also deleted. I know this is possible using hibernate @OnDelete a开发者_开发知识库nnotation, but I want to do that achievable also if you use tables other than by hibernate. Is it possible by JPA implementation?(or by hibernate)
JPA does NOT support FK constraint definition by metadata (XML/annotations), only whether to cascade. JDO is the only persistence spec to define FK details. You need to use JPA vendor-specifics to achieve what you need.
Oracle supports ON DELETE CASCADE
on foreign key constraints, so I don't see why it couldn't be used, whether or not you use Hibernate (which is just a layer on top of JDBC).
I doubt you'll be able to define this clause using JPA annotations, but anyway, other than for a quick n' dirty test, the database schema shouldn't be created by Hibernate, but by a specific script (which handles table spaces, indexes, naming conventions, etc.)
精彩评论