Can I name my constraints with JPA?












21














When I use the maven-hibernate3-plugin (aka hbm2ddl) to generate my database schema, it creates many database constraints with terrifically hard-to-remember constraint names like FK7770538AEE7BC70 .



Is there any way to provide a more useful name such as FOO_FK_BAR_ID ?



If so, it would make it a tad easier to track down issues in the log files and other places where the violation doesn't tell you anything other than the constraint name.










share|improve this question
























  • No. JDO is the only standard supporting naming of constraints (index, uniques, FKs, PKs).
    – DataNucleus
    Jul 3 '10 at 6:17










  • You cannot name PKs: stackoverflow.com/q/3289126/1389219
    – vegemite4me
    Dec 4 '15 at 9:33
















21














When I use the maven-hibernate3-plugin (aka hbm2ddl) to generate my database schema, it creates many database constraints with terrifically hard-to-remember constraint names like FK7770538AEE7BC70 .



Is there any way to provide a more useful name such as FOO_FK_BAR_ID ?



If so, it would make it a tad easier to track down issues in the log files and other places where the violation doesn't tell you anything other than the constraint name.










share|improve this question
























  • No. JDO is the only standard supporting naming of constraints (index, uniques, FKs, PKs).
    – DataNucleus
    Jul 3 '10 at 6:17










  • You cannot name PKs: stackoverflow.com/q/3289126/1389219
    – vegemite4me
    Dec 4 '15 at 9:33














21












21








21


4





When I use the maven-hibernate3-plugin (aka hbm2ddl) to generate my database schema, it creates many database constraints with terrifically hard-to-remember constraint names like FK7770538AEE7BC70 .



Is there any way to provide a more useful name such as FOO_FK_BAR_ID ?



If so, it would make it a tad easier to track down issues in the log files and other places where the violation doesn't tell you anything other than the constraint name.










share|improve this question















When I use the maven-hibernate3-plugin (aka hbm2ddl) to generate my database schema, it creates many database constraints with terrifically hard-to-remember constraint names like FK7770538AEE7BC70 .



Is there any way to provide a more useful name such as FOO_FK_BAR_ID ?



If so, it would make it a tad easier to track down issues in the log files and other places where the violation doesn't tell you anything other than the constraint name.







database hibernate orm jpa constraints






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jul 2 '10 at 22:15









Pascal Thivent

479k1119441060




479k1119441060










asked Jul 2 '10 at 21:17









HDave

12.3k23120211




12.3k23120211












  • No. JDO is the only standard supporting naming of constraints (index, uniques, FKs, PKs).
    – DataNucleus
    Jul 3 '10 at 6:17










  • You cannot name PKs: stackoverflow.com/q/3289126/1389219
    – vegemite4me
    Dec 4 '15 at 9:33


















  • No. JDO is the only standard supporting naming of constraints (index, uniques, FKs, PKs).
    – DataNucleus
    Jul 3 '10 at 6:17










  • You cannot name PKs: stackoverflow.com/q/3289126/1389219
    – vegemite4me
    Dec 4 '15 at 9:33
















No. JDO is the only standard supporting naming of constraints (index, uniques, FKs, PKs).
– DataNucleus
Jul 3 '10 at 6:17




No. JDO is the only standard supporting naming of constraints (index, uniques, FKs, PKs).
– DataNucleus
Jul 3 '10 at 6:17












You cannot name PKs: stackoverflow.com/q/3289126/1389219
– vegemite4me
Dec 4 '15 at 9:33




You cannot name PKs: stackoverflow.com/q/3289126/1389219
– vegemite4me
Dec 4 '15 at 9:33












3 Answers
3






active

oldest

votes


















20














As of JPA 2.1 it is possible to give a name to foreign key.
E.g.



@ManyToOne
@JoinColumn(foreignKey=@ForeignKey(name="MY_FANCY_FK_NAME"))
Account account;


Just make sure it is used within @JoinColumn. JavaDoc: https://docs.oracle.com/javaee/7/api/javax/persistence/ForeignKey.html#name%28%29






