我已经定义了3个类,如下所示: 我试图在MySQL中生成模式。 它不会成功。但有线的事情是我重命名了一个类,CerifLink ---> MyLink,它可以工作。
任何人都可以给出合理的解释吗?
package org.epos.grdb.jpa.entity;
import java.io.Serializable;
import javax.persistence.ConstraintMode;
import javax.persistence.Entity;
import javax.persistence.ForeignKey;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
@Entity
public class CerifLink implements Serializable {
/**
*
*/
private static final long serialVersionUID = -9162577962410473641L;
@Id
@ManyToOne
@JoinColumns(value = { @JoinColumn(referencedColumnName = "id"),
@JoinColumn(referencedColumnName = "cfid") }, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, foreignKeyDefinition = "foreign key (`cfClassId`) references `cfClass` (`cfClassId`)"))
private Class clazz;
public Class getClazz() {
return clazz;
}
public void setClazz(Class clazz) {
this.clazz = clazz;
}
}
package org.epos.grdb.jpa.entity;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
public class MyEntity implements Serializable {
/**
*
*/
private static final long serialVersionUID = 5185624925049306788L;
@Id
protected String id;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
}
package org.epos.grdb.jpa.entity;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
@Entity
public class Class implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1573828246619342971L;
@Id
protected String id;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
@Id
@ManyToOne
@JoinColumn(name = "cfid", referencedColumnName = "id")
private MyEntity classSchema;
public MyEntity getClassSchema() {
return classSchema;
}
public void setClassSchema(MyEntity classSchema) {
this.classSchema = classSchema;
}
}
但有线的事情是在我重命名了一个类,CerifLink ---> MyLink之后,它可以工作。
任何人都可以给出合理的解释吗?
答案 0 :(得分:2)
是的类名很重要,你应该检查一下Hibernate的NamingStrategy,你可以根据你正在使用的hibernate版本来修改它,但是对于你在做什么我想你可以使用注释表并指定一个特定的名称
@Table(name =" myname")