オブジェクトではなく、関連するすべてのテーブルに id を含むオブジェクトを返すために、休止状態でサブセレクトを使用しています。
これは私が定義したdtoです
@Entity
@Subselect("select di.id as id, user.id as userId, client.id as clientId, controller.id as controllerId,"
+ "supplier.id as supplierId, grade.id as gradeId, packing.id as packingId, warehouse.id as warehouseId,"
+ "qualityController.id as qualityControllerId,"
+ "companyMasterByPledger.id as pledgerId,"
+ "di.refNumber as refNumber,"
+ "di.clientRef as clientRef,"
+ "di.date as date,"
+ "di.supplierRef as supplierRef,"
+ "di.tons as tons,"
+ "di.kgPerBag as kgPerBag,"
+ "di.noOfBags as noOfBags,"
+ "di.deliveryDate as deliveryDate,"
+ "di.fromTime as fromTime,"
+ "di.toTime as toTime,"
+ "di.markingOnBags as markingOnBags,"
+ "di.originId as originId,"
+ "di.qualityId as qualityId,"
+ "di.remarks as remarks,"
+ "di.status as status,"
+ "di.log as log "
+ "from DeliveryInstruction as di "
+ "left join di.user as user "
+ "left join di.companyMasterByClientId as client "
+ "left join di.companyMasterByWeightControllerId as controller "
+ "left join di.companyMasterBySupplierId as supplier "
+ "left join di.gradeMaster as grade "
+ "left join di.packingMaster as packing "
+ "left join di.companyMasterByQualityControllerId as qualityController "
+ "left join di.companyMasterByPledger as pledger "
+ "left join di.warehouse as warehouse")
@Synchronize({"DeliveryInstruction"})
public class DeliveryView implements Serializable{
private Integer id;
private Integer userId;
private Integer clientId;
private Integer controllerId;
private Integer supplierId;
private Integer gradeId;
private Integer packingId;
private Integer warehouseId;
private Integer qualityControllerId;
private Integer pledgerId;
private String refNumber;
private String clientRef;
private Date date;
private String supplierRef;
private Double tons;
private Float kgPerBag;
private Integer noOfBags;
private Date deliveryDate;
private String fromTime;
private String toTime;
private String markingOnBags;
private Integer originId;
private Integer qualityId;
private String remark;
private Byte status;
private String log;
public DeliveryView() {
}
public DeliveryView(Integer id, Integer userId, Integer clientId, Integer controllerId, Integer supplierId, Integer gradeId, Integer packingId, Integer warehouseId, Integer qualityControllerId, Integer pledgerId, String refNumber, String clientRef, Date date, String supplierRef, Double tons, Float kgPerBag, Integer noOfBags, Date deliveryDate, String fromTime, String toTime, String markingOnBags, Integer originId, Integer qualityId, String remark, Byte status, String log) {
this.id = id;
this.userId = userId;
this.clientId = clientId;
this.controllerId = controllerId;
this.supplierId = supplierId;
this.gradeId = gradeId;
this.packingId = packingId;
this.warehouseId = warehouseId;
this.qualityControllerId = qualityControllerId;
this.pledgerId = pledgerId;
this.refNumber = refNumber;
this.clientRef = clientRef;
this.date = date;
this.supplierRef = supplierRef;
this.tons = tons;
this.kgPerBag = kgPerBag;
this.noOfBags = noOfBags;
this.deliveryDate = deliveryDate;
this.fromTime = fromTime;
this.toTime = toTime;
this.markingOnBags = markingOnBags;
this.originId = originId;
this.qualityId = qualityId;
this.remark = remark;
this.status = status;
this.log = log;
}
@Id
public Integer getId() {
return id;
}
// ... others getter and setter
}
DAOクラスでは、メソッドは以下のようになります
public DeliveryView getDiById(int id) {
return (DeliveryView) getHibernateTemplate().get(DeliveryView.class, id);
}
ただし、上記の方法を使用すると、null が返されました。
メソッドを実行すると、コンソールに出力されるスクリプトは
select deliveryvi0_.id as id36_0_, deliveryvi0_.clientId as clientId36_0_, deliveryvi0_.clientRef as clientRef36_0_, deliveryvi0_.controllerId as controll4_36_0_, deliveryvi0_.date as date36_0_, deliveryvi0_.deliveryDate as delivery6_36_0_, deliveryvi0_.fromTime as fromTime36_0_, deliveryvi0_.gradeId as gradeId36_0_, deliveryvi0_.kgPerBag as kgPerBag36_0_, deliveryvi0_.log as log36_0_, deliveryvi0_.markingOnBags as marking11_36_0_, deliveryvi0_.noOfBags as noOfBags36_0_, deliveryvi0_.originId as originId36_0_, deliveryvi0_.packingId as packingId36_0_, deliveryvi0_.pledgerId as pledgerId36_0_, deliveryvi0_.qualityControllerId as quality16_36_0_, deliveryvi0_.qualityId as qualityId36_0_, deliveryvi0_.refNumber as refNumber36_0_, deliveryvi0_.remark as remark36_0_, deliveryvi0_.status as status36_0_, deliveryvi0_.supplierId as supplierId36_0_, deliveryvi0_.supplierRef as supplie22_36_0_, deliveryvi0_.toTime as toTime36_0_, deliveryvi0_.tons as tons36_0_, deliveryvi0_.userId as userId36_0_, deliveryvi0_.warehouseId as warehou26_36_0_ from DeliveryView deliveryvi0_ where deliveryvi0_.id=?
存在しない DeliveryView テーブルからデータを取得します。必要なのは、DeliveryInstruction テーブルからデータを取得することです。修正するのを手伝ってください、ありがとう
P / s:私は春と休止状態を使用しています.Jacksonと連携して多くの冗長な情報がロードされるのを防ぐためにこの方法を行っています(Jackson休止状態モジュールを使用しましたが、idだけではなく多くの不要な情報を返しました) . もっと良いアイデアがあれば教えてください、ありがとう。
- 更新: @subselect のスクリプトが実行されないことがわかりました。「get(DeliveryView.class, id)」メソッドを呼び出すと、デフォルトのスクリプト「select * from deliveryView」が実行されます。
更新:これは私がチェックしたネイティブスクリプトです
id として di.id、userId として user.id、clientId として client.id、controllerId として controller.id、supplierId としてsupplier.id、gradeId として grade.id、packingId としてpacking.id、warehouseId として Warehouse.id、qualityController を選択します。 .id (qualityControllerId)、pledger.id (pledgerId)、di.ref_number (refNumber)、di.client_ref (clientRef)、di.date (日付)、di.supplier_ref (supplierRef)、di.tons (トン)、di.kg_per_bag (kgPerBag)、di.no_of_bags noOfBags として di.delivery_date、deliveryDate として di.from_time、toTime として di.to_time、markingOnBags として di.marking_on_bags、originId として di.origin_id、qualityId として di.quality_id、remarks として di.remark、status として di.status 、ディ。delivery_instruction からのログとして記録 di left user.id = di.user_id でユーザーに参加 左 client.id = di.client_id で company_master クライアントに参加 左 controller.id = di.weight_controller_id で company_master コントローラーに参加 左 Supplier.id = で company_master サプライヤーに参加di.supplier_id は、grade.id = di.grade_id で grade_master グレードに参加しました。packing.id = di.packing_id で、packing_master に参加しました。左は、qualityController.id で company_master qualityController に参加しました。誓約者は、warehouse.id = di.warehouse_id で di.id = 21 の倉庫に参加しましたclient_id は左から controller.id = di.weight_controller_id で company_master コントローラーに参加しますqualityController.id = di.quality_controller_id で company_master qualityController に参加する Pledger.id = di.pledger で company_master Pledger に参加する Warehouse.id = di.warehouse_id で倉庫に参加する di.id = 21client_id は左から controller.id = di.weight_controller_id で company_master コントローラーに参加しますqualityController.id = di.quality_controller_id で company_master qualityController に参加する Pledger.id = di.pledger で company_master Pledger に参加する Warehouse.id = di.warehouse_id で倉庫に参加する di.id = 21packing_id は左 qualityController.id で company_master qualityController に参加 = di.quality_controller_id 左 Pledger.id で company_master 誓約者に参加 = di.pledger 左 Warehouse.id = di.warehouse_id で倉庫に参加 di.id = 21packing_id は左 qualityController.id で company_master qualityController に参加 = di.quality_controller_id 左 Pledger.id で company_master 誓約者に参加 = di.pledger 左 Warehouse.id = di.warehouse_id で倉庫に参加 di.id = 21