gpt4 book ai didi

java - hibernate :参数索引超出范围(8>参数数量,即7)

转载 作者:行者123 更新时间:2023-12-04 17:08:53 25 4
gpt4 key购买 nike

不是这个问题的重复Parameter index out of range (8 > number of parameters, which is 7)

我的SaltTranDef实体类别是

@Id
@Column(name="salt_id")
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Integer saltId;

@Column(name="tran_type")
private String transactionType;

@Column(name="user_id")
private String userId;

@Column(name="parent_system")
private String parentSystem;

@Column(name="parent_sys_ref_id")
private String parentSystemReference;

@Column(name="status")
private int status;

@OneToMany(mappedBy = "saltTranDef")
@Cascade({ org.hibernate.annotations.CascadeType.ALL,
org.hibernate.annotations.CascadeType.DELETE_ORPHAN })
private Set<SaltTranUser> saltTranUsers;

SaltTranUser实体类别为
@Id
@Column(name="salt_id")
private Integer saltId;

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

@Column(name="salt_value")
private String saltValue;

@ManyToOne
@JoinColumn(name="salt_id")
private SaltTranDef saltTranDef;

上面的两个实体类都扩展了mappingSuperclass
@Column(name="cre_suid")
private String creatorId;

@Column(name="mod_suid")
private String modifiedId;

@Column(name="cre_date")
private Timestamp creationDate;

@Column(name="mod_date")
private Timestamp modificationDate;

从JUnit插入时:
@Test
public void testInsert(){

SaltTranDef std = new SaltTranDef();
SaltTranUser stu1 = new SaltTranUser();
SaltTranUser stu2 = new SaltTranUser();
SaltTranUser stu3 = new SaltTranUser();
Set<SaltTranUser> set1 = new HashSet<SaltTranUser>();

Transaction tx = session.beginTransaction();

std.setParentSystem("A");
std.setParentSystemReference("123");
std.setStatus(10);
std.setTransactionType("A");
std.setUserId("1234");
std.setCreationDate(new Timestamp(new Date().getTime()));
std.setCreatorId("1234");

session.persist(std);
// session.flush();

stu1.setCreationDate(new Timestamp(new Date().getTime()));
stu1.setCreatorId("1234");
stu1.setSaltProp("Fname");
stu1.setSaltValue("Swateek");
stu1.setSaltId(std.getSaltId());

stu2.setCreationDate(new Timestamp(new Date().getTime()));
stu2.setCreatorId("1234");
stu2.setSaltProp("Lname");
stu2.setSaltValue("Jena");
stu2.setSaltId(std.getSaltId());

stu3.setCreationDate(new Timestamp(new Date().getTime()));
stu3.setCreatorId("1234");
stu3.setSaltProp("Phone");
stu3.setSaltValue("9900056668");
stu3.setSaltId(std.getSaltId());

set1.add(stu1);
set1.add(stu2);
set1.add(stu3);

std.setSaltTranUsers(set1);

session.save(std);
tx.commit();
}

我收到一条错误消息:

SEVERE: Parameter index out of range (8 > number of parameters, which is 7). Mar 25, 2015 8:06:35 AM org.hibernate.event.def.AbstractFlushingEventListener performExecutions SEVERE: Could not synchronize database state with session org.hibernate.exception.GenericJDBCException: could not insert: [com.salt.entity.SaltTranUser] at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103) Caused by: java.sql.SQLException: Parameter index out of range (8 > number of parameters, which is 7). at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)

最佳答案

这种问题几乎总是与双列映射有关。的确如此。我们可以看到,此映射两次使用一列两次 "salt_id" :
SaltTranUser实体类:

@Id
@Column(name="salt_id")
private Integer saltId;
...

@ManyToOne
@JoinColumn(name="salt_id")
private SaltTranDef saltTranDef;

那是错误的。 Hibernate最后将两次插入到一列中,即在INSERT,UPDATE列中添加更多的参数

这里的解决方案很可能非常简单-因为 @ManyToOne似乎是错误的。我希望有一些特殊的列可供引用,例如: SaltTranDef_id

关于java - hibernate :参数索引超出范围(8>参数数量,即7),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29246707/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com