我修改了一个名为alignment的类中的一些工作代码,以包含第4列。alignment在列表中由另一个类使用,因此alignment被定义为@embedded。在using类中,列是使用attributeoverrides定义的。
令人沮丧的是,它在3列的原始状态下工作。我添加了第4列“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元素构造器却不是。检索数据的select不引用此表,因为它是基于上面定义的hibernate属性对齐的嵌入式类。
选择尚未更改,原点已作为varchar(10)添加到对齐表中。
我错过了什么?
1条答案
按热度按时间ej83mcc01#
所以这根本不是冬眠的问题。alignment类嵌入到整个系统的几个类中,它们指向几个不同的表。把origin列添加到这些表中,瞧!一切正常。
现在来决定这是不是一个好的设计。
有人知道hibenate是否有一个重写,在获取时不使用类中的列吗?