share|improve this answer





















  • Is there a way to do that with PK indexes also?
    – Please_Dont_Bully_Me_SO_Lords
    Nov 11 at 19:36










  • Do you need to change the name of a PK index, created automatically (AFAICT)?
    – Piohen
    Nov 12 at 15:03










  • Yes, just like the user asking wants to define a name for the FK, to avoid 'difficult to handle' names
    – Please_Dont_Bully_Me_SO_Lords
    Nov 13 at 16:10










  • I guess this might be needed in some cases, but honestly I've never seen any (business) need to rename the default PK's "unique index". I can imagine this name might be "difficult to handle" but I'd focus if the "handling" is really needed and/or justified. Anyway, I don't know such a way and I never had to.
    – Piohen
    Nov 29 at 11:27












  • you're right in most cases no one needs it, but in this case we want to make a community database framework to be used in many projects and many startups, so it would be easier to users to understand model IF ALL objects are correctly named.
    – Please_Dont_Bully_Me_SO_Lords
    Nov 30 at 12:29



















15














Hibernate has a @ForeignKey annotation allowing to override the constraint name. From the reference documentation:




2.4.6. Collection related annotations



(...)



Foreign key constraints, while
generated by Hibernate, have a fairly
unreadable name. You can override the
constraint name by use @ForeignKey.
Note that this annotation has to be
placed on the owning side of the
relationship, inverseName
referencing to the other side
constraint.



@Entity
public class Woman {
...
@ManyToMany(cascade = {CascadeType.ALL})
@ForeignKey(name = "TO_WOMAN_FK", inverseName = "TO_MAN_FK")
public Set<Man> getMens() {
return mens;
}
}

alter table Man_Woman add constraint TO_WOMAN_FK foreign key (woman_id) references Woman
alter table Man_Woman add constraint TO_MAN_FK foreign key (man_id) references Man



But I'm not aware of a standard JPA equivalent.






share|improve this answer























  • Arrgggghhhhh. Thanks.
    – HDave
    Jul 2 '10 at 21:59










  • In JPA: @JoinTable(joinColumns=@JoinColumn(name="TO_WOMAN_FK"), inverseJoinColumns=@JoinColumn(name="TO_MAN_FK"))
    – Arjan
    Jul 2 '10 at 22:31










  • @arjantop: No, this doesn't allow to specify the name of the foreign key constraint. You missed the point.
    – Pascal Thivent
    Jul 2 '10 at 22:38








  • 2




    my bad, i read the question too quickly
    – Arjan
    Jul 3 '10 at 8:27






  • 2




    Hibernate @ForeignKey is deprecated, use JPA annotation instead it.
    – Mohsen Kashi
    Feb 23 '15 at 10:47



















-1














Normally in an enterprise stack, DBAs will not and should not allow systemic entity creation in their database. They will usually ask for the DDLs to be inserted manually and you will set your Hibernate apps ddl-auto to the update mode and not create or create-drop mode. This is a ideal scenario in most of the brands I worked with. Having said, you can let the DBA decide to rename the Constraints through the alter-table statements that Hibernate will generate for you. Also, the Primary key constraint names will also be managed by DBAs once the Create table DDL is handed over to them.



If you are in a full stack role where you decide everything, you can only change the Foreign key name with current releases using the @ForeignKey annotation.



But I would still recommend, manual insertion of DDL statements to your Database rather than allowing a systemic process to take control since maintaining the the Database and de-fragmenting the structure becomes easier if a manual DBA architecture is embraced.



