简体   繁体   English

如何迭代列表 <ClassUsingEntityAnnotationOfSpring> ?

[英]How to iterate a list <ClassUsingEntityAnnotationOfSpring>?

I am trying to iterate a list of (Users) and I am receiving this error: 我正在尝试迭代(用户)的列表,并且收到此错误:

 java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to br.com.meupacote.model.Usuario at 

Users is a class with @Entity annotattion. 用户是带有@Entity注释的类。 It's a table of my database. 这是我的数据库表。

I trying to interate this 2 forms: 我试图插入这两种形式:

 List<Deg> lista = new ArrayList<Deg>(); degV.forEach(d -> { Deg dgust = Degustacao.builder().codProduto(d.getId().getCodProduto()) .dataInicio(d.getDtaInicio()) .dataFim(d.getDtaFim()).build(); lista.add(dgust); }); for (Usuario d : degV) { Deg dgust = Degustacao.builder().codProduto(d.getId().getCodProduto()) .dataInicio(d.getDtaInicio()) .dataFim(d.getDtaFim()).build(); lista.add(dgust); } 

Sorry for my english. 对不起我的英语不好。

Thanks in advance. 提前致谢。

The problem is that I was not returning a Usuario List in the method that accessed my table. 问题是我没有在访问表的方法中返回Usuario列表。 Since u was only selecting a few columns, I was returning an object list, so the cast error. 由于您仅选择了几列,因此我返回了一个对象列表,因此出现了强制转换错误。 I solved the problem by returning all the fields of the tables and selecting only the ones I wanted during the iteration to build the Deg obj. 我通过返回表的所有字段并仅选择我在迭代期间构建Deg obj所需的字段来解决了该问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM