You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Borut Bolčina <bo...@gmail.com> on 2010/10/13 11:02:51 UTC
Relationship not set (NULL)
Hello,
one of my relationships is not set and I can not find an explanation.
I fetch two objects from shared data context and create local copies.
MapObjectType mot =
persistenceService.findMapObjectType(MapObjectTypeEnum.STREET);
MapObjectType localMot = (MapObjectType)
dataContext.localObject(mot.getObjectId(), mot);
Town town = persistenceService.findTownByMid(townMid);
Town localTown = (Town)
dataContext.localObject(town.getObjectId(), town);
I create two new objects
MapObject mapObject = dataContext.newObject(MapObject.class);
Street street = dataContext.newObject(Street.class);
Now I set the relationships (and some attributes, but ommited here):
street.setTown(localTown);
mapObject.setStreet(street);
mapObject.setMapObjectType(localMot);
but when commited, the town_mid is NULL
[access.QueryLogger:logQuery]: INSERT INTO maps.street (mid, name, town_mid)
VALUES (?, ?, ?)
[access.QueryLogger:logQueryParameters]: [bind: 1->mid:19568962,
2->name:'Ulica Milana Klemenčiča', 3->*town_mid:NULL*]
I printed out all the objects in the data context in the log file Any
idea???
Here is the log file:
[2010/10/13 10:34:47.723] INFO [access.QueryLogger:logQueryStart]: --- will
run 1 query.
[access.QueryLogger:logBeginTransaction]: --- transaction started.
[access.QueryLogger:logQuery]: SELECT t0.id, t0.type FROM
maps.map_object_type t0 WHERE t0.type = ? [bind: 1->type:STREET=3]
[access.QueryLogger:logSelectCount]: === returned 1 row. - took 2 ms.
[access.QueryLogger:logCommitTransaction]: +++ transaction committed.
[access.QueryLogger:logQueryStart]: --- will run 1 query.
[access.QueryLogger:logBeginTransaction]: --- transaction started.
[access.QueryLogger:logQuery]: SELECT t0.name, t0.id, t0.mid, t0.label_y,
t0.label_x FROM maps.town t0 WHERE t0.mid = ? [bind: 1->mid:10083931]
[access.QueryLogger:logSelectCount]: === returned 1 row. - took 4 ms.
[access.QueryLogger:logCommitTransaction]: +++ transaction committed.
[AppModule.ImportService:importStreetsData]: localTown: {<ObjectId:Town,
id=208>; committed; [name=>Ajdovščina; mapObjects=>(..); streets=>(..);
mid=>10083931; labelY=>85131.71; houseNumbers=>(..); labelX=>416031.93]}
[AppModule.ImportService:importStreetsData]: Imported Street:
{<ObjectId:Street, TEMP:000001BA335F1188>; new; [name=>Ulica Milana
Klemenčiča; mapObjects=>(..); town=>{<ObjectId:Town, id=208>};
mid=>19568962; houseNumbers=>(..)]}
NEW objects
{<ObjectId:Street, TEMP:000001BA335F1188>; new; [name=>Ulica Milana
Klemenčiča; mapObjects=>(..); town=>{<ObjectId:Town, id=208>};
mid=>19568962; houseNumbers=>(..)]}
{<ObjectId:MapObject, TEMP:000000BA335E1188>; new;
[mapObjectType=>{<ObjectId:MapObjectType, id=4>}; street=>{<ObjectId:Street,
TEMP:000001BA335F1188>}]}
DELETED objects
MODIFIED objects
{<ObjectId:MapObjectType, id=4>; modified; [mapObjects=>(..); type=>STREET]}
{<ObjectId:Town, id=208>; modified; [name=>Ajdovščina; mapObjects=>(..);
streets=>(..); mid=>10083931; labelY=>85131.71; houseNumbers=>(..);
labelX=>416031.93]}
UNCOMMITED objects
{<ObjectId:Street, TEMP:000001BA335F1188>; new; [name=>Ulica Milana
Klemenčiča; mapObjects=>(..); town=>{<ObjectId:Town, id=208>};
mid=>19568962; houseNumbers=>(..)]}
{<ObjectId:MapObjectType, id=4>; modified; [mapObjects=>(..); type=>STREET]}
{<ObjectId:Town, id=208>; modified; [name=>Ajdovščina; mapObjects=>(..);
streets=>(..); mid=>10083931; labelY=>85131.71; houseNumbers=>(..);
labelX=>416031.93]}
{<ObjectId:MapObject, TEMP:000000BA335E1188>; new;
[mapObjectType=>{<ObjectId:MapObjectType, id=4>}; street=>{<ObjectId:Street,
TEMP:000001BA335F1188>}]}
[access.QueryLogger:logQueryStart]: --- will run 2 queries.
[access.QueryLogger:logBeginTransaction]: --- transaction started.
*[access.QueryLogger:logQuery]: INSERT INTO maps.street (mid, name,
town_mid) VALUES (?, ?, ?)
[access.QueryLogger:logQueryParameters]: [bind: 1->mid:19568962,
2->name:'Ulica Milana Klemenčiča', 3->town_mid:NULL]*
[access.QueryLogger:logGeneratedKey]: Generated PK: street.id = 1
[access.QueryLogger:logUpdateCount]: === updated 1 row.
[access.QueryLogger:logQuery]: INSERT INTO maps.map_object (company_id,
ehis_id, map_object_type_id, poi_id, post_office_id, street_id, town_id)
VALUES (?, ?, ?, ?, ?, ?, ?)
[access.QueryLogger:logQueryParameters]: [bind: 1->company_id:NULL,
2->ehis_id:NULL, 3->map_object_type_id:4, 4->poi_id:NULL,
5->post_office_id:NULL, 6->street_id:1, 7->town_id:NULL]
[access.QueryLogger:logGeneratedKey]: Generated PK: map_object.id = 30617
[access.QueryLogger:logUpdateCount]: === updated 1 row.
[access.QueryLogger:logCommitTransaction]: +++ transaction committed.
This is how the objects are connected
TOWN ------< MAP_OBJECT
TOWN ------< STREET
STREET ----< MAP_OBJECT
Cayenne 3.0.1
Thanks,
Borut
Re: Relationship not set (NULL)
Posted by Andrus Adamchik <an...@objectstyle.org>.
And I was about to start trying your code samples :-)
On Oct 14, 2010, at 8:44 PM, Borut Bolčina wrote:
> Only after I checked out the cayenne sources, debuged for a couple of hours
> I checked again the relationship and found out I was referencing attribute
> named mid instead of id attribute - what a plonker! I will make larger fonts
> on my screen.
>
> Of course it works now.
>
>
> 2010/10/14 Borut Bolčina <bo...@gmail.com>
>
>> Andrus,
>>
>> thanks for the tip. Unfortunately it does not work. Just now I replaced the
>> code which fetches the two objects from shared to local datacontext with two
>> queries which return the two objects in question (localMot and localTown)
>> into the same datacontext.
>>
>> I commented the code which was "transfering" the two objects from shared
>> data context before. This is how it looks now:
>>
>> // MapObjectType mot =
>> persistenceService.findMapObjectType(MapObjectTypeEnum.STREET);
>> // System.out.println("mot dc:" + mot.getDataContext());
>> // // mot lives in shared datacontext so we need a copy
>> // MapObjectType localMot = (MapObjectType)
>> dataContext.localObject(mot.getObjectId(), null);
>> // System.out.println("localMot dc:" +
>> localMot.getDataContext());
>>
>> Expression e =
>> ExpressionFactory.matchExp(MapObjectType.TYPE_PROPERTY,
>> MapObjectTypeEnum.STREET);
>> SelectQuery query = new SelectQuery(MapObjectType.class, e);
>> List list = dataContext.performQuery(query);
>> MapObjectType localMot = null;
>> if (list.size() > 0) {
>> localMot = (MapObjectType) list.get(0);
>> } else {
>> return false;
>> }
>>
>> while (featureIterator.hasNext()) {
>> SimpleFeature feature = (SimpleFeature)
>> featureIterator.next();
>>
>> Integer mid =
>> Integer.parseInt(feature.getAttribute("UL_MID").toString());
>>
>> String rawname = (String) feature.getAttribute("UL_UIME");
>> // prettyPrintHex(rawname.getBytes());
>>
>>
>> MapObject mapObject =
>> dataContext.newObject(MapObject.class);
>> Street street = dataContext.newObject(Street.class);
>>
>> street.setMid(mid);
>> street.setName(rawname);
>>
>> Integer townMid =
>> Integer.parseInt(feature.getAttribute("NA_MID").toString());
>> // Town town = persistenceService.findTownByMid(townMid);
>> // System.out.println("town dc:" + town.getDataContext());
>> // if (town == null) {
>> // logger.error("Street with mid {} has no town
>> associated.", street.getMid());
>> // return false; // TODO tell why (each street must have
>> a town)
>> // }
>> // // town lives in shared datacontext so we need a copy
>> // Town localTown = (Town)
>> dataContext.localObject(town.getObjectId(), null);
>> // System.out.println("localTown dc:" +
>> localTown.getDataContext());
>> // logger.debug("localTown: " + localTown);
>>
>> Expression e1 =
>> ExpressionFactory.matchExp(Town.MID_PROPERTY, townMid);
>> SelectQuery query1 = new SelectQuery(Town.class, e1);
>> List list1 = dataContext.performQuery(query1);
>> Town localTown = null;
>> if (list1.size() > 0) {
>> localTown = (Town) list1.get(0);
>> } else {
>> return false;
>> }
>>
>> *street.setTown(localTown);*
>> //localTown.addToStreets(street);
>>
>>
>>
>>
>> mapObject.setStreet(street);
>> mapObject.setMapObjectType(localMot);
>>
>> counter++;
>>
>> printDataContext(dataContext);
>>
>> logger.debug("Will import Street: " + street);
>>
>> dataContext.commitChanges();
>> }
>>
>> But the* town_mid is still NULL* while the other relationship
>> (mapObject.setStreet(street)) is set correctly.
>>
>> [2010/10/14 09:57:16.327] INFO
>> [AppModule.ImportService:getShapeFileFromClasspath]: Importing Street from
>> jar:file:/C:/Users/borutb/.m2/repository/si/planet9/maps-geodata/0.0.2-SNAPSHOT/maps-geodata-0.0.2-SNAPSHOT.jar!/geodata/UL.shp
>> [2010/10/14 09:57:16.361] DEBUG
>> [AppModule.ImportService:getFeatureIteratorForShapeResource]: Setting Shape
>> file encoding: windows-1250
>> [2010/10/14 09:57:16.586] INFO [access.QueryLogger:logQueryStart]: ---
>> will run 1 query.
>> [2010/10/14 09:57:16.589] INFO [access.QueryLogger:logBeginTransaction]:
>> --- transaction started.
>> [2010/10/14 09:57:16.590] INFO [access.QueryLogger:logQuery]: SELECT
>> t0.id, t0.type FROM maps.map_object_type t0 WHERE t0.type = ? [bind:
>> 1->type:STREET=3]
>> [2010/10/14 09:57:16.593] INFO [access.QueryLogger:logSelectCount]: ===
>> returned 1 row. - took 3 ms.
>> [2010/10/14 09:57:16.594] INFO [access.QueryLogger:logCommitTransaction]:
>> +++ transaction committed.
>> [2010/10/14 09:57:16.619] INFO [access.QueryLogger:logQueryStart]: ---
>> will run 1 query.
>> [2010/10/14 09:57:16.622] INFO [access.QueryLogger:logBeginTransaction]:
>> --- transaction started.
>> [2010/10/14 09:57:16.623] INFO [access.QueryLogger:logQuery]: SELECT
>> t0.name, t0.id, t0.mid, t0.label_y, t0.label_x FROM maps.town t0 WHERE
>> t0.mid = ? [bind: 1->mid:10083931]
>> [2010/10/14 09:57:16.625] INFO [access.QueryLogger:logSelectCount]: ===
>> returned 1 row. - took 3 ms.
>> [2010/10/14 09:57:16.627] INFO [access.QueryLogger:logCommitTransaction]:
>> +++ transaction committed.
>> NEW objects
>> {<ObjectId:Street, TEMP:000001BE35CB1188>; new; [name=>Ulica Milana
>> Klemenčiča; mapObjects=>(..); town=>{<ObjectId:Town, id=446>};
>> mid=>19568962; houseNumbers=>(..)]}
>> {<ObjectId:MapObject, TEMP:000000BE35C71188>; new;
>> [mapObjectType=>{<ObjectId:MapObjectType, id=4>}; street=>{<ObjectId:Street,
>> TEMP:000001BE35CB1188>}]}
>>
>> DELETED objects
>> MODIFIED objects
>> {<ObjectId:MapObjectType, id=4>; modified; [mapObjects=>(..);
>> type=>STREET]}
>> {<ObjectId:Town, id=446>; modified; [name=>Ajdovščina; mapObjects=>?;
>> streets=>(..); mid=>10083931; labelY=>85131.71; houseNumbers=>?;
>> labelX=>416031.93]}
>> UNCOMMITED objects
>>
>> {<ObjectId:MapObjectType, id=4>; modified; [mapObjects=>(..);
>> type=>STREET]}
>> {<ObjectId:Town, id=446>; modified; [name=>Ajdovščina; mapObjects=>?;
>> streets=>(..); mid=>10083931; labelY=>85131.71; houseNumbers=>?;
>> labelX=>416031.93]}
>> {<ObjectId:Street, TEMP:000001BE35CB1188>; new; [name=>Ulica Milana
>> Klemenčiča; mapObjects=>(..); town=>{<ObjectId:Town, id=446>};
>> mid=>19568962; houseNumbers=>(..)]}
>> {<ObjectId:MapObject, TEMP:000000BE35C71188>; new;
>> [mapObjectType=>{<ObjectId:MapObjectType, id=4>}; street=>{<ObjectId:Street,
>> TEMP:000001BE35CB1188>}]}
>> [2010/10/14 09:57:16.633] DEBUG
>> [AppModule.ImportService:importStreetsData]: Will import Street:
>> {<ObjectId:Street, TEMP:000001BE35CB1188>; new; [name=>Ulica Milana
>> Klemenčiča; mapObjects=>(..); town=>{<ObjectId:Town, id=446>};
>> mid=>19568962; houseNumbers=>(..)]}
>> [2010/10/14 09:57:21.709] INFO [access.QueryLogger:logQueryStart]: ---
>> will run 2 queries.
>> [2010/10/14 09:57:21.718] INFO [access.QueryLogger:logBeginTransaction]:
>> --- transaction started.
>> [2010/10/14 09:57:21.734] INFO [access.QueryLogger:logQuery]: INSERT INTO
>> maps.street (mid, name, town_mid) VALUES (?, ?, ?)
>> [2010/10/14 09:57:21.742] INFO [access.QueryLogger:logQueryParameters]:
>> [bind: 1->mid:19568962, 2->name:'Ulica Milana Klemenčiča', *
>> 3->town_mid:NULL*]
>> [2010/10/14 09:57:21.756] INFO [access.QueryLogger:logGeneratedKey]:
>> Generated PK: street.id = 1
>> [2010/10/14 09:57:21.763] INFO [access.QueryLogger:logUpdateCount]: ===
>> updated 1 row.
>> [2010/10/14 09:57:21.770] INFO [access.QueryLogger:logQuery]: INSERT INTO
>> maps.map_object (company_id, house_number_id, map_object_type_id, poi_id,
>> post_office_id, street_id, town_id) VALUES (?, ?, ?, ?, ?, ?, ?)
>> [2010/10/14 09:57:21.778] INFO [access.QueryLogger:logQueryParameters]:
>> [bind: 1->company_id:NULL, 2->house_number_id:NULL, *
>> 3->map_object_type_id:4*, 4->poi_id:NULL, 5->post_office_id:NULL,
>> 6->street_id:1, 7->town_id:NULL]
>> [2010/10/14 09:57:21.787] INFO [access.QueryLogger:logGeneratedKey]:
>> Generated PK: map_object.id = 15997
>> [2010/10/14 09:57:21.794] INFO [access.QueryLogger:logUpdateCount]: ===
>> updated 1 row.
>> [2010/10/14 09:57:21.831] INFO [access.QueryLogger:logCommitTransaction]:
>> +++ transaction committed.
>>
>> If this is a bug, what would you recomend?
>>
>> Thanks,
>> Borut
>>
>>
>> 2010/10/13 Andrus Adamchik <an...@objectstyle.org>
>>
>> Hi Borut,
>>>
>>> On Oct 13, 2010, at 12:02 PM, Borut Bolčina wrote:
>>>
>>>> MapObjectType localMot = (MapObjectType)
>>>> dataContext.localObject(mot.getObjectId(), mot);
>>>
>>> Not sure if there's anything else involved, but the use of 'localObject'
>>> is suspect. Try using null as the second argument:
>>>
>>> MapObjectType localMot = (MapObjectType)
>>> dataContext.localObject(mot.getObjectId(), null);
>>>
>>> This is a piece of less intuitive API in Cayenne. I really wish to replace
>>> it with something more explicit...
>>>
>>> Andrus
>>>
>>>
>>
Re: Relationship not set (NULL)
Posted by Borut Bolčina <bo...@gmail.com>.
Only after I checked out the cayenne sources, debuged for a couple of hours
I checked again the relationship and found out I was referencing attribute
named mid instead of id attribute - what a plonker! I will make larger fonts
on my screen.
Of course it works now.
2010/10/14 Borut Bolčina <bo...@gmail.com>
> Andrus,
>
> thanks for the tip. Unfortunately it does not work. Just now I replaced the
> code which fetches the two objects from shared to local datacontext with two
> queries which return the two objects in question (localMot and localTown)
> into the same datacontext.
>
> I commented the code which was "transfering" the two objects from shared
> data context before. This is how it looks now:
>
> // MapObjectType mot =
> persistenceService.findMapObjectType(MapObjectTypeEnum.STREET);
> // System.out.println("mot dc:" + mot.getDataContext());
> // // mot lives in shared datacontext so we need a copy
> // MapObjectType localMot = (MapObjectType)
> dataContext.localObject(mot.getObjectId(), null);
> // System.out.println("localMot dc:" +
> localMot.getDataContext());
>
> Expression e =
> ExpressionFactory.matchExp(MapObjectType.TYPE_PROPERTY,
> MapObjectTypeEnum.STREET);
> SelectQuery query = new SelectQuery(MapObjectType.class, e);
> List list = dataContext.performQuery(query);
> MapObjectType localMot = null;
> if (list.size() > 0) {
> localMot = (MapObjectType) list.get(0);
> } else {
> return false;
> }
>
> while (featureIterator.hasNext()) {
> SimpleFeature feature = (SimpleFeature)
> featureIterator.next();
>
> Integer mid =
> Integer.parseInt(feature.getAttribute("UL_MID").toString());
>
> String rawname = (String) feature.getAttribute("UL_UIME");
> // prettyPrintHex(rawname.getBytes());
>
>
> MapObject mapObject =
> dataContext.newObject(MapObject.class);
> Street street = dataContext.newObject(Street.class);
>
> street.setMid(mid);
> street.setName(rawname);
>
> Integer townMid =
> Integer.parseInt(feature.getAttribute("NA_MID").toString());
> // Town town = persistenceService.findTownByMid(townMid);
> // System.out.println("town dc:" + town.getDataContext());
> // if (town == null) {
> // logger.error("Street with mid {} has no town
> associated.", street.getMid());
> // return false; // TODO tell why (each street must have
> a town)
> // }
> // // town lives in shared datacontext so we need a copy
> // Town localTown = (Town)
> dataContext.localObject(town.getObjectId(), null);
> // System.out.println("localTown dc:" +
> localTown.getDataContext());
> // logger.debug("localTown: " + localTown);
>
> Expression e1 =
> ExpressionFactory.matchExp(Town.MID_PROPERTY, townMid);
> SelectQuery query1 = new SelectQuery(Town.class, e1);
> List list1 = dataContext.performQuery(query1);
> Town localTown = null;
> if (list1.size() > 0) {
> localTown = (Town) list1.get(0);
> } else {
> return false;
> }
>
> *street.setTown(localTown);*
> //localTown.addToStreets(street);
>
>
>
>
> mapObject.setStreet(street);
> mapObject.setMapObjectType(localMot);
>
> counter++;
>
> printDataContext(dataContext);
>
> logger.debug("Will import Street: " + street);
>
> dataContext.commitChanges();
> }
>
> But the* town_mid is still NULL* while the other relationship
> (mapObject.setStreet(street)) is set correctly.
>
> [2010/10/14 09:57:16.327] INFO
> [AppModule.ImportService:getShapeFileFromClasspath]: Importing Street from
> jar:file:/C:/Users/borutb/.m2/repository/si/planet9/maps-geodata/0.0.2-SNAPSHOT/maps-geodata-0.0.2-SNAPSHOT.jar!/geodata/UL.shp
> [2010/10/14 09:57:16.361] DEBUG
> [AppModule.ImportService:getFeatureIteratorForShapeResource]: Setting Shape
> file encoding: windows-1250
> [2010/10/14 09:57:16.586] INFO [access.QueryLogger:logQueryStart]: ---
> will run 1 query.
> [2010/10/14 09:57:16.589] INFO [access.QueryLogger:logBeginTransaction]:
> --- transaction started.
> [2010/10/14 09:57:16.590] INFO [access.QueryLogger:logQuery]: SELECT
> t0.id, t0.type FROM maps.map_object_type t0 WHERE t0.type = ? [bind:
> 1->type:STREET=3]
> [2010/10/14 09:57:16.593] INFO [access.QueryLogger:logSelectCount]: ===
> returned 1 row. - took 3 ms.
> [2010/10/14 09:57:16.594] INFO [access.QueryLogger:logCommitTransaction]:
> +++ transaction committed.
> [2010/10/14 09:57:16.619] INFO [access.QueryLogger:logQueryStart]: ---
> will run 1 query.
> [2010/10/14 09:57:16.622] INFO [access.QueryLogger:logBeginTransaction]:
> --- transaction started.
> [2010/10/14 09:57:16.623] INFO [access.QueryLogger:logQuery]: SELECT
> t0.name, t0.id, t0.mid, t0.label_y, t0.label_x FROM maps.town t0 WHERE
> t0.mid = ? [bind: 1->mid:10083931]
> [2010/10/14 09:57:16.625] INFO [access.QueryLogger:logSelectCount]: ===
> returned 1 row. - took 3 ms.
> [2010/10/14 09:57:16.627] INFO [access.QueryLogger:logCommitTransaction]:
> +++ transaction committed.
> NEW objects
> {<ObjectId:Street, TEMP:000001BE35CB1188>; new; [name=>Ulica Milana
> Klemenčiča; mapObjects=>(..); town=>{<ObjectId:Town, id=446>};
> mid=>19568962; houseNumbers=>(..)]}
> {<ObjectId:MapObject, TEMP:000000BE35C71188>; new;
> [mapObjectType=>{<ObjectId:MapObjectType, id=4>}; street=>{<ObjectId:Street,
> TEMP:000001BE35CB1188>}]}
>
> DELETED objects
> MODIFIED objects
> {<ObjectId:MapObjectType, id=4>; modified; [mapObjects=>(..);
> type=>STREET]}
> {<ObjectId:Town, id=446>; modified; [name=>Ajdovščina; mapObjects=>?;
> streets=>(..); mid=>10083931; labelY=>85131.71; houseNumbers=>?;
> labelX=>416031.93]}
> UNCOMMITED objects
>
> {<ObjectId:MapObjectType, id=4>; modified; [mapObjects=>(..);
> type=>STREET]}
> {<ObjectId:Town, id=446>; modified; [name=>Ajdovščina; mapObjects=>?;
> streets=>(..); mid=>10083931; labelY=>85131.71; houseNumbers=>?;
> labelX=>416031.93]}
> {<ObjectId:Street, TEMP:000001BE35CB1188>; new; [name=>Ulica Milana
> Klemenčiča; mapObjects=>(..); town=>{<ObjectId:Town, id=446>};
> mid=>19568962; houseNumbers=>(..)]}
> {<ObjectId:MapObject, TEMP:000000BE35C71188>; new;
> [mapObjectType=>{<ObjectId:MapObjectType, id=4>}; street=>{<ObjectId:Street,
> TEMP:000001BE35CB1188>}]}
> [2010/10/14 09:57:16.633] DEBUG
> [AppModule.ImportService:importStreetsData]: Will import Street:
> {<ObjectId:Street, TEMP:000001BE35CB1188>; new; [name=>Ulica Milana
> Klemenčiča; mapObjects=>(..); town=>{<ObjectId:Town, id=446>};
> mid=>19568962; houseNumbers=>(..)]}
> [2010/10/14 09:57:21.709] INFO [access.QueryLogger:logQueryStart]: ---
> will run 2 queries.
> [2010/10/14 09:57:21.718] INFO [access.QueryLogger:logBeginTransaction]:
> --- transaction started.
> [2010/10/14 09:57:21.734] INFO [access.QueryLogger:logQuery]: INSERT INTO
> maps.street (mid, name, town_mid) VALUES (?, ?, ?)
> [2010/10/14 09:57:21.742] INFO [access.QueryLogger:logQueryParameters]:
> [bind: 1->mid:19568962, 2->name:'Ulica Milana Klemenčiča', *
> 3->town_mid:NULL*]
> [2010/10/14 09:57:21.756] INFO [access.QueryLogger:logGeneratedKey]:
> Generated PK: street.id = 1
> [2010/10/14 09:57:21.763] INFO [access.QueryLogger:logUpdateCount]: ===
> updated 1 row.
> [2010/10/14 09:57:21.770] INFO [access.QueryLogger:logQuery]: INSERT INTO
> maps.map_object (company_id, house_number_id, map_object_type_id, poi_id,
> post_office_id, street_id, town_id) VALUES (?, ?, ?, ?, ?, ?, ?)
> [2010/10/14 09:57:21.778] INFO [access.QueryLogger:logQueryParameters]:
> [bind: 1->company_id:NULL, 2->house_number_id:NULL, *
> 3->map_object_type_id:4*, 4->poi_id:NULL, 5->post_office_id:NULL,
> 6->street_id:1, 7->town_id:NULL]
> [2010/10/14 09:57:21.787] INFO [access.QueryLogger:logGeneratedKey]:
> Generated PK: map_object.id = 15997
> [2010/10/14 09:57:21.794] INFO [access.QueryLogger:logUpdateCount]: ===
> updated 1 row.
> [2010/10/14 09:57:21.831] INFO [access.QueryLogger:logCommitTransaction]:
> +++ transaction committed.
>
> If this is a bug, what would you recomend?
>
> Thanks,
> Borut
>
>
> 2010/10/13 Andrus Adamchik <an...@objectstyle.org>
>
> Hi Borut,
>>
>> On Oct 13, 2010, at 12:02 PM, Borut Bolčina wrote:
>>
>> > MapObjectType localMot = (MapObjectType)
>> > dataContext.localObject(mot.getObjectId(), mot);
>>
>> Not sure if there's anything else involved, but the use of 'localObject'
>> is suspect. Try using null as the second argument:
>>
>> MapObjectType localMot = (MapObjectType)
>> dataContext.localObject(mot.getObjectId(), null);
>>
>> This is a piece of less intuitive API in Cayenne. I really wish to replace
>> it with something more explicit...
>>
>> Andrus
>>
>>
>
Re: Relationship not set (NULL)
Posted by Borut Bolčina <bo...@gmail.com>.
Andrus,
thanks for the tip. Unfortunately it does not work. Just now I replaced the
code which fetches the two objects from shared to local datacontext with two
queries which return the two objects in question (localMot and localTown)
into the same datacontext.
I commented the code which was "transfering" the two objects from shared
data context before. This is how it looks now:
// MapObjectType mot =
persistenceService.findMapObjectType(MapObjectTypeEnum.STREET);
// System.out.println("mot dc:" + mot.getDataContext());
// // mot lives in shared datacontext so we need a copy
// MapObjectType localMot = (MapObjectType)
dataContext.localObject(mot.getObjectId(), null);
// System.out.println("localMot dc:" +
localMot.getDataContext());
Expression e =
ExpressionFactory.matchExp(MapObjectType.TYPE_PROPERTY,
MapObjectTypeEnum.STREET);
SelectQuery query = new SelectQuery(MapObjectType.class, e);
List list = dataContext.performQuery(query);
MapObjectType localMot = null;
if (list.size() > 0) {
localMot = (MapObjectType) list.get(0);
} else {
return false;
}
while (featureIterator.hasNext()) {
SimpleFeature feature = (SimpleFeature)
featureIterator.next();
Integer mid =
Integer.parseInt(feature.getAttribute("UL_MID").toString());
String rawname = (String) feature.getAttribute("UL_UIME");
// prettyPrintHex(rawname.getBytes());
MapObject mapObject =
dataContext.newObject(MapObject.class);
Street street = dataContext.newObject(Street.class);
street.setMid(mid);
street.setName(rawname);
Integer townMid =
Integer.parseInt(feature.getAttribute("NA_MID").toString());
// Town town = persistenceService.findTownByMid(townMid);
// System.out.println("town dc:" + town.getDataContext());
// if (town == null) {
// logger.error("Street with mid {} has no town
associated.", street.getMid());
// return false; // TODO tell why (each street must have
a town)
// }
// // town lives in shared datacontext so we need a copy
// Town localTown = (Town)
dataContext.localObject(town.getObjectId(), null);
// System.out.println("localTown dc:" +
localTown.getDataContext());
// logger.debug("localTown: " + localTown);
Expression e1 =
ExpressionFactory.matchExp(Town.MID_PROPERTY, townMid);
SelectQuery query1 = new SelectQuery(Town.class, e1);
List list1 = dataContext.performQuery(query1);
Town localTown = null;
if (list1.size() > 0) {
localTown = (Town) list1.get(0);
} else {
return false;
}
*street.setTown(localTown);*
//localTown.addToStreets(street);
mapObject.setStreet(street);
mapObject.setMapObjectType(localMot);
counter++;
printDataContext(dataContext);
logger.debug("Will import Street: " + street);
dataContext.commitChanges();
}
But the* town_mid is still NULL* while the other relationship
(mapObject.setStreet(street)) is set correctly.
[2010/10/14 09:57:16.327] INFO
[AppModule.ImportService:getShapeFileFromClasspath]: Importing Street from
jar:file:/C:/Users/borutb/.m2/repository/si/planet9/maps-geodata/0.0.2-SNAPSHOT/maps-geodata-0.0.2-SNAPSHOT.jar!/geodata/UL.shp
[2010/10/14 09:57:16.361] DEBUG
[AppModule.ImportService:getFeatureIteratorForShapeResource]: Setting Shape
file encoding: windows-1250
[2010/10/14 09:57:16.586] INFO [access.QueryLogger:logQueryStart]: --- will
run 1 query.
[2010/10/14 09:57:16.589] INFO [access.QueryLogger:logBeginTransaction]:
--- transaction started.
[2010/10/14 09:57:16.590] INFO [access.QueryLogger:logQuery]: SELECT t0.id,
t0.type FROM maps.map_object_type t0 WHERE t0.type = ? [bind:
1->type:STREET=3]
[2010/10/14 09:57:16.593] INFO [access.QueryLogger:logSelectCount]: ===
returned 1 row. - took 3 ms.
[2010/10/14 09:57:16.594] INFO [access.QueryLogger:logCommitTransaction]:
+++ transaction committed.
[2010/10/14 09:57:16.619] INFO [access.QueryLogger:logQueryStart]: --- will
run 1 query.
[2010/10/14 09:57:16.622] INFO [access.QueryLogger:logBeginTransaction]:
--- transaction started.
[2010/10/14 09:57:16.623] INFO [access.QueryLogger:logQuery]: SELECT
t0.name, t0.id, t0.mid, t0.label_y, t0.label_x FROM maps.town t0 WHERE
t0.mid = ? [bind: 1->mid:10083931]
[2010/10/14 09:57:16.625] INFO [access.QueryLogger:logSelectCount]: ===
returned 1 row. - took 3 ms.
[2010/10/14 09:57:16.627] INFO [access.QueryLogger:logCommitTransaction]:
+++ transaction committed.
NEW objects
{<ObjectId:Street, TEMP:000001BE35CB1188>; new; [name=>Ulica Milana
Klemenčiča; mapObjects=>(..); town=>{<ObjectId:Town, id=446>};
mid=>19568962; houseNumbers=>(..)]}
{<ObjectId:MapObject, TEMP:000000BE35C71188>; new;
[mapObjectType=>{<ObjectId:MapObjectType, id=4>}; street=>{<ObjectId:Street,
TEMP:000001BE35CB1188>}]}
DELETED objects
MODIFIED objects
{<ObjectId:MapObjectType, id=4>; modified; [mapObjects=>(..); type=>STREET]}
{<ObjectId:Town, id=446>; modified; [name=>Ajdovščina; mapObjects=>?;
streets=>(..); mid=>10083931; labelY=>85131.71; houseNumbers=>?;
labelX=>416031.93]}
UNCOMMITED objects
{<ObjectId:MapObjectType, id=4>; modified; [mapObjects=>(..); type=>STREET]}
{<ObjectId:Town, id=446>; modified; [name=>Ajdovščina; mapObjects=>?;
streets=>(..); mid=>10083931; labelY=>85131.71; houseNumbers=>?;
labelX=>416031.93]}
{<ObjectId:Street, TEMP:000001BE35CB1188>; new; [name=>Ulica Milana
Klemenčiča; mapObjects=>(..); town=>{<ObjectId:Town, id=446>};
mid=>19568962; houseNumbers=>(..)]}
{<ObjectId:MapObject, TEMP:000000BE35C71188>; new;
[mapObjectType=>{<ObjectId:MapObjectType, id=4>}; street=>{<ObjectId:Street,
TEMP:000001BE35CB1188>}]}
[2010/10/14 09:57:16.633] DEBUG [AppModule.ImportService:importStreetsData]:
Will import Street: {<ObjectId:Street, TEMP:000001BE35CB1188>; new;
[name=>Ulica Milana Klemenčiča; mapObjects=>(..); town=>{<ObjectId:Town,
id=446>}; mid=>19568962; houseNumbers=>(..)]}
[2010/10/14 09:57:21.709] INFO [access.QueryLogger:logQueryStart]: --- will
run 2 queries.
[2010/10/14 09:57:21.718] INFO [access.QueryLogger:logBeginTransaction]:
--- transaction started.
[2010/10/14 09:57:21.734] INFO [access.QueryLogger:logQuery]: INSERT INTO
maps.street (mid, name, town_mid) VALUES (?, ?, ?)
[2010/10/14 09:57:21.742] INFO [access.QueryLogger:logQueryParameters]:
[bind: 1->mid:19568962, 2->name:'Ulica Milana Klemenčiča', *3->town_mid:NULL
*]
[2010/10/14 09:57:21.756] INFO [access.QueryLogger:logGeneratedKey]:
Generated PK: street.id = 1
[2010/10/14 09:57:21.763] INFO [access.QueryLogger:logUpdateCount]: ===
updated 1 row.
[2010/10/14 09:57:21.770] INFO [access.QueryLogger:logQuery]: INSERT INTO
maps.map_object (company_id, house_number_id, map_object_type_id, poi_id,
post_office_id, street_id, town_id) VALUES (?, ?, ?, ?, ?, ?, ?)
[2010/10/14 09:57:21.778] INFO [access.QueryLogger:logQueryParameters]:
[bind: 1->company_id:NULL, 2->house_number_id:NULL, *3->map_object_type_id:4
*, 4->poi_id:NULL, 5->post_office_id:NULL, 6->street_id:1, 7->town_id:NULL]
[2010/10/14 09:57:21.787] INFO [access.QueryLogger:logGeneratedKey]:
Generated PK: map_object.id = 15997
[2010/10/14 09:57:21.794] INFO [access.QueryLogger:logUpdateCount]: ===
updated 1 row.
[2010/10/14 09:57:21.831] INFO [access.QueryLogger:logCommitTransaction]:
+++ transaction committed.
If this is a bug, what would you recomend?
Thanks,
Borut
2010/10/13 Andrus Adamchik <an...@objectstyle.org>
> Hi Borut,
>
> On Oct 13, 2010, at 12:02 PM, Borut Bolčina wrote:
>
> > MapObjectType localMot = (MapObjectType)
> > dataContext.localObject(mot.getObjectId(), mot);
>
> Not sure if there's anything else involved, but the use of 'localObject' is
> suspect. Try using null as the second argument:
>
> MapObjectType localMot = (MapObjectType)
> dataContext.localObject(mot.getObjectId(), null);
>
> This is a piece of less intuitive API in Cayenne. I really wish to replace
> it with something more explicit...
>
> Andrus
>
>
Re: Relationship not set (NULL)
Posted by Andrus Adamchik <an...@objectstyle.org>.
Hi Borut,
On Oct 13, 2010, at 12:02 PM, Borut Bolčina wrote:
> MapObjectType localMot = (MapObjectType)
> dataContext.localObject(mot.getObjectId(), mot);
Not sure if there's anything else involved, but the use of 'localObject' is suspect. Try using null as the second argument:
MapObjectType localMot = (MapObjectType) dataContext.localObject(mot.getObjectId(), null);
This is a piece of less intuitive API in Cayenne. I really wish to replace it with something more explicit...
Andrus