而不是重复这个问题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;
上述两个实体类都扩展了一个mappedSuperclass。
@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();
}
我说错了:
严重程度:参数指数超出范围(8 >参数数,即7)。2015年3月25日8:06:35 AM org.hibernate.event.def.AbstractFlushingEventListener performExecutions performExecutions:无法将数据库状态与会话org.hibernate.exception.GenericJDBCException同步:无法插入: com.salt.entity.SaltTranUser at org.hibernate.exception.GenericJDBCException引起的: java.sql.SQLException:参数索引超出范围(8 >参数数,即7)。在com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)
发布于 2015-03-25 05:30:41
这类问题几乎总是与双列映射有关。而且确实如此。我们可以看到,这个映射使用一个列(两次"salt_id"
)
SaltTranUser
实体类:
@Id
@Column(name="salt_id")
private Integer saltId;
...
@ManyToOne
@JoinColumn(name="salt_id")
private SaltTranDef saltTranDef;
这是错误的。Hibernate在末尾插入一列两次,即插入、更新中的参数比列多。
这里的解决方案可能非常简单--因为@ManyToOne
似乎是错误的。我希望有一些特别的专栏供参考,如:SaltTranDef_id
发布于 2017-10-31 06:50:42
当我使用单向映射(包含子类的父类,但子类不保留父类的引用)时,我也遇到了同样的问题。地图看起来就像
@OneToMany(cascade = CascadeType.ALL, fetch=FetchType.EAGER, orphanRemoval = true)
@JoinColumn(name="jobcard_id", nullable=false)
private List<JobServiceMapping> services;
误差参数指数超出了范围。然后,我稍微修改了注释,现在它对我起作用了。
@OneToMany(mappedBy="jobcardId", cascade = CascadeType.ALL, fetch=FetchType.EAGER, orphanRemoval = true)
private List<JobServiceMapping> services;
发布于 2016-09-07 13:49:22
在我的例子中,问题是关于user_type
字段的。它被定义为歧视者和公共财产。它没有被标记为@Column
,但无论如何Hibernate在这方面失败了
@Entity
@Table(
name = "abstract_users",
indexes = {@Index(name = "idx__abstract_users__is_enabled", columnList = "is_enabled")}
)
@Access(AccessType.FIELD)
@Inheritance(strategy = InheritanceType.JOINED)
// @TODO: rename user_type to discriminator
@DiscriminatorColumn(name = "user_type", discriminatorType = DiscriminatorType.STRING, length = 10)
abstract public class AbstractUser extends CreateUpdateTimestampableBase
{
// @TODO: rename user_type to discriminator
public String user_type;
@Min(0)
@NotNull
@Column(precision = 19, scale = 2)
protected BigDecimal balance;
//...
}
https://stackoverflow.com/questions/29246707
复制相似问题