Deleting on rich link tables

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Deleting on rich link tables

Maarten Mostert

Hi,

I have a link table (two primary keys) wich is mapped itself and holds additinal data about the link (margin and type in this case).

If I do so I cannot delete the link in a normal fashion.

The moment I want to delete the link, Glorp wants to recreate the linked objects resulting in a: 'Duplicate objects with same primary key' error.

I am doing something like this:

aModel getGlorpSession inUnitOfWorkDo:

[start_task tasksFromEnd remove: self ifAbsent: [].

end_task tasksToStart remove: self ifAbsent: [].

aModel getGlorpSession delete: self].

The error stack is enclosed.

The concerned descriptor methods are given below (notice that key is mapped to task_id as Task is subclassed from AssociationTreeWithParent).

Nota: I have to say that I have been strugling with deleting objects for years, often I end up writing a direct SQL command followed by refreshing associated objects to clean up Glorp’s cash.

Regards,

@+Maarten,

classModelForTaskAllRelation: aClassModel

aClassModel newAttributeNamed: #start_task type: Task.

aClassModel newAttributeNamed: #end_task type:  Task.

aClassModel newAttributeNamed: #margin.

aClassModel newAttributeNamed: #type

classModelForTask: aClassModel

aClassModel newAttributeNamed: #key.

aClassModel newAttributeNamed: #value.

aClassModel newAttributeNamed: #proj_id.

aClassModel newAttributeNamed: #task_order.

aClassModel newAttributeNamed: #parent type: Task.

aClassModel newAttributeNamed: #children collectionOf: Task.

aClassModel newAttributeNamed: #outlinenumber.

aClassModel newAttributeNamed: #msp_uid.

aClassModel newAttributeNamed: #task_early_finish type: Date. "fin plustot"

aClassModel newAttributeNamed: #task_late_start type: Date. "debut plus tard"

aClassModel newAttributeNamed: #task_dur. "duree"

aClassModel newAttributeNamed: #task_start_date type: Date. "ordonnancée"

aClassModel newAttributeNamed: #task_finish_date type: Date. "ordonnancée"

aClassModel newAttributeNamed: #task_pct_comp. "Avancement"

aClassModel newAttributeNamed: #critical_a.

aClassModel newAttributeNamed: #critical_b.

aClassModel newAttributeNamed: #critical_c.

aClassModel newAttributeNamed: #critical_d.

aClassModel newAttributeNamed: #task_type.

aClassModel newAttributeNamed: #task_creation_date type: Date.

aClassModel newAttributeNamed: #task_early_start type: Date. "debut plustot"

aClassModel newAttributeNamed: #task_late_finish type: Date. "fin plustard"

aClassModel newAttributeNamed: #task_cal_uid. "Calender UID"

aClassModel newAttributeNamed: #task_work. "Temps ordonnancée"

aClassModel newAttributeNamed: #task_cost.

aClassModel newAttributeNamed: #task_fixed_cost.

aClassModel newAttributeNamed: #task_wbs_chain.

aClassModel newAttributeNamed: #task_wbs_node type: HierarchyTreeNode.

aClassModel newAttributeNamed: #task_org_key.

aClassModel newAttributeNamed: #task_org_node type: OrganisationTreeNode.

aClassModel newAttributeNamed: #task_resource type: Resource.

aClassModel newAttributeNamed: #tasksToStart  collectionOf: TaskAllRelation.

aClassModel newAttributeNamed: #tasksFromEnd collectionOf: TaskAllRelation.

aClassModel newAttributeNamed: #avancementcol collection: OrderedCollection of: Avancement.

aClassModel newAttributeNamed: #attachementcol collection: OrderedCollection of: Attachement

descriptorForTaskAllRelation: aDescriptor

"Be carefull  the relations start is normally the end of a task the relations end is the beginning of a new task"

| table |

table := self tableNamed: 'MMT_TASK_ALL_RELATION'.

aDescriptor table: table.

(aDescriptor newMapping: Glorp.OneToOneMapping)

attributeName: #start_task;

join: (Glorp.Join from: (table fieldNamed: 'start_task')

to: ((self tableNamed: 'MMT_TASK') fieldNamed: 'task_id')).

(aDescriptor newMapping: Glorp.OneToOneMapping)

attributeName: #end_task;

join: (Glorp.Join from: (table fieldNamed: 'end_task')

to: ((self tableNamed: 'MMT_TASK') fieldNamed: 'task_id')).

(aDescriptor newMapping: DirectMapping) from: #margin

to: (table fieldNamed: 'margin').

(aDescriptor newMapping: DirectMapping) from: #type

to: (table fieldNamed: 'type')

descriptorForTask: aDescriptor

| table |

table := self tableNamed: 'MMT_TASK'.

aDescriptor table: table.

