gpt4 book ai didi

java - ORM 过程中类名重要吗?

转载 作者:行者123 更新时间:2023-11-30 02:08:22 25 4
gpt4 key购买 nike

我定义了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,它起作用了。

谁能给个合理的解释吗?

最佳答案

是的,类名很重要,你应该检查Hibernate的NamingStrategy,你可以根据你使用的hibernate版本修改它,但是你在做什么我想你可以使用注释表并分配一个特定的名称

@Table(name = "我的名字")

关于java - ORM 过程中类名重要吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50801140/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com