Reputation: 616
The JDO Inheritance guide for DataNucleus mentions that in InheritanceStrategy.NEW_TABLE
class relationships, a foreign key will be created between the superclass' and subclass' tables. Running the DataNucleus schema generator, I do see that such a foreign key is being generated. What I can't discover, though, is how the names for these foreign keys can be customized.
For example:
@PersistenceCapable(table = "login_identities")
@Inheritance(strategy = InheritanceStrategy.NEW_TABLE)
public abstract class AbstractLoginIdentity { ... }
@PersistenceCapable(table = "email_login_identities")
@Inheritance(strategy = InheritanceStrategy.NEW_TABLE)
public class EmailLoginIdentity extends AbstractLoginIdentity { ... }
Given those classes, DataNucleus will generate a foreign key like the following (for PostgreSQL):
-- Constraints for table "email_login_identities" for class(es) [com.trickle.api.accounts.EmailLoginIdentity]
ALTER TABLE "email_login_identities" ADD CONSTRAINT "email_login_identities_FK1" FOREIGN KEY ("id") REFERENCES "login_identities" ("id") ;
I can't discover any way to alter the "email_login_identities_FK1
" constraint's name. Adding a @ForeignKey
annotation to the subclass just adds a new foreign key.
Can this be customized?
Upvotes: 1
Views: 208
Reputation: 11531
The foot of this page shows how to define a foreign key for the join to superclass, using XML.
I don't see a way of doing that in annotations (since @Inheritance
has no @Join
, and @Join
has no @ForeignKey
) ... but then I would never want to hardcode ORM definitions into a Java class. I assume you could request such a facility in annotations via the Apache JDO people.
Upvotes: 1