[ https://issues.apache.org/jira/browse/METAMODEL-251?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15281425#comment-15281425 ]
Hans Drexler commented on METAMODEL-251: ---------------------------------------- We realize that this would be a drastic change in MetaModel. It would also be possible to add a StrictRow class in addition to Row. The reason why we propose this is twofold: 1. From a JDBC perspective consuming a column that is not in the ResultSet results in a SQLException. Since MetaModel provides a SQL-like abstraction, it could be argued that a similar behaviour should be in place for Row objects 2. When MetaModel returns null, the application can not know wether the database cell was empty (on nullable columns), or if the column was missing from the query object. This can hide bugs in the application. There is a little bit more going on here that we did not mention in this issue. We get spurious (once every 10 million records or so) exceptions in our application, but only when we retrieve a column from the Row that is not a SelectItem in the query. Instead of returning null, the Row appears to return a value from another SelectItem in the query. The types are then wrong, resulting in class cast exceptions (See sample stack trace below). We don't know why this happens, but the problem (so far) never occurs when we only retrieve select items that are in the query. So there could be another bug lurking here. ``` java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Long at com.hi.cdi.DaoHelper.getLongValue(DaoHelper.java:25) at com.hi.cdi.model.internal.MetaModelRowSourceRecord.<init>(MetaModelRowSourceRecord.java:54) ``` We are now checking all uses of MetaModel queries in our application for this. But this is tedious and error-prone. Can you please provide advise on how to proceed? > MetaModel should fail when accessing a column that is not a select item > ----------------------------------------------------------------------- > > Key: METAMODEL-251 > URL: https://issues.apache.org/jira/browse/METAMODEL-251 > Project: Apache MetaModel > Issue Type: Bug > Affects Versions: 4.5.2 > Environment: Postgres > Reporter: Hans Drexler > Attachments: MetaModel251Sample.java > > > In our software, we create a query with SelectItems for 6 out of the 7 > columns of a postgres data base table. We actually forgot to add the seventh > column as a SelectItem. > {code} > query.select(selectItems) > .from(someTable) > {code} > When consuming the rows returned by this query, the code actually fetches the > column that was not a select item, using a construct like: > {code} > row.getValue(table.getColumnByName('foo')); > {code} > This returns null values most of the time. But under stress, the code starts > to throw exceptions. > It would be much better if MetaModel throws an exception when the code > attempts to access a column that is not part of the query (fail fast). -- This message was sent by Atlassian JIRA (v6.3.4#6332)