-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Override ForeignKey constraint for join inherited entity
PostPosted: Thu Oct 29, 2015 11:52 am 
Newbie

Joined: Thu Oct 29, 2015 11:10 am
Posts: 1
Hey guys, can you please help me out with ForeignKey constraint name override for following setup:
Code:
@MappedSuperclass
public abstract class Base
{

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    protected long id;

    public Long getId()
    {
        return id;
    }

}


Code:
@MappedSuperclass
public abstract class CreateUpdateTimestampableBase extends Base {}


Code:
@Entity
@Table(name = "abstract_users")
@Access(AccessType.FIELD)
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn(name = "user_type", discriminatorType = DiscriminatorType.STRING, length = 15)
abstract public class AbstractUser extends CreateUpdateTimestampableBase {}


Code:
@Entity
@Table(name = "users")
@Access(AccessType.FIELD)
@DiscriminatorValue("user")
public class User extends AbstractUser {}


I tried @PrimaryKeyJoinColumn(name = "id", foreignKey = @ForeignKey(name = "...")), it changed primary key column name, however it doesn't respect foreign key. Also i tried @AssociationOverride(), but couldn't make it work... Any ideas?

Currently i get mangled FK name like:
Code:
ALTER TABLE ONLY users ADD CONSTRAINT fk_ncwxer8x284o9w96xjk9uxfh7 FOREIGN KEY (id) REFERENCES abstract_users(id);


I don't want to use custom naming strategy, because default strategy with mangled name makes easier for me to find which foreign keys i didn't declared by myself, and makes it easier to handle liquibase dependencies later for me.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.