aDescriptor addMapping: (DirectMapping from: #key to: (table fieldNamed: 'task_id')).

(aDescriptor newMapping: DirectMapping) from: #value to: (table fieldNamed: 'task_name').

(aDescriptor newMapping: DirectMapping) from: #task_order to: (table fieldNamed: 'task_order').

"Define parent child links"

(aDescriptor newMapping: Glorp.OneToOneMapping)

attributeName: #parent;

useLinkTable;

join: (Glorp.Join from: (table fieldNamed: 'task_id') to: ((self tableNamed: 'MMT_TASK_TREE_LINK') fieldNamed: 'CHILD')).

(aDescriptor newMapping: Glorp.ToManyMapping)

attributeName: #children;

useLinkTable;

orderBy: #task_order;

join: (Glorp.Join from: (table fieldNamed: 'task_id') to: ((self tableNamed: 'MMT_TASK_TREE_LINK') fieldNamed: 'PARENT')).

"aDescriptor newMapping: Glorp.ToManyMapping."

"====//===="

(aDescriptor newMapping: DirectMapping) from: #outlinenumber to: (table fieldNamed: 'outlinenumber').

(aDescriptor newMapping: DirectMapping) from: #proj_id to: (table fieldNamed: 'proj_id').

(aDescriptor newMapping: DirectMapping) from: #task_early_finish to: (table fieldNamed: 'task_early_finish').

(aDescriptor newMapping: DirectMapping) from: #task_late_start to: (table fieldNamed: 'task_late_start').

(aDescriptor newMapping: DirectMapping) from: #task_dur to: (table fieldNamed: 'task_dur').

(aDescriptor newMapping: DirectMapping) from: #task_start_date to: (table fieldNamed: 'task_start_date').

(aDescriptor newMapping: DirectMapping) from: #task_finish_date to: (table fieldNamed: 'task_finish_date').

(aDescriptor newMapping: DirectMapping) from: #task_pct_comp to: (table fieldNamed: 'task_pct_comp').

(aDescriptor newMapping: DirectMapping) from: #critical_a to: (table fieldNamed: 'critical_a').

(aDescriptor newMapping: DirectMapping) from: #critical_b to: (table fieldNamed: 'critical_b').

(aDescriptor newMapping: DirectMapping) from: #critical_c to: (table fieldNamed: 'critical_c').

(aDescriptor newMapping: DirectMapping) from: #critical_d to: (table fieldNamed: 'critical_d').

(aDescriptor newMapping: DirectMapping) from: #task_type to: (table fieldNamed: 'task_type').

(aDescriptor newMapping: DirectMapping) from: #task_creation_date to: (table fieldNamed: 'task_creation_date').

(aDescriptor newMapping: DirectMapping) from: #task_early_start to: (table fieldNamed: 'task_early_start').

(aDescriptor newMapping: DirectMapping) from: #task_late_finish to: (table fieldNamed: 'task_late_finish').

(aDescriptor newMapping: DirectMapping) from: #task_work to: (table fieldNamed: 'task_work').

(aDescriptor newMapping: DirectMapping) from: #task_cost to: (table fieldNamed: 'task_cost').

(aDescriptor newMapping: DirectMapping) from: #task_fixed_cost to: (table fieldNamed: 'task_fixed_cost').

(aDescriptor newMapping: DirectMapping) from: #task_wbs_chain to: (table fieldNamed: 'task_wbs_chain').

(aDescriptor newMapping: Glorp.OneToOneMapping) attributeName: #task_wbs_node.

(aDescriptor newMapping: DirectMapping) from: #task_org_key to: (table fieldNamed: 'task_org_key').

(aDescriptor newMapping: Glorp.OneToOneMapping) attributeName: #task_org_node.

(aDescriptor newMapping: Glorp.OneToOneMapping) attributeName: #task_resource.

(aDescriptor newMapping: Glorp.ToManyMapping)

attributeName: #tasksFromEnd;

join: (Glorp.Join from: (table fieldNamed: 'task_id')

to: ((self tableNamed: 'MMT_TASK_ALL_RELATION') fieldNamed: 'START_TASK'));

referenceClass: TaskAllRelation.

(aDescriptor newMapping: Glorp.ToManyMapping)

attributeName: #tasksToStart;

join: (Glorp.Join from: (table fieldNamed: 'task_id')

to: ((self tableNamed: 'MMT_TASK_ALL_RELATION') fieldNamed: 'END_TASK'));

referenceClass: TaskAllRelation.

(aDescriptor newMapping: Glorp.ToManyMapping)

attributeName: #avancementcol;

orderBy: #registerdate;

join: (Glorp.Join from: (table fieldNamed: 'task_id')

to: ((self tableNamed: 'MMT_AVANCEMENT') fieldNamed: 'avanc_plannedtask_id')).

(aDescriptor newMapping: Glorp.ToManyMapping)

attributeName: #attachementcol;

orderBy: #id;

join: (Glorp.Join from: (table fieldNamed: 'task_id')

to: ((self tableNamed: 'MMT_ATTACHEMENT') fieldNamed: 'att_plannedtask_id')).

(aDescriptor newMapping: DirectMapping) from: #msp_uid to: (table fieldNamed: 'msp_uid')

tableForMMT_TASK_ALL_RELATION: aTable

| start end |

start := (aTable createFieldNamed: 'start_task' type: platform int4)

bePrimaryKey.

aTable addForeignKeyFrom: start

to: ((self tableNamed: 'MMT_TASK') fieldNamed: 'task_id').

end := (aTable createFieldNamed: 'end_task' type: platform int4)

bePrimaryKey.

aTable addForeignKeyFrom: end

to: ((self tableNamed: 'MMT_TASK') fieldNamed: 'task_id').

aTable createFieldNamed: 'margin' type: platform int4.

aTable createFieldNamed: 'type' type: (platform varchar: 8)

tableForMMT_TASK: aTable

| resource orgnode wbsnode |

(aTable createFieldNamed: 'task_id' type: platform sequence) bePrimaryKey.

aTable createFieldNamed: 'task_name' type: (platform varchar: 255).

aTable createFieldNamed: 'task_order' type: platform int4.

(aTable createFieldNamed: 'proj_id' type: platform integer)

beNullable: true.

aTable createFieldNamed: 'outlinenumber' type: (platform varchar: 255). "platform clob."

aTable createFieldNamed: 'msp_uid' type: platform int4.

aTable createFieldNamed: 'task_financial' type: platform boolean.

aTable createFieldNamed: 'task_imputation' type: (platform varchar: 255).

aTable createFieldNamed: 'task_early_finish' type: platform date.

aTable createFieldNamed: 'task_late_start' type: platform date.

(aTable createFieldNamed: 'task_dur' type: platform integer)

beNullable: true.

(aTable createFieldNamed: 'task_start_date' type: platform date)

beNullable: true.

(aTable createFieldNamed: 'task_finish_date' type: platform date)

beNullable: true.

aTable createFieldNamed: 'task_pct_comp' type: platform float.

aTable createFieldNamed: 'task_last_registerdate' type: platform date.

aTable createFieldNamed: 'critical_a' type: platform float.

aTable createFieldNamed: 'critical_b' type: platform float.

aTable createFieldNamed: 'critical_c' type: platform float.

aTable createFieldNamed: 'critical_d' type: platform float.

aTable createFieldNamed: 'task_type' type: platform int2.

aTable createFieldNamed: 'task_creation_date' type: platform timestamp.

aTable createFieldNamed: 'task_early_start' type: platform date.

aTable createFieldNamed: 'task_late_finish' type: platform date.

(aTable createFieldNamed: 'task_cal_uid' type: platform int4)

beNullable: true.

aTable createFieldNamed: 'task_work' type: platform float.

aTable createFieldNamed: 'task_cost' type: platform float.

aTable createFieldNamed: 'task_fixed_cost' type: platform float.

aTable createFieldNamed: 'task_wbs_chain' type: platform clob.

wbsnode := aTable createFieldNamed: 'task_wbs_node' type: platform int4.

aTable addForeignKeyFrom: wbsnode

to: ((self tableNamed: 'MMT_HIERARCHY_TREE_NODE') fieldNamed: 'id').

aTable createFieldNamed: 'task_org_key' type: platform int4.

orgnode := (aTable createFieldNamed: 'task_org_node' type: platform int4)

beNullable: true.

aTable addForeignKeyFrom: orgnode

to: ((self tableNamed: 'MMT_ORGANISATION_TREE_NODE') fieldNamed: 'id').

resource := aTable createFieldNamed: 'task_resource' type: platform int4.

aTable addForeignKeyFrom: resource

to: ((self tableNamed: 'MMT_RESOURCES') fieldNamed: 'res_id')

--
You received this message because you are subscribed to the Google Groups "glorp-group" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/glorp-group?hl=en.

glorp error stack.zip (6K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Deleting on rich link tables

Alan Knight-2
Hi,
   That's certainly not supposed to happen. What do you mean by "Glorp
wants to recreate the linked objects". Glorp won't ever create those.
From the stack you provided the problem is in registerForDelete:. And
unless your print strings are doing something odd, it appears that the
object in question is an association from 34 -> '<new task>', but for
the relation startTask, which isn't a dictionary mapping.  Are you
storing associations in regular collections, or is that a printString
that just looks like one?

  In general, the duplicate primary key exception is what it says.
You've asked to put an object in the cache under a particular primary
key and there's already a non-identical object there under that key.
So the question is where it's coming from. If it's doing a
registerForDelete: it would definitely expect the identical object to
already be there. So if a non-identical object is being passed in, the
question is where it's coming from.

  You also don't include the tables, which might be helpful.

Alan

On Sat, Aug 18, 2012 at 7:27 AM,  <[hidden email]> wrote:

> Hi,
>
> I have a link table (two primary keys) wich is mapped itself and holds
> additinal data about the link (margin and type in this case).
>
> If I do so I cannot delete the link in a normal fashion.
>
> The moment I want to delete the link, Glorp wants to recreate the linked
> objects resulting in a: 'Duplicate objects with same primary key' error.
>
> I am doing something like this:
>
> aModel getGlorpSession inUnitOfWorkDo:
>
> [start_task tasksFromEnd remove: self ifAbsent: [].
>
> end_task tasksToStart remove: self ifAbsent: [].
>
> aModel getGlorpSession delete: self].
>
> The error stack is enclosed.
>
> The concerned descriptor methods are given below (notice that key is mapped
> to task_id as Task is subclassed from AssociationTreeWithParent).
>
> Nota: I have to say that I have been strugling with deleting objects for
> years, often I end up writing a direct SQL command followed by refreshing
> associated objects to clean up Glorp’s cash.
>
> Regards,
>
> @+Maarten,
>
> classModelForTaskAllRelation: aClassModel
>
> aClassModel newAttributeNamed: #start_task type: Task.
>
> aClassModel newAttributeNamed: #end_task type:  Task.
>
> aClassModel newAttributeNamed: #margin.
>
> aClassModel newAttributeNamed: #type
>
> classModelForTask: aClassModel
>
> aClassModel newAttributeNamed: #key.
>
> aClassModel newAttributeNamed: #value.
>
> aClassModel newAttributeNamed: #proj_id.
>
> aClassModel newAttributeNamed: #task_order.
>
> aClassModel newAttributeNamed: #parent type: Task.
>
> aClassModel newAttributeNamed: #children collectionOf: Task.
>
> aClassModel newAttributeNamed: #outlinenumber.
>
> aClassModel newAttributeNamed: #msp_uid.
>
> aClassModel newAttributeNamed: #task_early_finish type: Date. "fin plustot"
>
> aClassModel newAttributeNamed: #task_late_start type: Date. "debut plus
> tard"
>
> aClassModel newAttributeNamed: #task_dur. "duree"
>
> aClassModel newAttributeNamed: #task_start_date type: Date. "ordonnancée"
>
> aClassModel newAttributeNamed: #task_finish_date type: Date. "ordonnancée"
>
> aClassModel newAttributeNamed: #task_pct_comp. "Avancement"
>
> aClassModel newAttributeNamed: #critical_a.
>
> aClassModel newAttributeNamed: #critical_b.
>
> aClassModel newAttributeNamed: #critical_c.
>
> aClassModel newAttributeNamed: #critical_d.
>
> aClassModel newAttributeNamed: #task_type.
>
> aClassModel newAttributeNamed: #task_creation_date type: Date.
>
> aClassModel newAttributeNamed: #task_early_start type: Date. "debut plustot"
>
> aClassModel newAttributeNamed: #task_late_finish type: Date. "fin plustard"
>
> aClassModel newAttributeNamed: #task_cal_uid. "Calender UID"
>
> aClassModel newAttributeNamed: #task_work. "Temps ordonnancée"
>
> aClassModel newAttributeNamed: #task_cost.
>
> aClassModel newAttributeNamed: #task_fixed_cost.
>
> aClassModel newAttributeNamed: #task_wbs_chain.
>
> aClassModel newAttributeNamed: #task_wbs_node type: HierarchyTreeNode.
>
> aClassModel newAttributeNamed: #task_org_key.
>
> aClassModel newAttributeNamed: #task_org_node type: OrganisationTreeNode.
>
> aClassModel newAttributeNamed: #task_resource type: Resource.
>
> aClassModel newAttributeNamed: #tasksToStart  collectionOf: TaskAllRelation.
>
> aClassModel newAttributeNamed: #tasksFromEnd collectionOf: TaskAllRelation.
>
> aClassModel newAttributeNamed: #avancementcol collection: OrderedCollection
> of: Avancement.
>
> aClassModel newAttributeNamed: #attachementcol collection: OrderedCollection
> of: Attachement
>
> descriptorForTaskAllRelation: aDescriptor
>
> "Be carefull  the relations start is normally the end of a task the
> relations end is the beginning of a new task"
>
> | table |
>
> table := self tableNamed: 'MMT_TASK_ALL_RELATION'.
>
> aDescriptor table: table.
>
> (aDescriptor newMapping: Glorp.OneToOneMapping)
>
> attributeName: #start_task;
>
> join: (Glorp.Join from: (table fieldNamed: 'start_task')
>
> to: ((self tableNamed: 'MMT_TASK') fieldNamed: 'task_id')).
>
> (aDescriptor newMapping: Glorp.OneToOneMapping)
>
> attributeName: #end_task;
>
> join: (Glorp.Join from: (table fieldNamed: 'end_task')
>
> to: ((self tableNamed: 'MMT_TASK') fieldNamed: 'task_id')).
>
> (aDescriptor newMapping: DirectMapping) from: #margin
>
> to: (table fieldNamed: 'margin').
>
> (aDescriptor newMapping: DirectMapping) from: #type
>
> to: (table fieldNamed: 'type')
>
> descriptorForTask: aDescriptor
>
> | table |
>
> table := self tableNamed: 'MMT_TASK'.
>
> aDescriptor table: table.
>
> aDescriptor addMapping: (DirectMapping from: #key to: (table fieldNamed:
> 'task_id')).
>
> (aDescriptor newMapping: DirectMapping) from: #value to: (table fieldNamed:
> 'task_name').
>
> (aDescriptor newMapping: DirectMapping) from: #task_order to: (table
> fieldNamed: 'task_order').
>
> "Define parent child links"
>
> (aDescriptor newMapping: Glorp.OneToOneMapping)
>
> attributeName: #parent;
>
> useLinkTable;
>
> join: (Glorp.Join from: (table fieldNamed: 'task_id') to: ((self tableNamed:
> 'MMT_TASK_TREE_LINK') fieldNamed: 'CHILD')).
>
> (aDescriptor newMapping: Glorp.ToManyMapping)
>
> attributeName: #children;
>
> useLinkTable;
>
> orderBy: #task_order;
>
> join: (Glorp.Join from: (table fieldNamed: 'task_id') to: ((self tableNamed:
> 'MMT_TASK_TREE_LINK') fieldNamed: 'PARENT')).
>
> "aDescriptor newMapping: Glorp.ToManyMapping."
>
> "====//===="
>
> (aDescriptor newMapping: DirectMapping) from: #outlinenumber to: (table
> fieldNamed: 'outlinenumber').
>
> (aDescriptor newMapping: DirectMapping) from: #proj_id to: (table
> fieldNamed: 'proj_id').
>
> (aDescriptor newMapping: DirectMapping) from: #task_early_finish to: (table
> fieldNamed: 'task_early_finish').
>
> (aDescriptor newMapping: DirectMapping) from: #task_late_start to: (table
> fieldNamed: 'task_late_start').
>
> (aDescriptor newMapping: DirectMapping) from: #task_dur to: (table
> fieldNamed: 'task_dur').
>
> (aDescriptor newMapping: DirectMapping) from: #task_start_date to: (table
> fieldNamed: 'task_start_date').
>
> (aDescriptor newMapping: DirectMapping) from: #task_finish_date to: (table
> fieldNamed: 'task_finish_date').
>
> (aDescriptor newMapping: DirectMapping) from: #task_pct_comp to: (table
> fieldNamed: 'task_pct_comp').
>
> (aDescriptor newMapping: DirectMapping) from: #critical_a to: (table
> fieldNamed: 'critical_a').
>
> (aDescriptor newMapping: DirectMapping) from: #critical_b to: (table
> fieldNamed: 'critical_b').
>
> (aDescriptor newMapping: DirectMapping) from: #critical_c to: (table
> fieldNamed: 'critical_c').
>
> (aDescriptor newMapping: DirectMapping) from: #critical_d to: (table
> fieldNamed: 'critical_d').
>
> (aDescriptor newMapping: DirectMapping) from: #task_type to: (table
> fieldNamed: 'task_type').
>
> (aDescriptor newMapping: DirectMapping) from: #task_creation_date to: (table
> fieldNamed: 'task_creation_date').
>
> (aDescriptor newMapping: DirectMapping) from: #task_early_start to: (table
> fieldNamed: 'task_early_start').
>
> (aDescriptor newMapping: DirectMapping) from: #task_late_finish to: (table
> fieldNamed: 'task_late_finish').
>
> (aDescriptor newMapping: DirectMapping) from: #task_work to: (table
> fieldNamed: 'task_work').
>
> (aDescriptor newMapping: DirectMapping) from: #task_cost to: (table
> fieldNamed: 'task_cost').
>
> (aDescriptor newMapping: DirectMapping) from: #task_fixed_cost to: (table
> fieldNamed: 'task_fixed_cost').
>
> (aDescriptor newMapping: DirectMapping) from: #task_wbs_chain to: (table
> fieldNamed: 'task_wbs_chain').
>
> (aDescriptor newMapping: Glorp.OneToOneMapping) attributeName:
> #task_wbs_node.
>
> (aDescriptor newMapping: DirectMapping) from: #task_org_key to: (table
> fieldNamed: 'task_org_key').
>
> (aDescriptor newMapping: Glorp.OneToOneMapping) attributeName:
> #task_org_node.
>
> (aDescriptor newMapping: Glorp.OneToOneMapping) attributeName:
> #task_resource.
>
> (aDescriptor newMapping: Glorp.ToManyMapping)
>
> attributeName: #tasksFromEnd;
>
> join: (Glorp.Join from: (table fieldNamed: 'task_id')
>
> to: ((self tableNamed: 'MMT_TASK_ALL_RELATION') fieldNamed: 'START_TASK'));
>
> referenceClass: TaskAllRelation.
>
> (aDescriptor newMapping: Glorp.ToManyMapping)
>
> attributeName: #tasksToStart;
>
> join: (Glorp.Join from: (table fieldNamed: 'task_id')
>
> to: ((self tableNamed: 'MMT_TASK_ALL_RELATION') fieldNamed: 'END_TASK'));
>
> referenceClass: TaskAllRelation.
>
> (aDescriptor newMapping: Glorp.ToManyMapping)
>
> attributeName: #avancementcol;
>
> orderBy: #registerdate;
>
> join: (Glorp.Join from: (table fieldNamed: 'task_id')
>
> to: ((self tableNamed: 'MMT_AVANCEMENT') fieldNamed:
> 'avanc_plannedtask_id')).
>
> (aDescriptor newMapping: Glorp.ToManyMapping)
>
> attributeName: #attachementcol;
>
> orderBy: #id;
>
> join: (Glorp.Join from: (table fieldNamed: 'task_id')
>
> to: ((self tableNamed: 'MMT_ATTACHEMENT') fieldNamed:
> 'att_plannedtask_id')).
>
> (aDescriptor newMapping: DirectMapping) from: #msp_uid to: (table
> fieldNamed: 'msp_uid')
>
> tableForMMT_TASK_ALL_RELATION: aTable
>
> | start end |
>
> start := (aTable createFieldNamed: 'start_task' type: platform int4)
>
> bePrimaryKey.
>
> aTable addForeignKeyFrom: start
>
> to: ((self tableNamed: 'MMT_TASK') fieldNamed: 'task_id').
>
> end := (aTable createFieldNamed: 'end_task' type: platform int4)
>
> bePrimaryKey.
>
> aTable addForeignKeyFrom: end
>
> to: ((self tableNamed: 'MMT_TASK') fieldNamed: 'task_id').
>
> aTable createFieldNamed: 'margin' type: platform int4.
>
> aTable createFieldNamed: 'type' type: (platform varchar: 8)
>
> tableForMMT_TASK: aTable
>
> | resource orgnode wbsnode |
>
> (aTable createFieldNamed: 'task_id' type: platform sequence) bePrimaryKey.
>
> aTable createFieldNamed: 'task_name' type: (platform varchar: 255).
>
> aTable createFieldNamed: 'task_order' type: platform int4.
>
> (aTable createFieldNamed: 'proj_id' type: platform integer)
>
> beNullable: true.
>
> aTable createFieldNamed: 'outlinenumber' type: (platform varchar: 255).
> "platform clob."
>
> aTable createFieldNamed: 'msp_uid' type: platform int4.
>
> aTable createFieldNamed: 'task_financial' type: platform boolean.
>
> aTable createFieldNamed: 'task_imputation' type: (platform varchar: 255).
>
> aTable createFieldNamed: 'task_early_finish' type: platform date.
>
> aTable createFieldNamed: 'task_late_start' type: platform date.
>
> (aTable createFieldNamed: 'task_dur' type: platform integer)
>
> beNullable: true.
>
> (aTable createFieldNamed: 'task_start_date' type: platform date)
>
> beNullable: true.
>
> (aTable createFieldNamed: 'task_finish_date' type: platform date)
>
> beNullable: true.
>
> aTable createFieldNamed: 'task_pct_comp' type: platform float.
>
> aTable createFieldNamed: 'task_last_registerdate' type: platform date.
>
> aTable createFieldNamed: 'critical_a' type: platform float.
>
> aTable createFieldNamed: 'critical_b' type: platform float.
>
> aTable createFieldNamed: 'critical_c' type: platform float.
>
> aTable createFieldNamed: 'critical_d' type: platform float.
>
> aTable createFieldNamed: 'task_type' type: platform int2.
>
> aTable createFieldNamed: 'task_creation_date' type: platform timestamp.
>
> aTable createFieldNamed: 'task_early_start' type: platform date.
>
> aTable createFieldNamed: 'task_late_finish' type: platform date.
>
> (aTable createFieldNamed: 'task_cal_uid' type: platform int4)
>
> beNullable: true.
>
> aTable createFieldNamed: 'task_work' type: platform float.
>
> aTable createFieldNamed: 'task_cost' type: platform float.
>
> aTable createFieldNamed: 'task_fixed_cost' type: platform float.
>
> aTable createFieldNamed: 'task_wbs_chain' type: platform clob.
>
> wbsnode := aTable createFieldNamed: 'task_wbs_node' type: platform int4.
>
> aTable addForeignKeyFrom: wbsnode
>
> to: ((self tableNamed: 'MMT_HIERARCHY_TREE_NODE') fieldNamed: 'id').
>
> aTable createFieldNamed: 'task_org_key' type: platform int4.
>
> orgnode := (aTable createFieldNamed: 'task_org_node' type: platform int4)
>
> beNullable: true.
>
> aTable addForeignKeyFrom: orgnode
>
> to: ((self tableNamed: 'MMT_ORGANISATION_TREE_NODE') fieldNamed: 'id').
>
> resource := aTable createFieldNamed: 'task_resource' type: platform int4.
>
> aTable addForeignKeyFrom: resource
>
> to: ((self tableNamed: 'MMT_RESOURCES') fieldNamed: 'res_id')
>
> --
> You received this message because you are subscribed to the Google Groups
> "glorp-group" group.
> To post to this group, send email to [hidden email].
> To unsubscribe from this group, send email to
> [hidden email].
> For more options, visit this group at
> http://groups.google.com/group/glorp-group?hl=en.

