请各位高手留步,帮小弟一忙.困恼很久了.谢谢

package service;
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Session;
import net.sf.hibernate.Transaction;
import util.HibernateSessionFactory;
import bean.Orders;
public class SelectOrderItem {
static void sec(){
Session session = null ;
try {
session = HibernateSessionFactory.currentSession();
Transaction f = session.beginTransaction();
Orders order=(Orders)session.get(Orders.class,new Integer(27));
System.out.println(order.getCustId());
f.commit();


/*** String hSQL = " from Orders ";
***Query query = session.createQuery(hSQL);
**** Iterator i = query.list().iterator();
***while (i.hasNext()) {
**** Orders order=(Orders )i.next();
*** System.out.println(order.getCustId());
}
****/
} catch (Exception e) {
e.printStackTrace();
} finally {
if (session != null) {
try {
//关闭session
HibernateSessionFactory.closeSession();
} catch (HibernateException hex) {

}} }}

public static void main(String[] args) {
SelectOrderItem.sec();

}
}

[b]配置文件Order.hbm.xml:[/b]<hibernate-mapping package="bean">

<class name="Orders" table="orders" >
<id name="orderId" column="order_id" type="integer">
<generator class="native"/>
</id>
<set
name="orderItems"
table="orderitem"
lazy="true"
inverse="true"
cascade="all"
sort="unsorted" >
<key column="order_id" />
<one-to-many
class="bean.Orderitem"
/>
</set>
<property name="custId" column="cust_id" type="integer" not-null="true" />
<property name="totalprice" column="totalprice" type="float" not-null="true" />
</class>
</hibernate-mapping>

[b]hibernate.cfg.xml:[/b]<hibernate-configuration>

<session-factory>

<!-- mapping files -->
<property name="myeclipse.connection.profile">mysql</property>
<property name="connection.url">
jdbc:mysql://localhost/bookstoressh?useUnicode=true&characterEncoding=gb2312 </property>
<property name="connection.username">root</property>
<property name="connection.password"></property>
<property name="connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="dialect">
net.sf.hibernate.dialect.MySQLDialect
</property>
<property name="show_sql">true</property>
<property name="hibernate.transaction.factory_class">
net.sf.hibernate.transaction.JDBCTransactionFactory
</property>

<mapping resource="bean/Orderitem.hbm.xml" />
<mapping resource="bean/Orders.hbm.xml" />

</session-factory>

</hibernate-configuration>

其他代码都正常,此出略.
[b]如果数据库为ms sql我运行以上代码完全正确,如果数据库为mysql,运行以上注释中的代码完全正确,运行以上未注释代码则会报以下错误:[/b]Hibernate: select orders0_.order_id as order_id0_, orders0_.cust_id as cust_id0_, orders0_.totalprice as totalprice0_ from orders orders0_ where orders0_.order_id=?
net.sf.hibernate.exception.GenericJDBCException: could not load: [bean.Orders#27]
at net.sf.hibernate.exception.ErrorCodeConverter.handledNonSpecificException(ErrorCodeConverter.java:90)
at net.sf.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:79)
at net.sf.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:30)
at net.sf.hibernate.persister.AbstractEntityPersister.convert(AbstractEntityPersister.java:1332)
at net.sf.hibernate.persister.EntityPersister.load(EntityPersister.java:418)
at net.sf.hibernate.impl.SessionImpl.doLoad(SessionImpl.java:2130)
at net.sf.hibernate.impl.SessionImpl.doLoadByClass(SessionImpl.java:2000)
at net.sf.hibernate.impl.SessionImpl.get(SessionImpl.java:1936)
at service.SelectOrderItem.sec(SelectOrderItem.java:16)
at service.SelectOrderItem.main(SelectOrderItem.java:46)
Caused by: java.sql.SQLException: java.lang.ArrayIndexOutOfBoundsException: 6
at com.mysql.jdbc.ServerPreparedStatement.serverExecute(ServerPreparedStatement.java:1150)
at com.mysql.jdbc.ServerPreparedStatement.executeInternal(ServerPreparedStatement.java:804)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1559)
at net.sf.hibernate.impl.BatcherImpl.getResultSet(BatcherImpl.java:88)
at net.sf.hibernate.loader.Loader.getResultSet(Loader.java:875)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:269)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:911)
at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:931)
at net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:59)
at net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:51)
at net.sf.hibernate.persister.EntityPersister.load(EntityPersister.java:415)
... 5 more
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值