Hope this answers your question.






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f3169151%2fcan-i-name-my-constraints-with-jpa%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    20














    As of JPA 2.1 it is possible to give a name to foreign key.
    E.g.



    @ManyToOne
    @JoinColumn(foreignKey=@ForeignKey(name="MY_FANCY_FK_NAME"))
    Account account;


    Just make sure it is used within @JoinColumn. JavaDoc: https://docs.oracle.com/javaee/7/api/javax/persistence/ForeignKey.html#name%28%29






    share|improve this answer





















    • Is there a way to do that with PK indexes also?
      – Please_Dont_Bully_Me_SO_Lords
      Nov 11 at 19:36










    • Do you need to change the name of a PK index, created automatically (AFAICT)?
      – Piohen
      Nov 12 at 15:03










    • Yes, just like the user asking wants to define a name for the FK, to avoid 'difficult to handle' names
      – Please_Dont_Bully_Me_SO_Lords
      Nov 13 at 16:10










    • I guess this might be needed in some cases, but honestly I've never seen any (business) need to rename the default PK's "unique index". I can imagine this name might be "difficult to handle" but I'd focus if the "handling" is really needed and/or justified. Anyway, I don't know such a way and I never had to.
      – Piohen
      Nov 29 at 11:27












    • you're right in most cases no one needs it, but in this case we want to make a community database framework to be used in many projects and many startups, so it would be easier to users to understand model IF ALL objects are correctly named.
      – Please_Dont_Bully_Me_SO_Lords
      Nov 30 at 12:29
















    20














    As of JPA 2.1 it is possible to give a name to foreign key.
    E.g.



    @ManyToOne
    @JoinColumn(foreignKey=@ForeignKey(name="MY_FANCY_FK_NAME"))
    Account account;


    Just make sure it is used within @JoinColumn. JavaDoc: https://docs.oracle.com/javaee/7/api/javax/persistence/ForeignKey.html#name%28%29






    share|improve this answer





















    • Is there a way to do that with PK indexes also?
      – Please_Dont_Bully_Me_SO_Lords
      Nov 11 at 19:36










    • Do you need to change the name of a PK index, created automatically (AFAICT)?
      – Piohen
      Nov 12 at 15:03










    • Yes, just like the user asking wants to define a name for the FK, to avoid 'difficult to handle' names
      – Please_Dont_Bully_Me_SO_Lords
      Nov 13 at 16:10










    • I guess this might be needed in some cases, but honestly I've never seen any (business) need to rename the default PK's "unique index". I can imagine this name might be "difficult to handle" but I'd focus if the "handling" is really needed and/or justified. Anyway, I don't know such a way and I never had to.
      – Piohen
      Nov 29 at 11:27












    • you're right in most cases no one needs it, but in this case we want to make a community database framework to be used in many projects and many startups, so it would be easier to users to understand model IF ALL objects are correctly named.
      – Please_Dont_Bully_Me_SO_Lords
      Nov 30 at 12:29














    20












    20








    20






    As of JPA 2.1 it is possible to give a name to foreign key.
    E.g.



    @ManyToOne
    @JoinColumn(foreignKey=@ForeignKey(name="MY_FANCY_FK_NAME"))
    Account account;


    Just make sure it is used within @JoinColumn. JavaDoc: https://docs.oracle.com/javaee/7/api/javax/persistence/ForeignKey.html#name%28%29






    share|improve this answer












    As of JPA 2.1 it is possible to give a name to foreign key.
    E.g.



    @ManyToOne
    @JoinColumn(foreignKey=@ForeignKey(name="MY_FANCY_FK_NAME"))
    Account account;


    Just make sure it is used within @JoinColumn. JavaDoc: https://docs.oracle.com/javaee/7/api/javax/persistence/ForeignKey.html#name%28%29







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 18 '14 at 15:31









    Piohen

    1,0501119




    1,0501119












    • Is there a way to do that with PK indexes also?
      – Please_Dont_Bully_Me_SO_Lords
      Nov 11 at 19:36










    • Do you need to change the name of a PK index, created automatically (AFAICT)?
      – Piohen
      Nov 12 at 15:03










    • Yes, just like the user asking wants to define a name for the FK, to avoid 'difficult to handle' names
      – Please_Dont_Bully_Me_SO_Lords
      Nov 13 at 16:10










    • I guess this might be needed in some cases, but honestly I've never seen any (business) need to rename the default PK's "unique index". I can imagine this name might be "difficult to handle" but I'd focus if the "handling" is really needed and/or justified. Anyway, I don't know such a way and I never had to.
      – Piohen
      Nov 29 at 11:27












    • you're right in most cases no one needs it, but in this case we want to make a community database framework to be used in many projects and many startups, so it would be easier to users to understand model IF ALL objects are correctly named.
      – Please_Dont_Bully_Me_SO_Lords
      Nov 30 at 12:29


















    • Is there a way to do that with PK indexes also?
      – Please_Dont_Bully_Me_SO_Lords
      Nov 11 at 19:36










    • Do you need to change the name of a PK index, created automatically (AFAICT)?
      – Piohen
      Nov 12 at 15:03










    • Yes, just like the user asking wants to define a name for the FK, to avoid 'difficult to handle' names
      – Please_Dont_Bully_Me_SO_Lords
      Nov 13 at 16:10










    • I guess this might be needed in some cases, but honestly I've never seen any (business) need to rename the default PK's "unique index". I can imagine this name might be "difficult to handle" but I'd focus if the "handling" is really needed and/or justified. Anyway, I don't know such a way and I never had to.
      – Piohen
      Nov 29 at 11:27












    • you're right in most cases no one needs it, but in this case we want to make a community database framework to be used in many projects and many startups, so it would be easier to users to understand model IF ALL objects are correctly named.
      – Please_Dont_Bully_Me_SO_Lords
      Nov 30 at 12:29
















    Is there a way to do that with PK indexes also?
    – Please_Dont_Bully_Me_SO_Lords
    Nov 11 at 19:36




    Is there a way to do that with PK indexes also?
    – Please_Dont_Bully_Me_SO_Lords
    Nov 11 at 19:36












    Do you need to change the name of a PK index, created automatically (AFAICT)?
    – Piohen
    Nov 12 at 15:03




    Do you need to change the name of a PK index, created automatically (AFAICT)?
    – Piohen
    Nov 12 at 15:03












    Yes, just like the user asking wants to define a name for the FK, to avoid 'difficult to handle' names
    – Please_Dont_Bully_Me_SO_Lords
    Nov 13 at 16:10




    Yes, just like the user asking wants to define a name for the FK, to avoid 'difficult to handle' names
    – Please_Dont_Bully_Me_SO_Lords
    Nov 13 at 16:10












    I guess this might be needed in some cases, but honestly I've never seen any (business) need to rename the default PK's "unique index". I can imagine this name might be "difficult to handle" but I'd focus if the "handling" is really needed and/or justified. Anyway, I don't know such a way and I never had to.
    – Piohen
    Nov 29 at 11:27






    I guess this might be needed in some cases, but honestly I've never seen any (business) need to rename the default PK's "unique index". I can imagine this name might be "difficult to handle" but I'd focus if the "handling" is really needed and/or justified. Anyway, I don't know such a way and I never had to.
    – Piohen
    Nov 29 at 11:27














    you're right in most cases no one needs it, but in this case we want to make a community database framework to be used in many projects and many startups, so it would be easier to users to understand model IF ALL objects are correctly named.
    – Please_Dont_Bully_Me_SO_Lords
    Nov 30 at 12:29




    you're right in most cases no one needs it, but in this case we want to make a community database framework to be used in many projects and many startups, so it would be easier to users to understand model IF ALL objects are correctly named.
    – Please_Dont_Bully_Me_SO_Lords
    Nov 30 at 12:29













    15














    Hibernate has a @ForeignKey annotation allowing to override the constraint name. From the reference documentation:




    2.4.6. Collection related annotations



    (...)



    Foreign key constraints, while
    generated by Hibernate, have a fairly
    unreadable name. You can override the
    constraint name by use @ForeignKey.
    Note that this annotation has to be
    placed on the owning side of the
    relationship, inverseName
    referencing to the other side
    constraint.



    @Entity
    public class Woman {
    ...
    @ManyToMany(cascade = {CascadeType.ALL})
    @ForeignKey(name = "TO_WOMAN_FK", inverseName = "TO_MAN_FK")
    public Set<Man> getMens() {
    return mens;
    }
    }

    alter table Man_Woman add constraint TO_WOMAN_FK foreign key (woman_id) references Woman
    alter table Man_Woman add constraint TO_MAN_FK foreign key (man_id) references Man



    But I'm not aware of a standard JPA equivalent.






    share|improve this answer























    • Arrgggghhhhh. Thanks.
      – HDave
      Jul 2 '10 at 21:59










    • In JPA: @JoinTable(joinColumns=@JoinColumn(name="TO_WOMAN_FK"), inverseJoinColumns=@JoinColumn(name="TO_MAN_FK"))
      – Arjan
      Jul 2 '10 at 22:31










    • @arjantop: No, this doesn't allow to specify the name of the foreign key constraint. You missed the point.
      – Pascal Thivent
      Jul 2 '10 at 22:38








    • 2




      my bad, i read the question too quickly
      – Arjan
      Jul 3 '10 at 8:27






    • 2




      Hibernate @ForeignKey is deprecated, use JPA annotation instead it.
      – Mohsen Kashi
      Feb 23 '15 at 10:47
















    15














    Hibernate has a @ForeignKey annotation allowing to override the constraint name. From the reference documentation:




    2.4.6. Collection related annotations



    (...)



    Foreign key constraints, while
    generated by Hibernate, have a fairly
    unreadable name. You can override the
    constraint name by use @ForeignKey.
    Note that this annotation has to be
    placed on the owning side of the
    relationship, inverseName
    referencing to the other side
    constraint.



    @Entity
    public class Woman {
    ...
    @ManyToMany(cascade = {CascadeType.ALL})
    @ForeignKey(name = "TO_WOMAN_FK", inverseName = "TO_MAN_FK")
    public Set<Man> getMens() {
    return mens;
    }
    }

    alter table Man_Woman add constraint TO_WOMAN_FK foreign key (woman_id) references Woman
    alter table Man_Woman add constraint TO_MAN_FK foreign key (man_id) references Man



    But I'm not aware of a standard JPA equivalent.






    share|improve this answer























    • Arrgggghhhhh. Thanks.
      – HDave
      Jul 2 '10 at 21:59










    • In JPA: @JoinTable(joinColumns=@JoinColumn(name="TO_WOMAN_FK"), inverseJoinColumns=@JoinColumn(name="TO_MAN_FK"))
      – Arjan
      Jul 2 '10 at 22:31










    • @arjantop: No, this doesn't allow to specify the name of the foreign key constraint. You missed the point.
      – Pascal Thivent
      Jul 2 '10 at 22:38








    • 2




      my bad, i read the question too quickly
      – Arjan
      Jul 3 '10 at 8:27






    • 2




      Hibernate @ForeignKey is deprecated, use JPA annotation instead it.
      – Mohsen Kashi
      Feb 23 '15 at 10:47














    15












    15








    15






    Hibernate has a @ForeignKey annotation allowing to override the constraint name. From the reference documentation:




    2.4.6. Collection related annotations



    (...)



    Foreign key constraints, while
    generated by Hibernate, have a fairly
    unreadable name. You can override the
    constraint name by use @ForeignKey.
    Note that this annotation has to be
    placed on the owning side of the
    relationship, inverseName
    referencing to the other side
    constraint.



    @Entity
    public class Woman {
    ...
    @ManyToMany(cascade = {CascadeType.ALL})
    @ForeignKey(name = "TO_WOMAN_FK", inverseName = "TO_MAN_FK")
    public Set<Man> getMens() {
    return mens;
    }
    }

    alter table Man_Woman add constraint TO_WOMAN_FK foreign key (woman_id) references Woman
    alter table Man_Woman add constraint TO_MAN_FK foreign key (man_id) references Man



    But I'm not aware of a standard JPA equivalent.






    share|improve this answer














    Hibernate has a @ForeignKey annotation allowing to override the constraint name. From the reference documentation:




    2.4.6. Collection related annotations



    (...)



    Foreign key constraints, while
    generated by Hibernate, have a fairly
    unreadable name. You can override the
    constraint name by use @ForeignKey.
    Note that this annotation has to be
    placed on the owning side of the
    relationship, inverseName
    referencing to the other side
    constraint.



    @Entity
    public class Woman {
    ...
    @ManyToMany(cascade = {CascadeType.ALL})
    @ForeignKey(name = "TO_WOMAN_FK", inverseName = "TO_MAN_FK")
    public Set<Man> getMens() {
    return mens;
    }
    }

    alter table Man_Woman add constraint TO_WOMAN_FK foreign key (woman_id) references Woman
    alter table Man_Woman add constraint TO_MAN_FK foreign key (man_id) references Man



    But I'm not aware of a standard JPA equivalent.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Jul 2 '10 at 21:41

























    answered Jul 2 '10 at 21:36









    Pascal Thivent

    479k1119441060




    479k1119441060












    • Arrgggghhhhh. Thanks.
      – HDave
      Jul 2 '10 at 21:59










    • In JPA: @JoinTable(joinColumns=@JoinColumn(name="TO_WOMAN_FK"), inverseJoinColumns=@JoinColumn(name="TO_MAN_FK"))
      – Arjan
      Jul 2 '10 at 22:31










    • @arjantop: No, this doesn't allow to specify the name of the foreign key constraint. You missed the point.
      – Pascal Thivent
      Jul 2 '10 at 22:38








    • 2




      my bad, i read the question too quickly
      – Arjan
      Jul 3 '10 at 8:27






    • 2




      Hibernate @ForeignKey is deprecated, use JPA annotation instead it.
      – Mohsen Kashi
      Feb 23 '15 at 10:47


















    • Arrgggghhhhh. Thanks.
      – HDave
      Jul 2 '10 at 21:59










    • In JPA: @JoinTable(joinColumns=@JoinColumn(name="TO_WOMAN_FK"), inverseJoinColumns=@JoinColumn(name="TO_MAN_FK"))
      – Arjan
      Jul 2 '10 at 22:31










    • @arjantop: No, this doesn't allow to specify the name of the foreign key constraint. You missed the point.
      – Pascal Thivent
      Jul 2 '10 at 22:38








    • 2




      my bad, i read the question too quickly
      – Arjan
      Jul 3 '10 at 8:27






    • 2




      Hibernate @ForeignKey is deprecated, use JPA annotation instead it.
      – Mohsen Kashi
      Feb 23 '15 at 10:47
















    Arrgggghhhhh. Thanks.
    – HDave
    Jul 2 '10 at 21:59




    Arrgggghhhhh. Thanks.
    – HDave
    Jul 2 '10 at 21:59












    In JPA: @JoinTable(joinColumns=@JoinColumn(name="TO_WOMAN_FK"), inverseJoinColumns=@JoinColumn(name="TO_MAN_FK"))
    – Arjan
    Jul 2 '10 at 22:31




    In JPA: @JoinTable(joinColumns=@JoinColumn(name="TO_WOMAN_FK"), inverseJoinColumns=@JoinColumn(name="TO_MAN_FK"))
    – Arjan
    Jul 2 '10 at 22:31












    @arjantop: No, this doesn't allow to specify the name of the foreign key constraint. You missed the point.
    – Pascal Thivent
    Jul 2 '10 at 22:38






    @arjantop: No, this doesn't allow to specify the name of the foreign key constraint. You missed the point.
    – Pascal Thivent
    Jul 2 '10 at 22:38






    2




    2




    my bad, i read the question too quickly
    – Arjan
    Jul 3 '10 at 8:27




    my bad, i read the question too quickly
    – Arjan
    Jul 3 '10 at 8:27




    2




    2




    Hibernate @ForeignKey is deprecated, use JPA annotation instead it.
    – Mohsen Kashi
    Feb 23 '15 at 10:47




    Hibernate @ForeignKey is deprecated, use JPA annotation instead it.
    – Mohsen Kashi
    Feb 23 '15 at 10:47











    -1














    Normally in an enterprise stack, DBAs will not and should not allow systemic entity creation in their database. They will usually ask for the DDLs to be inserted manually and you will set your Hibernate apps ddl-auto to the update mode and not create or create-drop mode. This is a ideal scenario in most of the brands I worked with. Having said, you can let the DBA decide to rename the Constraints through the alter-table statements that Hibernate will generate for you. Also, the Primary key constraint names will also be managed by DBAs once the Create table DDL is handed over to them.



    If you are in a full stack role where you decide everything, you can only change the Foreign key name with current releases using the @ForeignKey annotation.



    But I would still recommend, manual insertion of DDL statements to your Database rather than allowing a systemic process to take control since maintaining the the Database and de-fragmenting the structure becomes easier if a manual DBA architecture is embraced.



    Hope this answers your question.






    share|improve this answer


























      -1














      Normally in an enterprise stack, DBAs will not and should not allow systemic entity creation in their database. They will usually ask for the DDLs to be inserted manually and you will set your Hibernate apps ddl-auto to the update mode and not create or create-drop mode. This is a ideal scenario in most of the brands I worked with. Having said, you can let the DBA decide to rename the Constraints through the alter-table statements that Hibernate will generate for you. Also, the Primary key constraint names will also be managed by DBAs once the Create table DDL is handed over to them.



      If you are in a full stack role where you decide everything, you can only change the Foreign key name with current releases using the @ForeignKey annotation.



      But I would still recommend, manual insertion of DDL statements to your Database rather than allowing a systemic process to take control since maintaining the the Database and de-fragmenting the structure becomes easier if a manual DBA architecture is embraced.



      Hope this answers your question.






      share|improve this answer
























        -1












        -1








        -1






        Normally in an enterprise stack, DBAs will not and should not allow systemic entity creation in their database. They will usually ask for the DDLs to be inserted manually and you will set your Hibernate apps ddl-auto to the update mode and not create or create-drop mode. This is a ideal scenario in most of the brands I worked with. Having said, you can let the DBA decide to rename the Constraints through the alter-table statements that Hibernate will generate for you. Also, the Primary key constraint names will also be managed by DBAs once the Create table DDL is handed over to them.



        If you are in a full stack role where you decide everything, you can only change the Foreign key name with current releases using the @ForeignKey annotation.



        But I would still recommend, manual insertion of DDL statements to your Database rather than allowing a systemic process to take control since maintaining the the Database and de-fragmenting the structure becomes easier if a manual DBA architecture is embraced.



        Hope this answers your question.






        share|improve this answer












        Normally in an enterprise stack, DBAs will not and should not allow systemic entity creation in their database. They will usually ask for the DDLs to be inserted manually and you will set your Hibernate apps ddl-auto to the update mode and not create or create-drop mode. This is a ideal scenario in most of the brands I worked with. Having said, you can let the DBA decide to rename the Constraints through the alter-table statements that Hibernate will generate for you. Also, the Primary key constraint names will also be managed by DBAs once the Create table DDL is handed over to them.



        If you are in a full stack role where you decide everything, you can only change the Foreign key name with current releases using the @ForeignKey annotation.



        But I would still recommend, manual insertion of DDL statements to your Database rather than allowing a systemic process to take control since maintaining the the Database and de-fragmenting the structure becomes easier if a manual DBA architecture is embraced.



        Hope this answers your question.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 11 '16 at 18:05









        Phoenix Sri

        11




        11






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f3169151%2fcan-i-name-my-constraints-with-jpa%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            Xamarin.form Move up view when keyboard appear

            Post-Redirect-Get with Spring WebFlux and Thymeleaf

            Anylogic : not able to use stopDelay()