簡體   English   中英

休眠引發構造函數錯誤,多個字段

[英]hibernate throwing constructor error, multiple fields

我在名為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;
}

對齊的構造函數是:

@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)添加到對齊表中。

我在這里想念什么?

因此,這根本不是一個冬眠的問題。 Alignment類嵌入在整個系統的幾個類中,它們指向幾個不同的表。 將原始列添加到這些表中,瞧! 一切正常。

現在確定這是一個好的設計還是沒有。

有人知道hibenate是否具有重寫權限,以便在獲取時不使用類中的列嗎?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM