@Entity
@Table(name = "jobitems")
@IdClass(JobItemId.class)
public class JobItem implements Serializable {
@ManyToOne
@PrimaryKeyJoinColumn(name = "forumId")
private Forum forum;
@ManyToOne
@PrimaryKeyJoinColumn(name = "parsingJobId")
private ParsingJob parsingJob;
@Id
@Column(name = "forumId", insertable = false, updatable = false)
private int forumId;
@Id
@Column(name = "parsingJobId", insertable = false, updatable = false)
private int parsingJobId;
private String server;
private String comments;
/**
* @param forum
* @param parsingJob
*/
public JobItem(Forum forum, ParsingJob parsingjob) {
super();
setForumId(forum.getId());
setParsingJobId(parsingjob.getId());
}
當我創建一個實例並堅持時,我得到以下異常。它說索引超出範圍的參數,所以我想它會嘗試添加6個參數(對於我的6個字段)而不是4個。我是否缺少一些註釋?持續存在的問題實體
任何想法?
我在JBoss 4.2和MySQL
運行錯誤信息如下
2007-07-19 17:19:15,968 DEBUG [org.hibernate.SQL] insert into jobitems (server, comments, forumId, parsingJobId) values (?, ?, ?, ?)
2007-07-19 17:19:15,968 INFO [org.hibernate.type.IntegerType] could not bind value '1' to parameter: 5; Parameter index out of range (5 > number of parameters, which is 4).
2007-07-19 17:19:15,968 DEBUG [org.hibernate.jdbc.AbstractBatcher] about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
2007-07-19 17:19:15,968 DEBUG [org.hibernate.jdbc.ConnectionManager] skipping aggressive-release due to flush cycle
2007-07-19 17:19:15,968 DEBUG [org.hibernate.util.JDBCExceptionReporter] could not insert: [com.vico.software.tools.parsing.entities.JobItem] [insert into jobitems (server, comments, forumId, parsingJobId) values (?, ?, ?, ?)]
java.sql.SQLException: Parameter index out of range (5 > number of parameters, which is 4).
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:910)
at com.mysql.jdbc.PreparedStatement.setInternal(PreparedStatement.java:2740)
at com.mysql.jdbc.PreparedStatement.setInternal(PreparedStatement.java:2771)
at com.mysql.jdbc.PreparedStatement.setInt(PreparedStatement.java:2722)
at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.setInt(WrappedPreparedStatement.java:117)
當我看起來hibernate api,有一個代碼:if(id!= null) id => JobItemId [forumId:2,parsingJobId:1]。 所以它error.i undanstand。 – user397553 2010-07-21 06:44:19
@PrimaryKeyJoinColumn ==> @ JoinColumn, JobItemId ==> forumId ==> @ Column。 沒關係!!!非常好! – user397553 2010-07-21 07:51:45
@ cloud-w如果答案適合您,請將其標記爲已接受。 – Bozho 2010-07-25 14:13:48