0
我實現了「InheritanceType.JOINED」類型的數據庫繼承。 我已經擴展了CrudRepository接口來做CRUD操作。實現了一些單元測試後。我知道保存&更新完美,但刪除不工作。那麼,這是怎麼回事?Spring數據JPA InheritanceType.JOINED刪除不起作用
下面是代碼團結測試:
@RunWith(SpringRunner.class)
@SpringBootTest
public class LineCommandRepoTest {
@Autowired
CommandRepository commandRepository;
@Autowired
ProduitRepository produitRepository;
@Autowired
LineCommandRepository lineCommandRepository;
public void update() {
LineCommande lc = lineCommandRepository.findOne(4);
lc.setQty(BigDecimal.valueOf(2000));
lc.setRemise(BigDecimal.valueOf(2000));
lc.setPrice(BigDecimal.valueOf(2000));
// lineCommandRepository.save(lc);
lineCommandRepository.save(lc);
LineCommande lc2 = lineCommandRepository.findOne(4);
Assert.assertTrue(lc.getPrice().equals(BigDecimal.valueOf(2000)));
}
public void insert() {
Commande commande = commandRepository.findOne(1);
Product p = produitRepository.findOne(1);
LineCommande lc = new LineCommande();
lc.setQty(BigDecimal.ONE);
lc.setPrice(BigDecimal.ONE);
lc.setRemise(BigDecimal.ONE);
lc.setCommande(commande);
lc.setProduct(p);
lineCommandRepository.save(lc);
Assert.assertTrue(lineCommandRepository.exists(lc.getIdLine()));
}
@Test
public void delete() {
lineCommandRepository.delete(4);
Assert.assertFalse(lineCommandRepository.exists(4));
}
}
這裏是超代碼:
package com.example.model.purchase;
import com.example.model.Product;
import javax.persistence.*;
@Entity
@Table(name = "linecommande")
@PrimaryKeyJoinColumn(name = "idlinepiece")
public class LineCommande extends LinePiece {
private Commande commande;
private Product product;
@ManyToOne
@JoinColumn(name = "idcommercialepiece")
public Commande getCommande() {
return commande;
}
public void setCommande(Commande commande) {
this.commande = commande;
}
@ManyToOne
@JoinColumn(name = "idproduct")
public Product getProduct() {
return product;
}
public void setProduct(Product product) {
this.product = product;
}
/*
public static Callback<LineCommande, Observable[]> extractor() {
return (LineCommande p) -> new Observable[]{p.qtyProperty(), p.priceProperty(), p.subTotalProperty()};
}*/
}