2

我正在尝试将ListHibernate 返回的转换为UserDetails[]数组,如下所示:

SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
Session session = sessionFactory.openSession();
session.beginTransaction();
List<UserDetails[]> oo = session.createSQLQuery("SELECT * FROM `userdetails` WHERE 1 ").list();
System.out.println(oo.size()); // Until here it works fine and it shows me the rows I asked in my query.
UserDetails[]us = oo.toArray(new UserDetails[oo.size()]); // Here it throws java.lang.ArrayStoreException
session.close();

但是,它会抛出一个java.lang.ArrayStoreException. 这是如何引起的,我该如何解决?

4

2 回答 2

0

您可以直接打印列表:

for(UserDetails list: oo){
    System.out.println("Result"+ list.toString());
}

或获取具体数据

for(UserDetails list: oo){
    System.out.println("Result"+ list.getId());
}
于 2013-01-07T13:46:18.630 回答
0

该错误表明已尝试将错误类型的对象存储到对象数组中。请参阅http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/ArrayStoreException.html

于 2013-01-07T13:48:36.527 回答