I haven't tried to reproduce the bug yet, but from Marcin's
description it looks like an actual bug. Traditionally all Cayenne
relationship modification methods would internally update the reverse
relationship as well. It should work the same way on both client and
server.
Andrus
On May 3, 2006, at 2:29 AM, Marcin Skladaniec wrote:
You are absolutely right Michael.
In CRoom have overriden setSite method :
public void setSite(CSite site) {
if (getSite() != null) {
getSite().removeFromRooms(this);
}
super.setSite(site);
}
and everything works.
Does it mean that I have to override setter in every many to one
relationship ? Is there any reason why cayenne itself shouldn't do
that ?
It seems not right for me.
Regards
Marcin
On 02/05/2006, at 11:21 PM, Gentry, Michael ((Contractor)) wrote:
Marcin,
I'm not certain this is a Cayenne bug. I think it is more of a
misunderstanding. When you do:
logger.info("(here relationship is modified)");
temproom.setSite(tempsite2);
You point the room's site to site2, but you never unlinked the
relationship from site1->room. Therefore, when you then do:
logger.info("site 1 rooms");
rooms = tempsite1.getRooms();
for (int i=0; i<rooms.size();i++) {
logger.info("\troom "+i+" :
"+((CRoom)rooms.get(i)).getName());
}
tempsite1 will still print the room out because the room is still it
site1's rooms relationship. Try:
logger.info("(here relationship is modified)");
tempsite1.removeFromRooms(temproom);
temproom.setSite(tempsite2);
And see if it helps.
/dev/mrg
-----Original Message-----
From: Marcin Skladaniec (JIRA) [mailto:[EMAIL PROTECTED]
Sent: Monday, May 01, 2006 9:53 PM
To: [email protected]
Subject: [JIRA] Created: (CAY-538) Relationship not refreshed before
committing the context.
Relationship not refreshed before committing the context.
----------------------------------------------------------
Key: CAY-538
URL: http://issues.apache.org/cayenne/browse/CAY-538
Project: Cayenne
Type: Bug
Components: Cayenne Core Library
Versions: 1.2 [BETA]
Environment: I think any platform, but tested on os x and freebsd.
Cayenne 3t
Reporter: Marcin Skladaniec
I have two sites : site1 and site2 and a room linked to site1
If I change the relationship so the room links to site2, than
before I
commit the changes both sites are linked to the room.
The code
{
Expression expression =
ExpressionFactory.matchExp(CSite.NAME_PROPERTY, "site1");
SelectQuery query = new SelectQuery(CSite.class,
expression);
List list = context2.performQuery(query);
CSite tempsite1 = (CSite)list.get(0);
expression =
ExpressionFactory.matchExp(CSite.NAME_PROPERTY, "site2");
query = new SelectQuery(CSite.class, expression);
list = context2.performQuery(query);
CSite tempsite2 = (CSite)list.get(0);
expression =
ExpressionFactory.matchExp(CRoom.NAME_PROPERTY, "room");
query = new SelectQuery(CRoom.class, expression);
list = context2.performQuery(query);
CRoom temproom = (CRoom)list.get(0);
logger.info("site 1 rooms");
List rooms = tempsite1.getRooms();
for (int i=0; i<rooms.size();i++) {
logger.info("\troom "+i+" :
"+((CRoom)rooms.get(i)).getName());
}
logger.info("site 2 rooms");
rooms = tempsite2.getRooms();
for (int i=0; i<rooms.size();i++) {
logger.info("\troom "+i+" :
"+((CRoom)rooms.get(i)).getName());
}
logger.info("(here relationship is modified)");
temproom.setSite(tempsite2);
logger.info("site 1 rooms");
rooms = tempsite1.getRooms();
for (int i=0; i<rooms.size();i++) {
logger.info("\troom "+i+" :
"+((CRoom)rooms.get(i)).getName());
}
logger.info("site 2 rooms");
rooms = tempsite2.getRooms();
for (int i=0; i<rooms.size();i++) {
logger.info("\troom "+i+" :
"+((CRoom)rooms.get(i)).getName());
}
}
produces output :
site 1 rooms
room 0 : room
site 2 rooms
(here relationship is modified)
site 1 rooms
room 0 : room
site 2 rooms
room 0 : room
I can publish a small project reproducing this bug.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the
administrators:
http://issues.apache.org/cayenne/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
-------------------------->
ish
http://www.ish.com.au
Level 1, 30 Wilson Street Newtown 2042 Australia
phone +61 2 9550 5001 fax +61 2 9550 4001