I have a CD class with a Media class inheritance:
CD:
@Entity public class CD extends Media { ... }
MASS MEDIA:
@Entity(name = "media") @Inheritance(strategy = InheritanceType.JOINED) public abstract class Media extends PersistenceId<Long> { ... }
JPA automatically generates a foreign key name, and I would like to override this name that I want:
03-10 18: 16: 58.174 [main] DEBUG org.hibernate.SQL - change the cd add table restriction FK_ehd468g2cptgh6bq6sxe75xlf foreign key links (id) media (id)
How to do it? I tried:
@Entity @AssociationOverride( name = "id", foreignKey = @ForeignKey(name = "fk_cd_media") ) public class CD extends Media { ... }
and
@Entity @PrimaryKeyJoinColumn( foreignKey=@ForeignKey (name = "fk_cd_media")) public class CD extends Media { ... }
but that will not work.
Here is the sql table created:
CREATE TABLE `cd` ( `artist` varchar(255) DEFAULT NULL, `year` int(11) NOT NULL, `id` bigint(20) NOT NULL, PRIMARY KEY (`id`), CONSTRAINT `FK_ehd468g2cptgh6bq6sxe75xlf` FOREIGN KEY (`id`) REFERENCES `media` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
I would like to:
CONSTRAINT `fk_cd_media` FOREIGN KEY (`id`) REFERENCES `media` (`id`)
source share