休眠引发构造函数错误,多个字段

时间:2018-10-10 08:33:07

标签: java mysql hibernate constructor

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

令人沮丧的是,它在3列的原始状态下工作。我添加了第四列“ origin”,并在创建列表时遇到此错误:

     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)

使用“对齐”的列表定义为:

@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元素构造函数却没有。 检索数据的选择不引用该表,因为它是基于上面定义的休眠属性的Alignment的嵌入式类。

选择未更改,并且原点作为varchar(10)添加到对齐表中。

我在这里想念什么?

1 个答案:

答案 0 :(得分:0)

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

现在要决定这是一个好的设计还是否。

有人知道hibenate是否具有重写权限,以便在获取时不使用类中的列吗?