我有两个类的两个实体。首先是第二个(Observer模式)的扩展类: 孩子:
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorValue("User")
@Table(name="SCH.USER")
public class User extends Observer implements Serializable{
...fields...
}
父亲:
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn(name = "DISCRIMINATOR", discriminatorType = DiscriminatorType.STRING)
@Table(name="SCH.OBSERVER")
public abstract class Observer implements Serializable{
@Id
@SequenceGenerator(name = "OBSERVER_ID_GENERATOR", sequenceName = "NEXO.SEQ_OBSERVER", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "OBSERVER_ID_GENERATOR")
@Column(name="ID_OBSERVER")
private Long idObserver;
@Column(name = "DISCRIMINATOR", nullable=false, length=20)
private String discriminator;
}
由于我将JPA 2.0升级到JPA 2.1,因此无法保留子实体: em.persist(userInstance); 这会生成下一个SQL:
insert
into
NEXO.OBSERVER
(DISCRIMINATOR, ID_OBSERVER)
values
('User', ?)
得到结果错误:
java.sql.SQLException: invalid column index
我很确定此行为更改是由升级到JPA 2.1
生成的答案 0 :(得分:1)
@Chris是对的。当我从Jboss7升级到Wildfly10时,注意到这个错误并通过更新鉴别器
来修复@Column(name =" INPUT_TYPE",nullable = false,length = 6,insertable = false,updatable = false) public String getInputType(){ return inputType; }
答案 1 :(得分:0)
我遇到了同样的问题:
错误SqlExceptionHelper:146 - 列索引超出范围:2, 列数:1
当我升级JPA版本时,将以下两个属性添加到discriminator列:
insertable = false
和updatable = false
此前这是默认设置。