Hibernate 5.3.1 SQL错误:列索引超出范围:4,列数:3

时间:2018-09-10 10:54:56

标签: hibernate jointable jpa-2.1

为什么Hibernate不正确地绑定我的值参数?如对unresolved HHH-8020 issue的评论,当Hibernate 5.3.1的定义是以连接的HHH000346命名时,SQLState: 22023仍然给我一个错误(@JoinTable@Entity)本身(恰好有一个复合@EmbeddedId,其中一个属性在@JoinColumn(name="ref_name")joinColumns={..}中都被称为inverseJoinColumns={..}):

@Embeddable
public class MyCompositeId
{ 
    @Column(name = "ref_name") 
    private String name; 

    @Column(name = "partial_id") 
    private Integer id; 

    @Column(name = "extension_id") 
    private String extensionId; 
}

interface MyLinkedEntity { }

@Entity
@Table(name = "my_join_table")
class MyLinkedEntityImpl implements MyLinkedEntity
{ 
    @EmbeddedId 
    private MyCompositeId id; 

    @Column(name = "extension_value") 
    private byte[] extensionValue; 
}

@Entity
class MyEntry {

    @Id
    @Column(name = "name")
    private String name;

    @OneToMany(fetch = FetchType.EAGER, targetEntity = MyLinkedEntityImpl.class, cascade = CascadeType.ALL)
    @JoinTable(name = "my_join_table", 
        joinColumns = @JoinColumn(name = "ref_name", insertable = false, updatable = false),
        inverseJoinColumns = { 
            @JoinColumn(name = "extension_id", referencedColumnName = "extension_id"), 
            @JoinColumn(name = "partial_name", referencedColumnName = "partial_name"), 
            @JoinColumn(name = "ref_name", referencedColumnName = "ref_name"), 
        })
    private Set<MyLinkedEntity> linkedEntities = new HashSet<>();
}

我的日志显示MyLinkedEntity首先被完全保留(冗余),然后再次是关系映射(即没有extension_value列)和{{1}的重复/错误值绑定}(相反)联接列:

ref_name

带有堆栈跟踪代码段:

DEBUG - insert into my_join_table (extension_value, partial_id, extension_id, ref_name) values (?, ?, ?, ?) [at o.h.SQL.logStatement(SqlStatementLogger.java:94)]
TRACE - binding parameter [1] as [VARBINARY] - [[11, 12, 13, 14, 15]] [at o.h.t.d.s.BasicBinder.bind(BasicBinder.java:65)]
TRACE - binding parameter [2] as [INTEGER] - [3] [at o.h.t.d.s.BasicBinder.bind(BasicBinder.java:65)]
TRACE - binding parameter [3] as [VARCHAR] - [B] [at o.h.t.d.s.BasicBinder.bind(BasicBinder.java:65)]
TRACE - binding parameter [4] as [VARCHAR] - [VWS1] [at o.h.t.d.s.BasicBinder.bind(BasicBinder.java:65)]
:
DEBUG - insert into my_join_table (ref_name, partial_id, extension_id) values (?, ?, ?) [at o.h.SQL.logStatement(SqlStatementLogger.java:94)]
TRACE - binding parameter [1] as [VARCHAR] - [VWS1] [at o.h.t.d.s.BasicBinder.bind(BasicBinder.java:65)]
TRACE - binding parameter [2] as [INTEGER] - [3] [at o.h.t.d.s.BasicBinder.bind(BasicBinder.java:65)]
TRACE - binding parameter [3] as [VARCHAR] - [B] [at o.h.t.d.s.BasicBinder.bind(BasicBinder.java:65)]
TRACE - binding parameter [4] as [VARCHAR] - [VWS1] [at o.h.t.d.s.BasicBinder.bind(BasicBinder.java:65)]
WARN - SQL Error: 0, SQLState: 22023 [at o.h.e.j.s.SqlExceptionHelper.logExceptions(SqlExceptionHelper.java:129)]
ERROR - The column index is out of range: 4, number of columns: 3. [at o.h.e.j.s.SqlExceptionHelper.logExceptions(SqlExceptionHelper.java:131)]
ERROR - HHH000346: Error during managed flush [org.hibernate.exception.DataException: could not insert collection: test.MyEntry.keys#ID] [at o.h.i.ExceptionMapperStandardImpl.mapManagedFlushFailure(ExceptionMapperStandardImpl.java:39)]

0 个答案:

没有答案