Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Hibernate没有在mysql中设置外键,甚至在java中设置了关系_Java_Mysql_Spring_Hibernate - Fatal编程技术网

Hibernate没有在mysql中设置外键,甚至在java中设置了关系

Hibernate没有在mysql中设置外键,甚至在java中设置了关系,java,mysql,spring,hibernate,Java,Mysql,Spring,Hibernate,我在我的spring boot应用程序中有以下配置和代码,但我在mysql中没有外键约束。请提供一些帮助 股票类别:- @Entity(name = "stock") public class Stock { @Id @Column(name = "p_id") private String productId; @Column(name="p_desc") private String productDescription; @Column(

我在我的spring boot应用程序中有以下配置和代码,但我在mysql中没有外键约束。请提供一些帮助

股票类别:-

@Entity(name = "stock")
public class Stock {
    @Id
    @Column(name = "p_id")
    private String productId;

    @Column(name="p_desc")
    private String productDescription;

    @Column(name="p_quantity")
    private double productQuantityInStock;

    @Column(name = "p_threshold")
    private double productThresholdQuantity;

    @OneToOne( cascade = CascadeType.ALL)
    @JoinColumn(foreignKey = @ForeignKey(name = "fk_productPrice"),referencedColumnName = "pr_id")
    private ProductPrice productPrice;

    @ManyToMany(mappedBy = "listOfProducts")
    private Set<OrderList> orderLists;

    public String getProductId() {
        return productId;
    }

    public void setProductId(String productId) {
        this.productId = productId;
    }

    public String getProductDescription() {
        return productDescription;
    }

    public void setProductDescription(String productDescription) {
        this.productDescription = productDescription;
    }

    public double getProductQuantityInStock() {
        return productQuantityInStock;
    }

    public void setProductQuantityInStock(double productQuantityInStock) {
        this.productQuantityInStock = productQuantityInStock;
    }

    public double getProductThresholdQuantity() {
        return productThresholdQuantity;
    }

    public void setProductThresholdQuantity(double productThresholdQuantity) {
        this.productThresholdQuantity = productThresholdQuantity;
    }

    public ProductPrice getProductPrice() {
        return productPrice;
    }

    public void setProductPrice(ProductPrice productPrice) {
        this.productPrice = productPrice;
    }
}
Project.properties

约束的应用程序日志

Mysql-DDL


如果可以看到mysql ddl,那么就没有外键约束。我在JoinColumn中尝试了所有可能的组合,但看不到外键。我开始知道,在mysql中,
KEY
表示索引。我没想到。任何帮助、材料或指导都会有所帮助。谢谢

我运行了完全相同的实体,它用外键创建了stock表。对我来说唯一的区别是删除了referencedColumnName。Hibernate版本可能有差异。为了更好地理解@NickDiv,请告诉我您使用的版本。我使用的是5.3.1Final@venkatReddi我使用的是4.3.11.Final,但在更改版本之前,能否尝试从中删除referencedColumnNameannotation@NickDiv当然可以。非常感谢。
@Entity(name = "productprice")
public class ProductPrice {
    @Id
    @Column(name = "pr_id")
    private String PriceId;

    @Column(name="p_id")
    private String ProductId;

    @Column(name="price")
    private double Price;

    public String getPriceId() {
        return PriceId;
    }

    public void setPriceId(String priceId) {
        PriceId = priceId;
    }

    public String getProductId() {
        return ProductId;
    }

    public void setProductId(String productId) {
        ProductId = productId;
    }

    public double getPrice() {
        return Price;
    }

    public void setPrice(double price) {
        Price = price;
    }
}