--
You received this message because you are subscribed to the Google Groups "glorp-group" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/glorp-group?hl=en.

Reply | Threaded
Open this post in threaded view
|

Re: Deleting on rich link tables

Alan Knight-2
Oh, I'll also mention that Store uses several different link tables
that are mapped to real objects (anything that's <x>InPackage). Some
of those have extra information, though I don't think it should matter
if they do or not. Store doesn't do a lot of deletes, but the garbage
collector does delete things. So it might be useful to look at for
examples.

On Mon, Aug 20, 2012 at 5:04 PM, Alan Knight <[hidden email]> wrote:

> Hi,
>    That's certainly not supposed to happen. What do you mean by "Glorp
> wants to recreate the linked objects". Glorp won't ever create those.
> From the stack you provided the problem is in registerForDelete:. And
> unless your print strings are doing something odd, it appears that the
> object in question is an association from 34 -> '<new task>', but for
> the relation startTask, which isn't a dictionary mapping.  Are you
> storing associations in regular collections, or is that a printString
> that just looks like one?
>
>   In general, the duplicate primary key exception is what it says.
> You've asked to put an object in the cache under a particular primary
> key and there's already a non-identical object there under that key.
> So the question is where it's coming from. If it's doing a
> registerForDelete: it would definitely expect the identical object to
> already be there. So if a non-identical object is being passed in, the
> question is where it's coming from.
>
>   You also don't include the tables, which might be helpful.
>
> Alan
>
> On Sat, Aug 18, 2012 at 7:27 AM,  <[hidden email]> wrote:
>> Hi,
>>
>> I have a link table (two primary keys) wich is mapped itself and holds
>> additinal data about the link (margin and type in this case).
>>
>> If I do so I cannot delete the link in a normal fashion.
>>
>> The moment I want to delete the link, Glorp wants to recreate the linked
>> objects resulting in a: 'Duplicate objects with same primary key' error.
>>
>> I am doing something like this:
>>
>> aModel getGlorpSession inUnitOfWorkDo:
>>
>> [start_task tasksFromEnd remove: self ifAbsent: [].
>>
>> end_task tasksToStart remove: self ifAbsent: [].
>>
>> aModel getGlorpSession delete: self].
>>
>> The error stack is enclosed.
>>
>> The concerned descriptor methods are given below (notice that key is mapped
>> to task_id as Task is subclassed from AssociationTreeWithParent).
>>
>> Nota: I have to say that I have been strugling with deleting objects for
>> years, often I end up writing a direct SQL command followed by refreshing
>> associated objects to clean up Glorp’s cash.
>>
>> Regards,
>>
>> @+Maarten,
>>
>> classModelForTaskAllRelation: aClassModel
>>
>> aClassModel newAttributeNamed: #start_task type: Task.
>>
>> aClassModel newAttributeNamed: #end_task type:  Task.
>>
>> aClassModel newAttributeNamed: #margin.
>>
>> aClassModel newAttributeNamed: #type
>>
>> classModelForTask: aClassModel
>>
>> aClassModel newAttributeNamed: #key.
>>
>> aClassModel newAttributeNamed: #value.
>>
>> aClassModel newAttributeNamed: #proj_id.
>>
>> aClassModel newAttributeNamed: #task_order.
>>
>> aClassModel newAttributeNamed: #parent type: Task.
>>
>> aClassModel newAttributeNamed: #children collectionOf: Task.
>>
>> aClassModel newAttributeNamed: #outlinenumber.
>>
>> aClassModel newAttributeNamed: #msp_uid.
>>
>> aClassModel newAttributeNamed: #task_early_finish type: Date. "fin plustot"
>>
>> aClassModel newAttributeNamed: #task_late_start type: Date. "debut plus
>> tard"
>>
>> aClassModel newAttributeNamed: #task_dur. "duree"
>>
>> aClassModel newAttributeNamed: #task_start_date type: Date. "ordonnancée"
>>
>> aClassModel newAttributeNamed: #task_finish_date type: Date. "ordonnancée"
>>
>> aClassModel newAttributeNamed: #task_pct_comp. "Avancement"
>>
>> aClassModel newAttributeNamed: #critical_a.
>>
>> aClassModel newAttributeNamed: #critical_b.
>>
>> aClassModel newAttributeNamed: #critical_c.
>>
>> aClassModel newAttributeNamed: #critical_d.
>>
>> aClassModel newAttributeNamed: #task_type.
>>
>> aClassModel newAttributeNamed: #task_creation_date type: Date.
>>
>> aClassModel newAttributeNamed: #task_early_start type: Date. "debut plustot"
>>
>> aClassModel newAttributeNamed: #task_late_finish type: Date. "fin plustard"
>>
>> aClassModel newAttributeNamed: #task_cal_uid. "Calender UID"
>>
>> aClassModel newAttributeNamed: #task_work. "Temps ordonnancée"
>>
>> aClassModel newAttributeNamed: #task_cost.
>>
>> aClassModel newAttributeNamed: #task_fixed_cost.
>>
>> aClassModel newAttributeNamed: #task_wbs_chain.
>>
>> aClassModel newAttributeNamed: #task_wbs_node type: HierarchyTreeNode.
>>
>> aClassModel newAttributeNamed: #task_org_key.
>>
>> aClassModel newAttributeNamed: #task_org_node type: OrganisationTreeNode.
>>
>> aClassModel newAttributeNamed: #task_resource type: Resource.
>>
>> aClassModel newAttributeNamed: #tasksToStart  collectionOf: TaskAllRelation.
>>
>> aClassModel newAttributeNamed: #tasksFromEnd collectionOf: TaskAllRelation.
>>
>> aClassModel newAttributeNamed: #avancementcol collection: OrderedCollection
>> of: Avancement.
>>
>> aClassModel newAttributeNamed: #attachementcol collection: OrderedCollection
>> of: Attachement
>>
>> descriptorForTaskAllRelation: aDescriptor
>>
>> "Be carefull  the relations start is normally the end of a task the
>> relations end is the beginning of a new task"
>>
>> | table |
>>
>> table := self tableNamed: 'MMT_TASK_ALL_RELATION'.
>>
>> aDescriptor table: table.
>>
>> (aDescriptor newMapping: Glorp.OneToOneMapping)
>>
>> attributeName: #start_task;
>>
>> join: (Glorp.Join from: (table fieldNamed: 'start_task')
>>
>> to: ((self tableNamed: 'MMT_TASK') fieldNamed: 'task_id')).
>>
>> (aDescriptor newMapping: Glorp.OneToOneMapping)
>>
>> attributeName: #end_task;
>>
>> join: (Glorp.Join from: (table fieldNamed: 'end_task')
>>
>> to: ((self tableNamed: 'MMT_TASK') fieldNamed: 'task_id')).
>>
>> (aDescriptor newMapping: DirectMapping) from: #margin
>>
>> to: (table fieldNamed: 'margin').
>>
>> (aDescriptor newMapping: DirectMapping) from: #type
>>
>> to: (table fieldNamed: 'type')
>>
>> descriptorForTask: aDescriptor
>>
>> | table |
>>
>> table := self tableNamed: 'MMT_TASK'.
>>
>> aDescriptor table: table.
>>
>> aDescriptor addMapping: (DirectMapping from: #key to: (table fieldNamed:
>> 'task_id')).
>>
>> (aDescriptor newMapping: DirectMapping) from: #value to: (table fieldNamed:
>> 'task_name').
>>
>> (aDescriptor newMapping: DirectMapping) from: #task_order to: (table
>> fieldNamed: 'task_order').
>>
>> "Define parent child links"
>>
>> (aDescriptor newMapping: Glorp.OneToOneMapping)
>>
>> attributeName: #parent;
>>
>> useLinkTable;
>>
>> join: (Glorp.Join from: (table fieldNamed: 'task_id') to: ((self tableNamed:
>> 'MMT_TASK_TREE_LINK') fieldNamed: 'CHILD')).
>>
>> (aDescriptor newMapping: Glorp.ToManyMapping)
>>
>> attributeName: #children;
>>
>> useLinkTable;
>>
>> orderBy: #task_order;
>>
>> join: (Glorp.Join from: (table fieldNamed: 'task_id') to: ((self tableNamed:
>> 'MMT_TASK_TREE_LINK') fieldNamed: 'PARENT')).
>>
>> "aDescriptor newMapping: Glorp.ToManyMapping."
>>
>> "====//===="
>>
>> (aDescriptor newMapping: DirectMapping) from: #outlinenumber to: (table
>> fieldNamed: 'outlinenumber').
>>
>> (aDescriptor newMapping: DirectMapping) from: #proj_id to: (table
>> fieldNamed: 'proj_id').
>>
>> (aDescriptor newMapping: DirectMapping) from: #task_early_finish to: (table
>> fieldNamed: 'task_early_finish').
>>
>> (aDescriptor newMapping: DirectMapping) from: #task_late_start to: (table
>> fieldNamed: 'task_late_start').
>>
>> (aDescriptor newMapping: DirectMapping) from: #task_dur to: (table
>> fieldNamed: 'task_dur').
>>
>> (aDescriptor newMapping: DirectMapping) from: #task_start_date to: (table
>> fieldNamed: 'task_start_date').
>>
>> (aDescriptor newMapping: DirectMapping) from: #task_finish_date to: (table
>> fieldNamed: 'task_finish_date').
>>
>> (aDescriptor newMapping: DirectMapping) from: #task_pct_comp to: (table
>> fieldNamed: 'task_pct_comp').
>>
>> (aDescriptor newMapping: DirectMapping) from: #critical_a to: (table
>> fieldNamed: 'critical_a').
>>
>> (aDescriptor newMapping: DirectMapping) from: #critical_b to: (table
>> fieldNamed: 'critical_b').
>>
>> (aDescriptor newMapping: DirectMapping) from: #critical_c to: (table
>> fieldNamed: 'critical_c').
>>
>> (aDescriptor newMapping: DirectMapping) from: #critical_d to: (table
>> fieldNamed: 'critical_d').
>>
>> (aDescriptor newMapping: DirectMapping) from: #task_type to: (table
>> fieldNamed: 'task_type').
>>
>> (aDescriptor newMapping: DirectMapping) from: #task_creation_date to: (table
>> fieldNamed: 'task_creation_date').
>>
>> (aDescriptor newMapping: DirectMapping) from: #task_early_start to: (table
>> fieldNamed: 'task_early_start').
>>
>> (aDescriptor newMapping: DirectMapping) from: #task_late_finish to: (table
>> fieldNamed: 'task_late_finish').
>>
>> (aDescriptor newMapping: DirectMapping) from: #task_work to: (table
>> fieldNamed: 'task_work').
>>
>> (aDescriptor newMapping: DirectMapping) from: #task_cost to: (table
>> fieldNamed: 'task_cost').
>>
>> (aDescriptor newMapping: DirectMapping) from: #task_fixed_cost to: (table
>> fieldNamed: 'task_fixed_cost').
>>
>> (aDescriptor newMapping: DirectMapping) from: #task_wbs_chain to: (table
>> fieldNamed: 'task_wbs_chain').
>>
>> (aDescriptor newMapping: Glorp.OneToOneMapping) attributeName:
>> #task_wbs_node.
>>
>> (aDescriptor newMapping: DirectMapping) from: #task_org_key to: (table
>> fieldNamed: 'task_org_key').
>>
>> (aDescriptor newMapping: Glorp.OneToOneMapping) attributeName:
>> #task_org_node.
>>
>> (aDescriptor newMapping: Glorp.OneToOneMapping) attributeName:
>> #task_resource.
>>
>> (aDescriptor newMapping: Glorp.ToManyMapping)
>>
>> attributeName: #tasksFromEnd;
>>
>> join: (Glorp.Join from: (table fieldNamed: 'task_id')
>>
>> to: ((self tableNamed: 'MMT_TASK_ALL_RELATION') fieldNamed: 'START_TASK'));
>>
>> referenceClass: TaskAllRelation.
>>
>> (aDescriptor newMapping: Glorp.ToManyMapping)
>>
>> attributeName: #tasksToStart;
>>
>> join: (Glorp.Join from: (table fieldNamed: 'task_id')
>>
>> to: ((self tableNamed: 'MMT_TASK_ALL_RELATION') fieldNamed: 'END_TASK'));
>>
>> referenceClass: TaskAllRelation.
>>
>> (aDescriptor newMapping: Glorp.ToManyMapping)
>>
>> attributeName: #avancementcol;
>>
>> orderBy: #registerdate;
>>
>> join: (Glorp.Join from: (table fieldNamed: 'task_id')
>>
>> to: ((self tableNamed: 'MMT_AVANCEMENT') fieldNamed:
>> 'avanc_plannedtask_id')).
>>
>> (aDescriptor newMapping: Glorp.ToManyMapping)
>>
>> attributeName: #attachementcol;
>>
>> orderBy: #id;
>>
>> join: (Glorp.Join from: (table fieldNamed: 'task_id')
>>
>> to: ((self tableNamed: 'MMT_ATTACHEMENT') fieldNamed:
>> 'att_plannedtask_id')).
>>
>> (aDescriptor newMapping: DirectMapping) from: #msp_uid to: (table
>> fieldNamed: 'msp_uid')
>>
>> tableForMMT_TASK_ALL_RELATION: aTable
>>
>> | start end |
>>
>> start := (aTable createFieldNamed: 'start_task' type: platform int4)
>>
>> bePrimaryKey.
>>
>> aTable addForeignKeyFrom: start
>>
>> to: ((self tableNamed: 'MMT_TASK') fieldNamed: 'task_id').
>>
>> end := (aTable createFieldNamed: 'end_task' type: platform int4)
>>
>> bePrimaryKey.
>>
>> aTable addForeignKeyFrom: end
>>
>> to: ((self tableNamed: 'MMT_TASK') fieldNamed: 'task_id').
>>
>> aTable createFieldNamed: 'margin' type: platform int4.
>>
>> aTable createFieldNamed: 'type' type: (platform varchar: 8)
>>
>> tableForMMT_TASK: aTable
>>
>> | resource orgnode wbsnode |
>>
>> (aTable createFieldNamed: 'task_id' type: platform sequence) bePrimaryKey.
>>
>> aTable createFieldNamed: 'task_name' type: (platform varchar: 255).
>>
>> aTable createFieldNamed: 'task_order' type: platform int4.
>>
>> (aTable createFieldNamed: 'proj_id' type: platform integer)
>>
>> beNullable: true.
>>
>> aTable createFieldNamed: 'outlinenumber' type: (platform varchar: 255).
>> "platform clob."
>>
>> aTable createFieldNamed: 'msp_uid' type: platform int4.
>>
>> aTable createFieldNamed: 'task_financial' type: platform boolean.
>>
>> aTable createFieldNamed: 'task_imputation' type: (platform varchar: 255).
>>
>> aTable createFieldNamed: 'task_early_finish' type: platform date.
>>
>> aTable createFieldNamed: 'task_late_start' type: platform date.
>>
>> (aTable createFieldNamed: 'task_dur' type: platform integer)
>>
>> beNullable: true.
>>
>> (aTable createFieldNamed: 'task_start_date' type: platform date)
>>
>> beNullable: true.
>>
>> (aTable createFieldNamed: 'task_finish_date' type: platform date)
>>
>> beNullable: true.
>>
>> aTable createFieldNamed: 'task_pct_comp' type: platform float.
>>
>> aTable createFieldNamed: 'task_last_registerdate' type: platform date.
>>
>> aTable createFieldNamed: 'critical_a' type: platform float.
>>
>> aTable createFieldNamed: 'critical_b' type: platform float.
>>
>> aTable createFieldNamed: 'critical_c' type: platform float.
>>
>> aTable createFieldNamed: 'critical_d' type: platform float.
>>
>> aTable createFieldNamed: 'task_type' type: platform int2.
>>
>> aTable createFieldNamed: 'task_creation_date' type: platform timestamp.
>>
>> aTable createFieldNamed: 'task_early_start' type: platform date.
>>
>> aTable createFieldNamed: 'task_late_finish' type: platform date.
>>
>> (aTable createFieldNamed: 'task_cal_uid' type: platform int4)
>>
>> beNullable: true.
>>
>> aTable createFieldNamed: 'task_work' type: platform float.
>>
>> aTable createFieldNamed: 'task_cost' type: platform float.
>>
>> aTable createFieldNamed: 'task_fixed_cost' type: platform float.
>>
>> aTable createFieldNamed: 'task_wbs_chain' type: platform clob.
>>
>> wbsnode := aTable createFieldNamed: 'task_wbs_node' type: platform int4.
>>
>> aTable addForeignKeyFrom: wbsnode
>>
>> to: ((self tableNamed: 'MMT_HIERARCHY_TREE_NODE') fieldNamed: 'id').
>>
>> aTable createFieldNamed: 'task_org_key' type: platform int4.
>>
>> orgnode := (aTable createFieldNamed: 'task_org_node' type: platform int4)
>>
>> beNullable: true.
>>
>> aTable addForeignKeyFrom: orgnode
>>
>> to: ((self tableNamed: 'MMT_ORGANISATION_TREE_NODE') fieldNamed: 'id').
>>
>> resource := aTable createFieldNamed: 'task_resource' type: platform int4.
>>
>> aTable addForeignKeyFrom: resource
>>
>> to: ((self tableNamed: 'MMT_RESOURCES') fieldNamed: 'res_id')
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "glorp-group" group.
>> To post to this group, send email to [hidden email].
>> To unsubscribe from this group, send email to
>> [hidden email].
>> For more options, visit this group at
>> http://groups.google.com/group/glorp-group?hl=en.

--
You received this message because you are subscribed to the Google Groups "glorp-group" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/glorp-group?hl=en.