Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jpa 正在保存游戏中相关对象的列表!表单的框架1.x_Jpa_Playframework 1.x - Fatal编程技术网

Jpa 正在保存游戏中相关对象的列表!表单的框架1.x

Jpa 正在保存游戏中相关对象的列表!表单的框架1.x,jpa,playframework-1.x,Jpa,Playframework 1.x,我在游戏模型中有一个Offer对象,它可以有一条或多条offerline,所以我有 @Required @ManyToOne public Offer offer; 论奥弗林 及 但是我的offerline不在JSON中,也就是说,它们似乎没有在Offer对象中传递回。如何在一个屏幕中编辑和保存与报价相关的报价线列表 [更新]我测试了传递给表单的MyOffer对象,它有offerlines,但它不会再次返回 { "offerLines": [ { "swag":

我在游戏模型中有一个Offer对象,它可以有一条或多条offerline,所以我有

@Required
@ManyToOne
public Offer offer;
论奥弗林

但是我的offerline不在JSON中,也就是说,它们似乎没有在Offer对象中传递回。如何在一个屏幕中编辑和保存与报价相关的报价线列表

[更新]我测试了传递给表单的MyOffer对象,它有offerlines,但它不会再次返回

    {
  "offerLines": [
    {
      "swag": {
        "Name": "Test Swag",
        "Description": "Big ol' test swag",
        "Quantity": 10,
        "Owner": {
          "username": "robcowell",
          "password": "REDACTED",
          "email": "REDACTED",
          "fullname": "Rob Cowell",
          "isAdmin": true,
          "isActive": true,
          "Photo": {
            "bucket": "REDACTED",
            "key": "d5654f8f-0cd0-45a2-a77f-3edda01feca0",
            "contentLength": 0
          },
          "hasChangedPassword": true,
          "id": 1
        },
        "Photo": {
          "bucket": "REDACTED",
          "key": "b0774667-a32a-4508-81ba-cdb84ebc689f",
          "contentLength": 0
        },
        "id": 52
      },
      "quantity": 0,
      "id": 134
    },
    {
      "swag": {
        "Name": "Swag 2",
        "Description": "Swag 2",
        "Quantity": 5,
        "Owner": {
          "username": "robcowell",
          "password": "REDACTED",
          "email": "REDACTED",
          "fullname": "Rob Cowell",
          "isAdmin": true,
          "isActive": true,
          "Photo": {
            "bucket": "REDACTED",
            "key": "d5654f8f-0cd0-45a2-a77f-3edda01feca0",
            "contentLength": 0
          },
          "hasChangedPassword": true,
          "id": 1
        },
        "id": 54
      },
      "quantity": 0,
      "id": 135
    },
    {
      "swag": {
        "Name": "Swag 3",
        "Description": "Mo' Swag",
        "Quantity": 1,
        "Owner": {
          "username": "robcowell",
          "password": "REDACTED",
          "email": "REDACTED",
          "fullname": "Rob Cowell",
          "isAdmin": true,
          "isActive": true,
          "Photo": {
            "bucket": "REDACTED",
            "key": "d5654f8f-0cd0-45a2-a77f-3edda01feca0",
            "contentLength": 0
          },
          "hasChangedPassword": true,
          "id": 1
        },
        "id": 55
      },
      "quantity": 0,
      "id": 136
    },
    {
      "swag": {
        "Name": "Test swag with an inordinately long name purely for the purposes of testing the rendering of these columns",
        "Description": "As above",
        "Quantity": 1,
        "Owner": {
          "username": "robcowell",
          "password": "REDACTED",
          "email": "REDACTED",
          "fullname": "Rob Cowell",
          "isAdmin": true,
          "isActive": true,
          "Photo": {
            "bucket": "REDACTED",
            "key": "d5654f8f-0cd0-45a2-a77f-3edda01feca0",
            "contentLength": 0
          },
          "hasChangedPassword": true,
          "id": 1
        },
        "id": 60
      },
      "quantity": 0,
      "id": 137
    }
  ],
  "offerTo": {
    "username": "todd",
    "password": "REDACTED",
    "email": "REDACTED",
    "fullname": "Todd Halfpenny",
    "isAdmin": false,
    "isActive": true,
    "hasChangedPassword": true,
    "id": 20
  },
  "offerFrom": {
    "username": "robcowell",
    "password": "REDACTED",
    "email": "REDACTED",
    "fullname": "Rob Cowell",
    "isAdmin": true,
    "isActive": true,
    "Photo": {
      "bucket": "REDACTED",
      "key": "d5654f8f-0cd0-45a2-a77f-3edda01feca0",
      "contentLength": 0
    },
    "hasChangedPassword": true,
    "id": 1
  },
  "targetSwag": {
    "Name": "Todd's tshirts",
    "Description": "Nice tshirts by Todd",
    "Quantity": 10,
    "Owner": {
      "username": "todd",
      "password": "REDACTED",
      "email": "REDACTED",
      "fullname": "Todd",
      "isAdmin": false,
      "isActive": true,
      "hasChangedPassword": true,
      "id": 20
    },
    "Photo": {
      "bucket": "REDACTED",
      "key": "f627cbcf-7eba-400d-a1f9-dcf1ab457709",
      "contentLength": 0
    },
    "id": 53
  },
  "id": 133
}

您可以尝试以下方法来设置索引以处理数组

#{list items:myOffer.offerLines, as:'offerline'}

<tr>
<td height="32" width="30"><input type="text" id="offerline.id" name="offerline[${offerline_index-1}].id" value="${offerline.id}"/></td>
<td height="32" width="80">
    ${offerline.swag.Name}
</td>
<td height="32">
    <input class="field" id="offerline.quantity" name="offerline[${offerline_index-1}].quantity" type="number" min="0" max="${offerline.swag.Quantity}" value="${offerline.quantity}"/>
</td>
</tr> 
#{/list}
#{列出项目:myOffer.offerline,如:'offerline'}
${offerline.swag.Name}
#{/list}

在进入表单的过程中测试了对象JSON,并且Offerlines存在。我还没有测试,但我猜在返回submitOffer的过程中,没有
myoffer.id
链接回您提交的Offerlines。可能会添加一个带有报价id的隐藏字段。你在打印行中看到了什么?是的,传递myOffer.Id,但是println给出了前后的差异-
Offerlines传递到表单-[149(Test Swag-0)、150(Swag 2-0)、151(Swag 3-0)、152(Test Swag的过长名称纯粹是为了测试这些列的呈现效果-0)]下载swag 1 swag照片utils。S3Blob@faec98请求1我的报价148 Todd's T恤Offerlines[]
因此在submitOffer方法中,myOffer的“父”属性似乎已设置,但我的Offerlines集合将被删除如果您签出,这表明对于POJO阵列,它需要http数组表示法,但没有造成任何影响。我将名称更改为
myOfffer.offerLines[${offerline_index-1}]
以进一步尝试强制绑定,现在我得到了
org.hibernate.PersistentObjectException:传递给persist:models.OfferLine的分离实体
-调用它一个晚上,现在就睡在上面我假设这个错误消息至少意味着您现在在调用submitOffer操作时正在接收offerLines在Offer对象上?我想你现在进入了JPA领域,这超出了我的深度(我已经把JPA抛在后面,并开始着手开发SQL,原因正是这些,在Play2和Kotlin web框架上都是如此),.Fix似乎正在根据这个答案将CascadeType设置为在关系的提供端合并-
#{form @submitOffer(), id:'submitOffer'}
<table border="1">
    <thead>
    <tr>
        <th width="30" align="left">ID</th>
        <th width="80" align="left">Swag</th>
        <th width="30" align="left">Quantity</th>
    </tr>
    </thead>
    <tbody>
    #{list items:myOffer.offerLines, as:'offerline'}

    <tr>
    <td height="32" width="30"><input type="text" id="offerline.id" 
name="offerline.id" value="${offerline.id}"/></td>
    <td height="32" width="80">
        ${offerline.swag.Name}
    </td>
    <td height="32">
        <input class="field" id="offerline.quantity" name="offerline.quantity" type="number" min="0" max="${offerline.swag.Quantity}" value="${offerline.quantity}"/>
    </td>
</tr>
    #{/list}
    </tbody>
</table>
public static void submitOffer(Integer amountRequested, Offer myOffer)
{
    myOffer.save();
    System.out.println("Requested " + amountRequested);
    System.out.println("My offer coming out " + myOffer.toString());


    renderJSON(myOffer);

}
    {
  "offerLines": [
    {
      "swag": {
        "Name": "Test Swag",
        "Description": "Big ol' test swag",
        "Quantity": 10,
        "Owner": {
          "username": "robcowell",
          "password": "REDACTED",
          "email": "REDACTED",
          "fullname": "Rob Cowell",
          "isAdmin": true,
          "isActive": true,
          "Photo": {
            "bucket": "REDACTED",
            "key": "d5654f8f-0cd0-45a2-a77f-3edda01feca0",
            "contentLength": 0
          },
          "hasChangedPassword": true,
          "id": 1
        },
        "Photo": {
          "bucket": "REDACTED",
          "key": "b0774667-a32a-4508-81ba-cdb84ebc689f",
          "contentLength": 0
        },
        "id": 52
      },
      "quantity": 0,
      "id": 134
    },
    {
      "swag": {
        "Name": "Swag 2",
        "Description": "Swag 2",
        "Quantity": 5,
        "Owner": {
          "username": "robcowell",
          "password": "REDACTED",
          "email": "REDACTED",
          "fullname": "Rob Cowell",
          "isAdmin": true,
          "isActive": true,
          "Photo": {
            "bucket": "REDACTED",
            "key": "d5654f8f-0cd0-45a2-a77f-3edda01feca0",
            "contentLength": 0
          },
          "hasChangedPassword": true,
          "id": 1
        },
        "id": 54
      },
      "quantity": 0,
      "id": 135
    },
    {
      "swag": {
        "Name": "Swag 3",
        "Description": "Mo' Swag",
        "Quantity": 1,
        "Owner": {
          "username": "robcowell",
          "password": "REDACTED",
          "email": "REDACTED",
          "fullname": "Rob Cowell",
          "isAdmin": true,
          "isActive": true,
          "Photo": {
            "bucket": "REDACTED",
            "key": "d5654f8f-0cd0-45a2-a77f-3edda01feca0",
            "contentLength": 0
          },
          "hasChangedPassword": true,
          "id": 1
        },
        "id": 55
      },
      "quantity": 0,
      "id": 136
    },
    {
      "swag": {
        "Name": "Test swag with an inordinately long name purely for the purposes of testing the rendering of these columns",
        "Description": "As above",
        "Quantity": 1,
        "Owner": {
          "username": "robcowell",
          "password": "REDACTED",
          "email": "REDACTED",
          "fullname": "Rob Cowell",
          "isAdmin": true,
          "isActive": true,
          "Photo": {
            "bucket": "REDACTED",
            "key": "d5654f8f-0cd0-45a2-a77f-3edda01feca0",
            "contentLength": 0
          },
          "hasChangedPassword": true,
          "id": 1
        },
        "id": 60
      },
      "quantity": 0,
      "id": 137
    }
  ],
  "offerTo": {
    "username": "todd",
    "password": "REDACTED",
    "email": "REDACTED",
    "fullname": "Todd Halfpenny",
    "isAdmin": false,
    "isActive": true,
    "hasChangedPassword": true,
    "id": 20
  },
  "offerFrom": {
    "username": "robcowell",
    "password": "REDACTED",
    "email": "REDACTED",
    "fullname": "Rob Cowell",
    "isAdmin": true,
    "isActive": true,
    "Photo": {
      "bucket": "REDACTED",
      "key": "d5654f8f-0cd0-45a2-a77f-3edda01feca0",
      "contentLength": 0
    },
    "hasChangedPassword": true,
    "id": 1
  },
  "targetSwag": {
    "Name": "Todd's tshirts",
    "Description": "Nice tshirts by Todd",
    "Quantity": 10,
    "Owner": {
      "username": "todd",
      "password": "REDACTED",
      "email": "REDACTED",
      "fullname": "Todd",
      "isAdmin": false,
      "isActive": true,
      "hasChangedPassword": true,
      "id": 20
    },
    "Photo": {
      "bucket": "REDACTED",
      "key": "f627cbcf-7eba-400d-a1f9-dcf1ab457709",
      "contentLength": 0
    },
    "id": 53
  },
  "id": 133
}
#{list items:myOffer.offerLines, as:'offerline'}

<tr>
<td height="32" width="30"><input type="text" id="offerline.id" name="offerline[${offerline_index-1}].id" value="${offerline.id}"/></td>
<td height="32" width="80">
    ${offerline.swag.Name}
</td>
<td height="32">
    <input class="field" id="offerline.quantity" name="offerline[${offerline_index-1}].quantity" type="number" min="0" max="${offerline.swag.Quantity}" value="${offerline.quantity}"/>
</td>
</tr> 
#{/list}