将 OneToOne link 更改为具有另一个 ID 的另一个实体
Change OneToOne link into another entity with another id
有问题但找不到答案 =)
我有实体包装
@Entity
public class Packing {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seq_packing")
@SequenceGenerator(allocationSize = 100, name="seq_packing", sequenceName="seq_packing")
@Getter
long id;
@Getter
@Setter
@OneToOne
PackingDictionary packingDictionary;
@Getter
@Setter
long price;
@Getter
@Setter
long quantity;
public Packing() {
}
public Packing(PackingDictionary packingDictionary, long price, long quantity) {
this.packingDictionary = packingDictionary;
this.price = price;
this.quantity = quantity;
}
public void changePackingType(Long id){
}
}
我使用 OneToOne 关系在 Packing 实体和 PackingDictionary(实际上是字典)之间进行引用。
那么我怎样才能创建一个方法来更改对字典中另一个已经存在的 id 的引用?
在 SQL 中,它只会更改 PACKING table 中的引用 ID。
packingRepository.findById(id)
.ifPresent(packing -> packing.setPackingDictionary(packingDictionaryRepository.getOne(dictionaryId))
有问题但找不到答案 =)
我有实体包装
@Entity
public class Packing {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seq_packing")
@SequenceGenerator(allocationSize = 100, name="seq_packing", sequenceName="seq_packing")
@Getter
long id;
@Getter
@Setter
@OneToOne
PackingDictionary packingDictionary;
@Getter
@Setter
long price;
@Getter
@Setter
long quantity;
public Packing() {
}
public Packing(PackingDictionary packingDictionary, long price, long quantity) {
this.packingDictionary = packingDictionary;
this.price = price;
this.quantity = quantity;
}
public void changePackingType(Long id){
}
}
我使用 OneToOne 关系在 Packing 实体和 PackingDictionary(实际上是字典)之间进行引用。
那么我怎样才能创建一个方法来更改对字典中另一个已经存在的 id 的引用?
在 SQL 中,它只会更改 PACKING table 中的引用 ID。
packingRepository.findById(id)
.ifPresent(packing -> packing.setPackingDictionary(packingDictionaryRepository.getOne(dictionaryId))