View Full Version : Successful post, but infinite update loop after

3 Dec 2012, 6:30 AM
Hi, I am having very strange issue with my code.
I have two models Company and Warehouse associated in following way:
Company hasOne Warehouse -> client (extjs) side
Company is associated with Warehouse on primary key join column manner -> hibernate, server

Problem occurs when I try to create new company along with warehouse and this is what I am sending to the server


I am able to receive successful server's answer that both company and warehouse had been insterted into tables.
This is the answer

action: "CREATE"
data: [{longName:d, warehouse:{id:4, name:d, createdDate:0-338-2012, description:d, usage:0, size:100},}]

0: {longName:d, warehouse:{id:4, name:d, createdDate:0-338-2012, description:d, usage:0, size:100},}

id: 4
longName: "d"
name: "d"
warehouse: {id:4, name:d, createdDate:0-338-2012, description:d, usage:0, size:100}

createdDate: "0-338-2012"
description: "d"
id: 4
name: "d"
size: 100
usage: 0

entity: "wms.model.Company"
handler: "wms.controller.CompanyController"
message: "CREATE took 108ms and affected 1 rows"
success: true
time: 108
total: 1

As you can see company and warehouse ID are the same which is good. But right after POST, PUT is triggered with following payload

Here warehouse_id is magically gone and I don't have any idea why.

In one word client goes in infinite loop with server by sending PUT request with exact same payload and receiving exact same answers with the difference on action in response's object.

Here is the code for company and warehouse model on the client side

Ext.define('WMS.model.entity.Company', {
extend : 'WMS.model.abstract.Simple',
requires : [
fields : [
{ name: 'longName', type: 'string' },
{ name: 'warehouse_id', type: 'int', mapping: 'warehouse.id'}
associations: [
type : 'hasOne',
name : 'warehouse',
associationName: 'warehouse',
instanceName : 'warehouse',
foreignKey : 'warehouse_id',
model : 'WMS.model.entity.Warehouse',
getterName : 'setWarehouse',
setterName : 'getWarehouse'
proxy : {
type : 'wms',
url : 'wms/agent/company',
writer: {
type : 'json',
root : 'data',
allowSingle : false,
writeAllFields: false,
getRecordData : function (record, operation) {
var company,
action = operation['action'];
if (action === 'create') {
var company = record.getData(),
warehouse = record['warehouse'];

company['warehouse'] = warehouse.getData();
var warehouseID = company['warehouse_id'];
if (Ext.isDefined(warehouseID) && warehouseID === 0) {
delete company['warehouse_id'];
} else {
company = record.getData();
return company;

Ext.define('WMS.model.entity.Warehouse', {
extend : 'WMS.model.abstract.DescribedSimple',
fields : [
{ name: 'usage', type: 'float', defaultValue: 0.0, convert: convertUsage},
{ name: 'size', type: 'int', defaultValue: 0},
{ name: 'createdDate', type: 'date', serialize: serializeDate}
proxy : {
type: 'wms',
url : 'wms/agent/warehouse'

4 Dec 2012, 3:52 AM
What is in the 'data' property of records you got after server response to POST?

4 Dec 2012, 5:02 AM
Thanks for the feedback but I am forced to deny any more help.
The problem was in the following fragment of the code

getterName : 'setWarehouse'
setterName : 'getWarehouse'

I think that it could be more hilarious...
thanks anyway ;-)