hibernate - spring boot jpa hibernate - 获取主详细数据
问题描述
我有两张桌子
ORDERS
ORDERITEMS
ORDERS will be having columns - ORDERS_ID, STATUS, TIMEPLACED,FIELD1,FIELD2,LASTUPDATE
ORDERITEMS is having columns - ORDERITEMS_ID, ORDERS_ID,PARTNUM,STATUS,FIELD1,FIELD2.
我的要求是获取以下 JSON 格式的数据
{
"orders_id":"1234",
"status":"C",
"timeplaced":"2018-05-10",
orderitems:[
{
orderitems_id="7",
orders_id="1234",
status="C"
},{
orderitems_id = 8,
orders_id = 1234,
status='C'
}
]
}
这里的 ORDER 详细信息就像我的响应中的标题,而 items 是与标题中存在的订单 ID 相对应的 orderitems 数组。
但是当我在 orderitems 实体上使用 ManyToOne 时,每个 orderitem id 都会重复订单详细信息。但这不是我想要的。我想在父级别获得订单详细信息,在子级别获得项目详细信息。
是否可以扩展 CrudRepository 或者我应该使用 HQL 查询?如果可能的话,你能给我一个方法吗?
解决方案
推荐阅读
- javascript - 使用 Web USB API 接收大于 64 字节的字符串
- python - .wav 文件是否会生成任何函数
- docker - docker运行找不到目录
- python - Pandas 将应用结果转换回原始数据框
- java - android java中的foregroundService
- perl - perl:使用 Digest::SHA3,使用网上的基本示例,输出的位值将其设置为 160,这表示哈希长度较弱(?)
- c++ - C ++中的排列
- html - 如何修复手机设备上的模糊徽标?
- javascript - 通过 call() 调用父类的构造函数
- flutter - 有没有办法在 ButtonBar 中懒惰地显示 RaisedButtons?