JPA m:n tables unique fields

7 views
Skip to first unread message

Florian Degenhardt

unread,
May 11, 2017, 4:34:50 AM5/11/17
to minuteproject
Hello
we have the problem, that the generator always UNIQUE Flag on ForeignKey Column on Mysql tables.
Thats wrong. ForeignKey Column doesnt havae a UNIQUE Index!


Example Ouput sql

....
CREATE TABLE `User` (
   
UserID             INTEGER NOT NULL,
   Passwordresettoken VARCHAR(255),
   UserAvatarimage    VARCHAR(255),
   UserCity           VARCHAR(75),
   UserCountry        VARCHAR(5),
   UserEmail          VARCHAR(255),
   UserFirstname      VARCHAR(255),
   UserLocale         VARCHAR(5),
   UserPassword       VARCHAR(255),
   UserPreferences    LONGTEXT,
   UserStatus         VARCHAR(255),
   UserStreet         VARCHAR(255),
   UserSurname        VARCHAR(255),
   UserType           VARCHAR(8),
   UserZip            VARCHAR(10),
   PRIMARY KEY (UserID)
)

CREATE TABLE
`Filter` (
   
FilterID      INTEGER NOT NULL,
   FilterContent LONGTEXT,
   FilterGlobal  TINYINT(1) DEFAULT 0,
   FilterTitle   VARCHAR(255),
   UserID        INTEGER UNIQUE ,
   PRIMARY KEY (FilterID)
)
....

Generate Entity Class

...
//MP-MANAGED-UPDATABLE-ENDING

    @ManyToOne (fetch=FetchType.LAZY )
   
@JoinColumn(name="UserID", referencedColumnName = "UserID" , nullable=true , unique=true , insertable=true, updatable=true)
   
private User userid;

    @Column(name="UserID"  , nullable=true , unique=true, insertable=false, updatable=false)
   
private Integer userid_;

    /**
    * Default constructor
    */
    public Filter() {
   
}
.....

We have workaround with setting the "unique" flag alwas to false in the file
DomainEntityJPA2Annotation.vm


Reply all
Reply to author
Forward
0 new messages