gpt4 book ai didi

java - Hibernate在列重命名后生成旧查询

转载 作者:行者123 更新时间:2023-12-02 08:27:21 25 4
gpt4 key购买 nike

我已重命名数据库中的列(从configuration_SYSTEM_ID 到SYSTEM_ID),并将AttributeOverride 注释添加到我的AbstractSubConfiguration 类中。但 hibernate 忽略此注释并继续使用旧列名(configuration_SYSTEM_ID 而不是 SYSTEM_ID)生成查询。

我的类(class)如下所示:

AbstractSubConfiguration.java

       @MappedSuperclass
@IdClass(Configuration.class)
public class AbstractSubConfiguration implements Dto, Serializable {
private static final long serialVersionUID = -6271877313478924753L;

@Id
@OneToOne(fetch = FetchType.LAZY)
@AttributeOverride(name = "systemId", column = @Column(name = "SYSTEM_ID"))
private Configuration configuration;

public AbstractSubConfiguration() {
super();
}

public AbstractSubConfiguration(final Configuration configuration) {
super();
this.configuration = configuration;
}

@XmlTransient
public final Configuration getConfiguration() {
return configuration;
}

public final void setConfiguration(final Configuration configuration) {
this.configuration = configuration;
}

}

配置.java

    Entity(name = "CONFIGURATION")
public class Configuration implements Dto, Serializable {
private static final long serialVersionUID = 6601197795258837065L;

@EmbeddedId
private ConfigurationId configurationId;

@Column(name = "CONFIGURATION_NAME")
private String configurationName;

@OneToOne(cascade = CascadeType.PERSIST, mappedBy = "configuration", fetch = FetchType.EAGER)
private BasicConfiguration basicConfiguration;
@OneToOne(cascade = CascadeType.PERSIST, mappedBy = "configuration", fetch = FetchType.EAGER)
private AdvancedConfiguration advancedConfiguration;

.....


...
}

配置Id.java

@Embeddable
public class ConfigurationId implements Serializable {
private static final long serialVersionUID = -5123943430808049180L;

private SystemId systemId;
@Column(name = "CONFIGURATION_ID")
private int configurationId;

public ConfigurationId(final SystemId systemId, final int configurationId) {
super();
this.systemId = systemId;
this.configurationId = configurationId;
}
....

....
}

因此,我收到错误 2695 [main] ERROR org.hibernate.engine.jdbc.spi.SqlExceptionHelper - “字段列表”中的未知列“tes0_.configuration_SYSTEM_ID”

最佳答案

来自文档 @AttributeOverride

java.lang.String name (Required) The name of the property whose mapping is being overridden if property-based access is being used, or the name of the field if field-based access is used.

在您的映射中,我没有看到 systemId 属性,而是看到 configurationId 属性

编辑

根据@AttributeOverride中的编辑名称应该是configuration.systemId

参见 java doc 中的示例带邮政编码:

@Embeddable public class Address {
protected String street;
protected String city;
protected String state;
@Embedded protected Zipcode zipcode;
}

@Embeddable public class Zipcode {
protected String zip;
protected String plusFour;
}

@Entity public class Customer {
@Id protected Integer id;
protected String name;
@AttributeOverrides({
@AttributeOverride(name="state",
column=@Column(name="ADDR_STATE")),
@AttributeOverride(name="zipcode.zip",
column=@Column(name="ADDR_ZIP"))
})
@Embedded protected Address address;
...
}

关于java - Hibernate在列重命名后生成旧查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31782087/

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