-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Parameter index out of range error
PostPosted: Fri Aug 20, 2004 5:17 am 
Beginner
Beginner

Joined: Thu Aug 19, 2004 5:20 am
Posts: 25
Hi

I get the error "java.sql.SQLException: Parameter index out of range (3 > 2)." when i try to save the code below, is there something missing from the many-to-one or one-to-many tag, i have tried cascade and it still doesnt work, it seems that it does not like the many-to-one tag in DDETAILS, because when i take that out it saves correctly, any ideas?


Hibernate version:2.1.3

Mapping documents:
<!--DDETAILS MAPPING-->
<hibernate-mapping>
<class name="DDetails" table="d_details">
<id name="id" column="id" type ="java.lang.Long" unsaved-value="null">
<generator class="native" />
</id>

<property name="value" column="value" not-null="false"/>
<property name="filesInID" column="filesin_id" not-null="false"/>
<many-to-one name="dEpFilesIn" class="DEpFilesIn" column="filesin_id" not-null="false" cascade="all"/>
</class>
</hibernate-mapping>


<!--DEPFILESIN Mapping-->
<hibernate-mapping>
<class name="DEpFilesIn" table="d_epfilesin">
<id name="id" column="id" type ="java.lang.Long" unsaved-value="null">
<generator class="native" />
</id>
<property name="fromId" column="from_id" not-null="true"/>
<bag name="dDetails" inverse="true" lazy="true" cascade="all">
<key column="filesin_id"/>
<one-to-many class="DDetails"/>
</bag>
</class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
DDetails dDetailsObj = (DDetails)it.next();
dDetailsObj.setId(null);
myMachineSession.save(dDetailsObj);
myMachineSession.flush();
myMachineTX.commit();


Full stack trace of any exception that occurs:
java.sql.SQLException: Parameter index out of range (3 > 2).
at com.mysql.jdbc.PreparedStatement.setInternal(PreparedStatement.java:1940)
at com.mysql.jdbc.PreparedStatement.setInternal(PreparedStatement.java:1967)
at com.mysql.jdbc.PreparedStatement.setLong(PreparedStatement.java:522)
at net.sf.hibernate.type.LongType.set(LongType.java:28)
at net.sf.hibernate.type.NullableType.nullSafeSet(NullableType.java:45)
at net.sf.hibernate.type.NullableType.nullSafeSet(NullableType.java:30)
at net.sf.hibernate.type.ManyToOneType.nullSafeSet(ManyToOneType.java:33)
at net.sf.hibernate.persister.EntityPersister.dehydrate(EntityPersister.java:361)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:471)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:719)
at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:607)
at XMLTest.getQuery(XMLTest.java:97)
at XMLTest.main(XMLTest.java:239)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:78)
java.sql.SQLException: Parameter index out of range (16 > 15).
at com.mysql.jdbc.PreparedStatement.setInternal(PreparedStatement.java:1940)
at com.mysql.jdbc.PreparedStatement.setInternal(PreparedStatement.java:1967)
at com.mysql.jdbc.PreparedStatement.setLong(PreparedStatement.java:522)
at net.sf.hibernate.type.LongType.set(LongType.java:28)
at net.sf.hibernate.type.NullableType.nullSafeSet(NullableType.java:45)
at net.sf.hibernate.type.NullableType.nullSafeSet(NullableType.java:30)
at net.sf.hibernate.type.ManyToOneType.nullSafeSet(ManyToOneType.java:33)
at net.sf.hibernate.persister.EntityPersister.dehydrate(EntityPersister.java:361)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:471)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:719)
at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:607)
at XMLTest.getQuery(XMLTest.java:97)
at XMLTest.main(XMLTest.java:239)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:78)
rethrown as net.sf.hibernate.JDBCException: Could not insert: Parameter index out of range (16 > 15).
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:722)
at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:607)
at XMLTest.getQuery(XMLTest.java:97)
at XMLTest.main(XMLTest.java:239)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:78)
Caused by: java.sql.SQLException: Parameter index out of range (16 > 15).
at com.mysql.jdbc.PreparedStatement.setInternal(PreparedStatement.java:1940)
at com.mysql.jdbc.PreparedStatement.setInternal(PreparedStatement.java:1967)
at com.mysql.jdbc.PreparedStatement.setLong(PreparedStatement.java:522)
at net.sf.hibernate.type.LongType.set(LongType.java:28)
at net.sf.hibernate.type.NullableType.nullSafeSet(NullableType.java:45)
at net.sf.hibernate.type.NullableType.nullSafeSet(NullableType.java:30)
at net.sf.hibernate.type.ManyToOneType.nullSafeSet(ManyToOneType.java:33)
at net.sf.hibernate.persister.EntityPersister.dehydrate(EntityPersister.java:361)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:471)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:719)
... 8 more


Name and version of the database you are using:

Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 20, 2004 7:12 am 
Regular
Regular

Joined: Wed Aug 18, 2004 5:16 am
Posts: 69
Location: Modena, Italy
Can you post the source of DEpFilesIn class?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 20, 2004 7:30 am 
Beginner
Beginner

Joined: Thu Aug 19, 2004 5:20 am
Posts: 25
/*Hope this helps*/


import java.util.Calendar;
import java.util.List;
import java.util.Set;

public class DEpFilesIn {
private Long id;
private Integer fromId;
private List dDetails;

public DEpFilesIn () {}

public List getdDetails()
{
return dDetails;
}

public void setdDetails(final List dDetails)
{
this.dDetails = dDetails;
}

public Long getId () {
return id;
}

public void setId (final Long id) {
this.id = id;
}

public Integer getFromId () {
return fromId;
}

public void setFromId (final Integer fromId) {
this.fromId = fromId;
}
}


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 20, 2004 9:03 am 
Regular
Regular

Joined: Wed Aug 18, 2004 5:16 am
Posts: 69
Location: Modena, Italy
You are trying to save a DDetails with dEpFilesIn reference null?

It seems that Hibernate try to set the value for filesin_id, maybe because of the inverse="true" at the other end of the relationship.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 20, 2004 9:10 am 
Beginner
Beginner

Joined: Thu Aug 19, 2004 5:20 am
Posts: 25
DDetails definitely has a valid DEPFILESIN reference and its not null

i tried removing the inverse=true from the DEPFILESIN mapping file and it still throws the same error but the minute i remove the one-to-many relationship from DDETAILS then it works...of course then it doesnt save DEPFILESIN

Any Ideas


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.