Home Wrong mapping in hibernate annotations
Reply: 0

Wrong mapping in hibernate annotations

user2749
1#
user2749 Published in July 23, 2018, 1:45 pm

I get this error, when trying to connect two table via manytomany: ERROR [org.hibernate.tool.hbm2ddl.SchemaUpdate] Unsuccessful: alter table PARAM_TRENDVALUE add constraint FK_TrendValue foreign key (AreaID, PcID, DeviceID, ValueID) references usrIFDBMaster.tblTrdProcessValues 08:44:43,800 ERROR [org.hibernate.tool.hbm2ddl.SchemaUpdate] Die 'usrIFDBMaster.tblTrdProcessValues.DeviceID'-Spalte hat nicht denselben Datentyp wie die verweisende 'PARAM_TRENDVALUE.PcID'-Spalte im 'FK_TrendValue'-Fremdschlüssel.

Principaly hibernate is trying to map the wrong columns.

Param.java:

This is the key:

@EmbeddedId
@AttributeOverrides( {
        @AttributeOverride(name = "pcId", column = @Column(name = "PcID", nullable = false)),
        @AttributeOverride(name = "unitId", column = @Column(name = "UnitID", nullable = false)),
        @AttributeOverride(name = "paramId", column = @Column(name = "ParamID", nullable = false)) })
public ParamId getId() {
    return this.id;
}

This is the mapping:

/**
 * @return the connection
 */
@ManyToMany
@ForeignKey(name = "FK_Param")
@JoinTable(
        name="PARAM_TRENDVALUE",
        inverseJoinColumns={    
                @JoinColumn(name = "PcID", referencedColumnName = "PcID"),
                @JoinColumn(name = "AreaID", referencedColumnName = "AreaID"),
                @JoinColumn(name = "DeviceID", referencedColumnName = "DeviceID"),
                @JoinColumn(name = "ValueID", referencedColumnName = "ValueID")
        }
)
public List<TrendValue> getTrendValues() {
    return trendValues; 
}

Trendvalue.java:

This is the key:

@EmbeddedId
@AttributeOverrides( {
        @AttributeOverride(name = "pcId", column = @Column(name = "PcID", nullable = false)),   
        @AttributeOverride(name = "areaId", column = @Column(name = "AreaID", nullable = false)),
        @AttributeOverride(name = "deviceId", column = @Column(name = "DeviceID", nullable = false)),
        @AttributeOverride(name = "valueId", column = @Column(name = "ValueID", nullable = false))
         })
public TrendValueId getId() {
    return this.id;
}

This is the mapping:

/**
 * @return the params
 */
@ManyToMany(
        mappedBy="trendValues",
        targetEntity=Param.class
    )
@ForeignKey(name = "FK_TrendValue")
public List<Param> getParams() {
    return params;
}

It´s the first manytomany I try to use, and it should work, I already tried without inversejoincolumns, with joincolumns, defining exactly the tables and datatypes in "joincolumns/inversejoincolumns", ... Don't know what else could be the problem.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.303853 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO