Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Not A Problem
-
4.0.M3
-
None
-
None
Description
SQLTemplateAction doesn't consider javaType from #result directive when configurating RowDescriptorBuilder. It put to RowDescriptorBuilder.typeOverrides only types from current ObjEntity and DbEntity.
So the following example doesn't work correctly.
I added Joda DateTimeType provided by John Huss in CAY-1626 to the ExtendedType.
Than I created two DbEntities with fields of TIMESTAMP type and one dependent ObjEntity.
<db-entity name="JODA"> <db-attribute name="DATETIME" type="TIMESTAMP"/> <db-attribute name="ID" type="INTEGER" isPrimaryKey="true" isMandatory="true"/> </db-entity> <db-entity name="JODA1"> <db-attribute name="DATETIME1" type="TIMESTAMP"/> </db-entity> <obj-entity name="Joda" className="org.example.cayenne.persistent.Joda" dbEntityName="JODA"> <obj-attribute name="datetime" type="org.joda.time.DateTime" db-attribute-path="DATETIME"/> </obj-entity>
And I got java.util.Date instead of org.joda.time.DateTime for column DATETIME1 AS D by the code below.
String sql = "SELECT j.ID, " + "#result('j.DATETIME' 'org.joda.time.DateTime' '' 'JODA.DATETIME'), " + "#result('DATETIME1' 'org.joda.time.DateTime' '' 'JODA1.DATETIME1') AS D " + "FROM JODA j, JODA1"; EntityResult jodaResult = new EntityResult(Joda.class); jodaResult.addDbField(Joda.ID_PK_COLUMN, "ID"); jodaResult.addObjectField(Joda.DATETIME_PROPERTY, "DATETIME"); SQLResult resultDescriptor = new SQLResult(); resultDescriptor.addEntityResult(jodaResult); resultDescriptor.addColumnResult("D"); SQLTemplate query = new SQLTemplate(Joda.class, sql); query.setResult(resultDescriptor); List<Object[]> dataList = context.performQuery(query); for (Object[] data : dataList) { System.out.println(data[0].getClass()); System.out.println(data[1].getClass()); }
class org.example.cayenne.persistent.Joda class java.util.Date