Ah I see.  Things have changed a bit in 4.1 so I should pay a bit more attention to what's new.  ;-)

Thank you!


On 2018-07-24 02:29 AM, Andrus Adamchik wrote:
Your query is configured to return List<CallLog>, yet the result does not have all the expected 
columns (specifically the PK column - UNIQUEID). That's the cause of the error. You have an option to fetch 
a List<DataRow> by settings "select.setFetchingDataRows(true)". This will get rid of the 
error, but won't still give you a List<String>.

If you want a List<String>, you can do it with SQLTemplate with some extra 
configuration, but I would recommend a more modern SQLSelect. Among other advantages 
of SQLSelect is no ambiguity on the returned result type:


List<String> list = SQLSelect
      .scalarQuery(String.class, "Select distinct VDN_IntoIVR from CallLog")
      .select(CallLogReportMain.getObjectContext());

The docs on SQLSelect and the rest of the "modern" Query API are available here 
[1].

Andrus
[1] https://cayenne.apache.org/docs/4.1/cayenne-guide/#queries

On Jul 23, 2018, at 11:41 PM, Andrew Willerding <[email protected]> 
wrote:

Hi,

I could use some insight as to why I'm getting a CayenneRuntimeException (v.4.1.M1) 
"No PK Column etc. from the code below..

Thanks,

Andrew

Here's the code...

     public static List<String> getVDN_InList() {
         ArrayList<String> list = new ArrayList<>();
         SQLTemplate select = new SQLTemplate(CallLog.class, "Select distinct 
VDN_IntoIVR from CallLog");
         //select.setColumnNamesCapitalization(CapsStrategy.UPPER);
         List<String> list2 = 
CallLogReportMain.getObjectContext().performQuery(select);
         return list;
     }

Executing the actual SQL from the template results in :

MariaDB [CTIData]> Select distinct VDN_IntoIVR from CallLog
     -> ;
+-------------+
| VDN_IntoIVR |
+-------------+
| 5390        |
| 5358        |
| 5356        |
| 5369        |
| 5386        |
| 5273        |
| 5367        |
| 5774        |
| 5284        |
| 5382        |
| 5772        |
| 5371        |
| 5287        |
| 5370        |
| 5362        |
| 5281        |
+-------------+
16 rows in set (0.00 sec)

Here's the extract from the DataMap files...

     <db-entity name="CallLog" catalog="CTIData">
  ...
         <db-attribute name="TRANSCODE" type="VARCHAR" length="30"/>
         <db-attribute name="UNIQUEID" type="VARCHAR" isPrimaryKey="true" isMandatory="true" 
length="20"/>
         <db-attribute name="UPDATEDBY" type="VARCHAR" length="35"/>
         <db-attribute name="VDN_IntoIVR" type="VARCHAR" length="16"/>
    ...

     </db-entity>

Here's the resultant MariaDB table output extract:

MariaDB [CTIData]> describe CallLog;
+------------------+--------------+------+-----+---------+-------+
| Field            | Type         | Null | Key | Default | Extra |
+------------------+--------------+------+-----+---------+-------+
...
| TRANSCODE        | varchar(30)  | YES  |     | NULL    |       |
| UNIQUEID         | varchar(20)  | NO   | PRI | NULL    |       |
| UPDATEDBY        | varchar(35)  | YES  |     | NULL    |       |
| VDN_IntoIVR      | varchar(16)  | YES  |     | NULL    |       |
...
+------------------+--------------+------+-----+---------+-------+

MariaDB [CTIData]> show index from CallLog where Key_name = 'PRIMARY';
+---------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table   | Non_unique | Key_name | Seq_in_index | Column_name | Collation | 
Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+---------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| CallLog |          0 | PRIMARY  |            1 | UNIQUEID    | A         |    
     100 |     NULL | NULL   |      | BTREE |         |               |
+---------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
1 row in set (0.00 sec)

MariaDB [CTIData]> select * from AUTO_PK_SUPPORT;
+------------------------------------------+---------+
| TABLE_NAME                               | NEXT_ID |
+------------------------------------------+---------+
...
| CallLog                                  |     200 |
...

And here is the exception stack....

org.apache.cayenne.CayenneRuntimeException: [v.4.1.M1 Oct 06 2017 09:23:31] No 
PK column 'UNIQUEID' found in data row.
     at 
org.apache.cayenne.access.ObjectResolver.createObjectId(ObjectResolver.java:218)
     at 
org.apache.cayenne.access.ObjectResolver.objectFromDataRow(ObjectResolver.java:133)
     at 
org.apache.cayenne.access.ObjectResolver.objectsFromDataRows(ObjectResolver.java:119)
     at 
org.apache.cayenne.access.ObjectResolver.synchronizedObjectsFromDataRows(ObjectResolver.java:99)
     at 
org.apache.cayenne.access.ObjectResolver.synchronizedRootResultNodeFromDataRows(ObjectResolver.java:90)
     at 
org.apache.cayenne.access.DataDomainQueryAction$ObjectConversionStrategy.toResultsTree(DataDomainQueryAction.java:637)
     at 
org.apache.cayenne.access.DataDomainQueryAction$SingleObjectConversionStrategy.convert(DataDomainQueryAction.java:687)
     at 
org.apache.cayenne.access.DataDomainQueryAction.interceptObjectConversion(DataDomainQueryAction.java:501)
     at 
org.apache.cayenne.access.DataDomainQueryAction.execute(DataDomainQueryAction.java:130)
     at 
org.apache.cayenne.access.DataDomain.onQueryNoFilters(DataDomain.java:564)
     at 
org.apache.cayenne.access.DataDomain$DataDomainQueryFilterChain.onQuery(DataDomain.java:748)
     at 
org.apache.cayenne.tx.TransactionFilter.onQuery(TransactionFilter.java:49)
     at 
org.apache.cayenne.access.DataDomain$DataDomainQueryFilterChain.onQuery(DataDomain.java:748)
     at org.apache.cayenne.access.DataDomain.onQuery(DataDomain.java:556)
     at 
org.apache.cayenne.util.ObjectContextQueryAction.runQuery(ObjectContextQueryAction.java:406)
     at 
org.apache.cayenne.util.ObjectContextQueryAction.executePostCache(ObjectContextQueryAction.java:107)
     at 
org.apache.cayenne.util.ObjectContextQueryAction.execute(ObjectContextQueryAction.java:94)
     at org.apache.cayenne.access.DataContext.onQuery(DataContext.java:965)
     at org.apache.cayenne.access.DataContext.performQuery(DataContext.java:954)
     at 
com.callistacti.quest.CTIData.database.CallLog.getVDN_InList(CallLog.java:47)


Reply via email to