java - hibernate 抛出构造函数错误,多个字段

标签 java mysql hibernate constructor

我修改了一个名为 Alignment 的类中的一些工作代码以包含第 4 列。 另一个类在列表中使用对齐方式,因此对齐方式定义为@embedded。在 using 类中,列是使用 AttributeOverrides 定义的。

令人沮丧的是,它在 3 列的原始状态下工作。我添加了第 4 列“来源”并在创建列表时出现此错误:

     demo.admin Fluence 0:0:0:0:0:0:0:1 /ia/secure/assignment/list.action] [36mo.h.engine.jdbc.spi.SqlExceptionHelper
[0;39m : Unknown column 'alignments0_.origin' in 'field list'

10-Oct-2018 14:40:27.571 SEVERE [tomcat-http--3] org.apache.catalina.core.ApplicationDispatcher.invoke Servlet.service() for servlet [jsp] threw exception
 com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'alignments0_.origin' in 'field list'
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)

使用Alignment的列表定义为:

@ElementCollection(fetch = FetchType.EAGER)
@OrderColumn(name = "order_index")
@CollectionTable(
  name = "alignment",
  joinColumns = @JoinColumn(name = "item_id", 
   nullable = false))
@AttributeOverrides({
  @AttributeOverride(name = "guid", column = @Column(name = "guid")),
  @AttributeOverride(name = "setName", column = @Column(name = "set_name")),
  @AttributeOverride(name = "subject", column = @Column(name = "subject")),
  @AttributeOverride(name = "origin", column = @Column(name = "origin"))
 })
@Cache(usage = 
CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public List<Alignment> getAlignments() {
  return this.alignments;
}

Alignment 的构造函数是:

@Embeddable
public class Alignment implements Serializable {

public static String MANUAL = "manual";
public static String AUTO = "auto";

public Alignment() {  }

public Alignment(Standard standard) {
  this.guid = standard.getGuid();
  this.setName = standard.getStandardSet();
  this.subject = standard.getSubjectArea();
  this.origin = AUTO;
}

public Alignment(String guid, String setName, 
  SubjectArea subject) {
  this.guid = guid;
  this.setName = setName;
  this.subject = subject;
  this.origin = AUTO;
}

public Alignment(String guid, String setName, 
  SubjectArea subject, String origin) {
  this.guid = guid;
  this.setName = setName;
  this.subject = subject;
  this.origin = origin;
}

非常令人沮丧,因为 3 元素构造函数工作正常,而 4 元素构造函数却不行。 检索数据的选择不引用此表,因为它是基于上面定义的 hibernate 属性的对齐的嵌入式类。

选择没有改变,原点作为 varchar(10) 添加到对齐表中。

我在这里错过了什么?

最佳答案

所以根本不是hibernate的问题。 Alignment 类嵌入到整个系统的几个类中,它们指向几个不同的表。将原始列添加到这些表中,瞧!一切正常。

现在决定这是不是一个好的设计。

任何人都知道 hibenate 是否有一个重写以在获取时不使用类中的列?

关于java - hibernate 抛出构造函数错误,多个字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52735920/

相关文章:

java - Spring XD - 模块 "source:trigger"无法按预期工作

mysql - 具有现有数据库的 Mariadb 多阶段容器

oracle - 去除外键约束、参照完整性和 hibernate

java - hibernate/C3P0 : Server crashes after MySQL timeout

mysql - 使用 hibernate session 的 saveOrUpdate 方法的奇怪之处

java - 将 Java 移植到 Ruby - 如何处理方法签名重载

java - 为什么 Java 文件必须与其公共(public)类同名?

java - 计算文件中与 String [ ] 中的单词匹配的单词数

java - 如何通过JDBC接口(interface)将UTF-8字符串正确写入MySQL

mysql - 如何估计SQL查询时间?