hibernate - how to set ForeignKey name when I have @ManyToMany -
I am creating a database using JPA classes.
If we have many of us relations, we can override the names of foreign names like this:
@ManyToOne @JoinColumn ( Foreign = @forganiki (name = "FK_ COUNTRY")) Private country country; In DB, we will have the following result:
OK, this is good results!
But when I have @ManyToMany, I will not manage to set my own FK name.
How can I make it? I try something like this, but it does not work:
@ManyToMany (waterfall = CascadeType.PERSIST, fetch = FetchType.LAZY) @JoinTable (name = "NEW_TABLE", ForeignKey = @ForeignKey (name = "FK_TEST")) Or something like this:
@JoinTable (name = "NEW_TABLE", joinColumns = @ JoinColumn (name = "ID1", referenced ColumnName = "id", foreignKey = @ForeignKey (name = "FK_DEV_ID")), inverseJoinColumns = id2 ", referenced ColumnName =" id ", foreignKey = @ForeignKey (name =" FK_DEV_ZONE ") )) or this:
@ManyToMany (waterfall = CascadeType.PERSIST) @JoinTable (name = "NEW_TABLE_2", joinColumns = @JoinColumn (name = "ID1", referenced ColumnName = "id", foreignKey = @ForeignKey (name = "FK_1"), inve (Name = "FK_2" "FK_2")) from the private list & lt; MyObject & gt; DeviceZones; They do not work.
I use this version of jar:
& lt; Dependency & gt; & Lt; Group & gt; Org.hibernate & lt; / Group & gt; & Lt; ArtifactId & gt; Hibernate-entitymanager & lt; / ArtifactId> & Lt; Version & gt; 4.3.6.Final & lt; / Edition & gt; & Lt; / Dependencies & gt; & Lt; Dependency & gt; & Lt; Group & gt; Org.hibernate & lt; / Group & gt; & Lt; ArtifactId & gt; Hibernate core & lt; / ArtifactId> & Lt; Version & gt; 4.3.6.Final & lt; / Edition & gt; & Lt; / Dependencies & gt; & Lt; Dependency & gt; & Lt; Group & gt; Org.hibernate.common & lt; / Group & gt; & Lt; ArtifactId & gt; Hibernate-Commons-Annotation & lt; / ArtifactId> & Lt; Version & gt; 4.0.5.Final & lt; / Edition & gt; & Lt; / Dependencies & gt; & Lt; Dependency & gt; & Lt; Group & gt; Org.hibernate & lt; / Group & gt; & Lt; ArtifactId & gt; Hibernate Verifier & lt; / ArtifactId> & Lt; Version & gt; 5.1.2.Final & lt; / Edition & gt; & Lt; / Dependencies & gt; & Lt; Dependency & gt; & Lt; Group & gt; Org.springframework & lt; / Group & gt; & Lt; ArtifactId & gt; Spring-JDBC & lt; / ArtifactId> & Lt; Version & gt; 4.0.6.RELEASE & lt; / Edition & gt; & Lt; / Dependencies & gt; and my Java version is 1.8
I think that I suggest doing this:
- Remove the following jar: Hibernate-Commons-Annotation and Hibernate-Enterprise Manager
- Check that you're foreign How to change the name of the key
Comments
Post a Comment