[
http://opensource.atlassian.com/projects/hibernate/browse/ANN-682?page=co...
]
Eugene Voytitsky commented on ANN-682:
--------------------------------------
Did I understand right that currently Hibernate doesn't have possibility to rename
name of auto-generated foreign key constraint for association which is defined in my
@MappedSuperclass?
In other words, if I have @ManyToOne association in my @MappedSuperclass class and number
of entity subclasses then I have no way to explicitly specify (rename) the names of
foreign keys in each entity subclass: neither @AttributeOverride nor @AssociationOverride
provides the possibility to specify foreign key name.
It's a pity.
Actually I only have very ugly solution/workaround:
because I use @AccessType("filed") strategy for my @MappedSuperclass class I can
change the strategy to @AccessType("property") on all entity subclasses and
fully redefine the association on getter method, something like this:
@AccessType("property")
public class Entity1 extends MyBaseClass {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id", nullable = false)
@ForeignKey(name = "fk_entity1_2_user")
public User getUser() {
return super.getUser();
}
Everything smells bad in this "solution":
* changing the strategy
* full redifinition of the association
* and even invocation of super.getUser()
Is it going to be improved in the upcoming Hibernate releases?
Thanks in advance.
@ForeignKey override of @MappedSuperclass
-----------------------------------------
Key: ANN-682
URL:
http://opensource.atlassian.com/projects/hibernate/browse/ANN-682
Project: Hibernate Annotations
Issue Type: New Feature
Components: binder
Reporter: Christian Bauer
Put this @ManyToOne in a @MappedSuperclass:
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "CREATED_BY_USER_ID", nullable = false)
// Ideally this foreign key should be ON DELETE SET NULL, however...
// Hibernate can't rename these so subclasses would get the same FK constraint
name. This doesn't
// work, so we need to let Hibernate create a random identifier for these. We could
fix this in the
// DatabaseObjects.hbm.xml file but we can't even address it because the name is
random. This sucks.
// So we do a manual SET NULL|DEFAULT when userHome.remove() is called.
// @org.hibernate.annotations.ForeignKey(name =
"FK_WIKI_NODE_CREATED_BY_USER_ID")
protected User createdBy;
Now all subclasses get that foreign key constraint name in the database catalog, which
isn't possible - constraint names have to be unique.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira