[jboss-user] [EJB 3.0] - Problem when persisting Entity

philipp.tiedt do-not-reply at jboss.com
Thu Jul 19 11:38:37 EDT 2007


Hi All,

I have an entity with a compound primary key. Each key field again is a foreign key to another entity. 

The entity is implemented like this 

@Entity
  | @Table(name = "jobitems")
  | @IdClass(JobItemId.class)
  | public class JobItem implements Serializable {
  | 
  | 	@ManyToOne
  | 	@JoinColumn(name = "forumId")
  | 	private Forum forum;
  | 
  | 	@ManyToOne
  | 	@JoinColumn(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());
  | 		
  | 	}

I get the following exception when I create an instance and persist the same. It says index out of range for the parameter so I guess it tries to add 6 parameters (for my 6 fields) instead of 4. Am I missing some annotations?

Any Ideas ? 

I run on JBoss 4.2 and MySql

the error message is as follows 

  | 
  | 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)

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4065873#4065873

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4065873



More information about the jboss-user mailing list