第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

無(wú)法為第二種情況映射 OneToMany 和 ManyToOne?

無(wú)法為第二種情況映射 OneToMany 和 ManyToOne?

幕布斯6054654 2023-09-20 15:53:42
我正在嘗試存儲(chǔ)用戶發(fā)出的訂單的集合。一個(gè)用戶可能有多個(gè)訂單,但一個(gè)訂單只有一個(gè)用戶。這樣就形成了1-M關(guān)系。Items 和 ItemOrders 之間也存在相同的關(guān)系,ItemOrder 由一個(gè) Item 和一定數(shù)量的要訂購(gòu)的 Items 組成。因此,一個(gè) ItemOrder 有一個(gè) Item,但一個(gè) Item 可以有多個(gè) ItemOrder。在我的測(cè)試套件中,我成功地正確創(chuàng)建了 Items 和 ItemOrders。但是,當(dāng)我擴(kuò)展測(cè)試以創(chuàng)建用戶和訂單時(shí),我收到“訂單”的 SQLSyntaxErrorException...這很奇怪,因?yàn)樗鼞?yīng)該是實(shí)現(xiàn)這兩種結(jié)果的完全相同的過程...而且我不知道是什么我在這里做錯(cuò)了,有什么想法嗎?@Entitypublic class ItemEntity implements EntityInt {    @Id    @GeneratedValue(generator = "incrementor")    @Column(name = "item_id", unique = true)    public int id;    @OneToMany(mappedBy="item")    public Set<OrderItemEntity> orderItems = new HashSet<>();}@Entitypublic class OrderItemEntity implements EntityInt {    @Id    @GeneratedValue(generator = "incrementor")    @Column(name = "order_item_id", unique = true)    public int id;    @Column(name = "amount", nullable = false)    public int amount;    @ManyToOne    @JoinColumn(name="item_id", nullable = false)    private ItemEntity item;    public OrderItemEntity(ItemEntity item, int amount) {        this.setItem(item);        this.amount = amount;    }    public void setItem(ItemEntity item) {        if (this.item != null)            this.item.orderItems.remove(this);        this.item = item;        this.item.orderItems.add(this);    }}@Entitypublic class OrderEntity implements EntityInt {    @Id    @GeneratedValue(generator = "incrementor")    @Column(name = "order_id", unique = true)    public int id;    @ManyToOne    @JoinColumn(name="user_id", nullable = false)    public UserEntity user;    public UserEntity getUser() {        return user;    }    public void setUser(UserEntity user) {        if (this.user != null)            this.user.orders.remove(this);        this.user = user;        this.user.orders.add(this);    }}EntityInt 包含主要由 BasicDao 用于執(zhí)行 CRUD 操作的方法。它有 getId()、getVersion()、createVerifyIsUnqieuQuery() 等內(nèi)容。
查看完整描述

1 回答

?
哈士奇WWW

TA貢獻(xiàn)1799條經(jīng)驗(yàn) 獲得超6個(gè)贊

“您的 SQL 語(yǔ)法有錯(cuò)誤;請(qǐng)檢查與您的 MySQL 服務(wù)器版本對(duì)應(yīng)的手冊(cè)以獲取正確的語(yǔ)法錯(cuò)誤” Hibernate 4

問題是我將我的表命名為“訂單”。這是從上面的堆棧跟蹤中獲得的。


查看完整回答
反對(duì) 回復(fù) 2023-09-20
  • 1 回答
  • 0 關(guān)注
  • 98 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)