我尝试通过在 RapidClipse4 中使用本机查询来生成交叉表。
数据已收集并在控制台上输出仍然可用,但分配给 xDevTable 不起作用。
我创建了以下代码:
private void button_buttonClick(final Button.ClickEvent event) {
try {
final String selJahr = this.cmbJahr.getSelectedItem().getBean().getJahr();
final StringBuilder sb = new StringBuilder();
sb.append("select FLOOR(RAND() * 999999) as rid, l1_Id as `l1id`, l1_GroupName as `l1GroupName`, l2_Id as `l2id`, l2_GroupName as `l2GroupName`, ");
sb.append("sum( case when (monat = 1) then dbetrag end ) AS `Jan`, ");
sb.append("sum( case when monat = 2 then dbetrag end ) AS `Feb`, ");
sb.append("sum( case when monat = 3 then dbetrag end ) AS `Mrz`, ");
sb.append("sum( case when monat = 4 then dbetrag end ) AS `Apr`, ");
sb.append("sum( case when monat = 5 then dbetrag end ) AS `Mai`, ");
sb.append("sum( case when monat = 6 then dbetrag end ) AS `Jun`, ");
sb.append("sum( case when monat = 7 then dbetrag end ) AS `Jul`, ");
sb.append("sum( case when monat = 8 then dbetrag end ) AS `Aug`, ");
sb.append("sum( case when monat = 9 then dbetrag end ) AS `Sep`, ");
sb.append("sum( case when monat = 10 then dbetrag end ) AS `Okt`, ");
sb.append("sum( case when monat = 11 then dbetrag end ) AS `Nov`, ");
sb.append("sum( case when monat = 12 then dbetrag end ) AS `Dez`, ");
sb.append("sum(dbetrag) as `Sum` ");
sb.append("from V_HibCrosUmsGiroOpaOmaReport ");
sb.append("where jahr='2019' and konto_Id in ('7,8') ");
sb.append("group by l1_Id, l1_GroupName, l2_Id, l2_GroupName; ");
final String sqlq = sb.toString();
final EntityManagerFactory emf = Persistence.createEntityManagerFactory("RC_07");
final EntityManager em = emf.createEntityManager();
System.out.print( "SQL String: " + sqlq + "/n");
final Query q = em.createNativeQuery(sqlq);
// will be later used:
//q.setParameter(1, selJahr);
//q.setParameter(2, "7,8");
// final List<VUmsCrosstbl> VUmsCrosstbl = q.getResultList();
final XdevBeanItemContainer<VUmsCrosstbl> myContainer = new XdevBeanItemContainer<>(VUmsCrosstbl.class);
myContainer.addAll(q.getResultList());
this.tblUmsCross.setContainerDataSource(myContainer);
this.tblUmsCross.setVisibleColumns(VUmsCrosstbl_.rid.getName(),VUmsCrosstbl_.l1Id.getName(),VUmsCrosstbl_.l1GroupName.getName(),VUmsCrosstbl_.l2Id.getName(),VUmsCrosstbl_.l2GroupName.getName(),VUmsCrosstbl_.jan.getName(),VUmsCrosstbl_.feb.getName(),VUmsCrosstbl_.mrz.getName(),VUmsCrosstbl_.apr.getName(),VUmsCrosstbl_.mai.getName(),VUmsCrosstbl_.jun.getName(),VUmsCrosstbl_.jul.getName(),VUmsCrosstbl_.aug.getName(),VUmsCrosstbl_.sep.getName(),VUmsCrosstbl_.okt.getName(),VUmsCrosstbl_.nov.getName(),VUmsCrosstbl_.dez.getName(),VUmsCrosstbl_.sum.getName());
this.tblUmsCross.setId(VUmsCrosstbl_.rid.getName());
this.tblUmsCross.setColumnHeaders(new String[] {"rid", "l1_Id", "l1_GroupName", "l2_Id", "l2_GroupName", "Jan","Feb","Mrz","Apr","Mai","Jun","Jul","Aug","Sep","Okt","Nov","Dez", "Sum"});
this.tblUmsCross.addItems(q.getResultList());
this.tblUmsCross.getBeanContainerDataSource().refresh();
final List<Object[]> VUmsCrosstbl = q.getResultList();
for (final Object[] a : VUmsCrosstbl) {
System.out.println("Ds: " + a[0] + " " + a[1] + " " + a[2] + " " + a[3] + " " + a[4] + " " + a[5] + " " + a[6] + " " + a[7] + " " + a[8] + " " + a[9] + " " + a[10] + " " + a[11] + " " + a[12] + " " + a[13] + " " + a[14] + " " + a[15]);
}
em.close();
} catch (final Exception e) {
e.printStackTrace();
Notification.show("Do isch was falsch bei button_buttonClick ", e.getMessage(),
Notification.Type.ERROR_MESSAGE);
}
}
该过程在没有任何错误
的情况下运行代码“ System.out.println("Ds: ..." ”末尾的行仅用于检查容器是否有数据。这些行在控制台上打印出完全预期的输出和所有预期的数据
在应用程序中,列(标题)仍然被创建并且可见,但没有包含数据的行。单元格是空的。
我的错误在哪里/我做错了什么?任何想法/帮助将不胜感激。
我想,你也应该知道:
我在查询中使用的表名与实体名称“VUmsCrosstbl”不同
为什么?
我使用的实体名称“VUmsCrosstbl”是一个 db-view,其中包含我作为查询结果集获得的字段。
有了这个技巧,我可以使用 rapidclipse 中的实体构建器,它会自动生成实体和 dao。
对于我在查询中使用的 View V_HibCrosUmsGiroOpaOmaReport,月份名称 Jan-Dez 仍然不在我第一次使用并产生其他错误的实体或 dao 中。
提前谢谢你 rgds OpaHeinz