Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/314.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
Java 使用spring引导的Hibernate上的表列映射错误_Java_Mysql_Spring_Hibernate_Spring Boot - Fatal编程技术网

Java 使用spring引导的Hibernate上的表列映射错误

Java 使用spring引导的Hibernate上的表列映射错误,java,mysql,spring,hibernate,spring-boot,Java,Mysql,Spring,Hibernate,Spring Boot,我在MySql数据库上有两个表。Item,ItemGroup由Item.groupid->ItemGroup.id关联,我也在使用hibernate entitymanager和spring引导。下面是我的Item和ItemGroup实体类 Item.java package com.thiha.entities; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.per

我在MySql数据库上有两个表。Item,ItemGroup由
Item.groupid->ItemGroup.id
关联,我也在使用
hibernate entitymanager
和spring引导。下面是我的Item和ItemGroup实体类

Item.java

package com.thiha.entities;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;

@Entity
public class Item {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Integer id;
    private String createdDate;
    private String modifiedDate;
    private String itemCode;
    private String description;
    private int groupId;
    private double quantity;
    private double price;
    private int recordStatus;
    private ItemGroup itemGroup;

    @ManyToOne
    @JoinColumn(name = "groupid")
    public ItemGroup getItemGroup() {
        return itemGroup;
    }

    public Integer getId() {
        return id;
    }
    public void setId(Integer id) {
        this.id = id;
    }
    public String getCreatedDate() {
        return createdDate;
    }
    public void setCreatedDate(String createdDate) {
        this.createdDate = createdDate;
    }
    public String getModifiedDate() {
        return modifiedDate;
    }
    public void setModifiedDate(String modifiedDate) {
        this.modifiedDate = modifiedDate;
    }
    public String getItemCode() {
        return itemCode;
    }
    public void setItemCode(String itemCode) {
        this.itemCode = itemCode;
    }
    public String getDescription() {
        return description;
    }
    public void setDescription(String description) {
        this.description = description;
    }
    public int getGroupId() {
        return groupId;
    }
    public void setGroupId(int groupId) {
        this.groupId = groupId;
    }
    public double getQuantity() {
        return quantity;
    }
    public void setQuantity(double quantity) {
        this.quantity = quantity;
    }
    public double getPrice() {
        return price;
    }
    public void setPrice(double price) {
        this.price = price;
    }
    public int getRecordStatus() {
        return recordStatus;
    }
    public void setRecordStatus(int recordStatus) {
        this.recordStatus = recordStatus;
    }
}
ItemGroup.java

package com.thiha.entities;

import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;

@Entity
public class ItemGroup {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Integer id;
    private String createdDate;
    private String modifiedDate;
    private String groupCode;
    private String groupName;
    private int recordStatus;
    private List<Item> items;

    @OneToMany(mappedBy = "itemGroup", cascade = CascadeType.ALL)
    public List<Item> getItems(){
        return items;
    }

    public Integer getId() {
        return id;
    }
    public void setId(Integer id) {
        this.id = id;
    }
    public String getCreatedDate() {
        return createdDate;
    }
    public void setCreatedDate(String createdDate) {
        this.createdDate = createdDate;
    }
    public String getModifiedDate() {
        return modifiedDate;
    }
    public void setModifiedDate(String modifiedDate) {
        this.modifiedDate = modifiedDate;
    }
    public String getGroupCode() {
        return groupCode;
    }
    public void setGroupCode(String groupCode) {
        this.groupCode = groupCode;
    }
    public String getGroupName() {
        return groupName;
    }
    public void setGroupName(String groupName) {
        this.groupName = groupName;
    }
    public int getRecordStatus() {
        return recordStatus;
    }
    public void setRecordStatus(int recordStatus) {
        this.recordStatus = recordStatus;
    }
}
如果我删除了这两个类中的关系,则它工作正常,但无法进行
内部联接
查询。请帮我解决这个问题

无法确定列:[org.hibernate.mapping.Column(items)]的表:item_group中的java.util.List的类型

因为您的
mappedBy
不正确。

当您在getter
getCategory()
上放置注释时,hibernate知道它是
category

@ManyToOne
@JoinColumn(name = "groupid")
public ItemGroup getCategory() {
    return itemGroup;
}
因此,请在您的
类项目组中使用适当的名称

@OneToMany(mappedBy = "category", cascade = CascadeType.ALL)
public List<Item> getItems(){
    return items;
}
@OneToMany(mappedBy=“category”,cascade=CascadeType.ALL)
公共列表getItems(){
退货项目;
}
上面写着

无法确定列:[org.hibernate.mapping.Column(items)]的表:item_group中的java.util.List的类型

因为您的
mappedBy
不正确。

当您在getter
getCategory()
上放置注释时,hibernate知道它是
category

@ManyToOne
@JoinColumn(name = "groupid")
public ItemGroup getCategory() {
    return itemGroup;
}
因此,请在您的
类项目组中使用适当的名称

@OneToMany(mappedBy = "category", cascade = CascadeType.ALL)
public List<Item> getItems(){
    return items;
}
@OneToMany(mappedBy=“category”,cascade=CascadeType.ALL)
公共列表getItems(){
退货项目;
}

在Hibernate中不能混合注释约定。请尝试将您的
@Id
@GeneratedValue
注释移动到getter,或将
@OneToMany
@manytone
移动到字段。

您不能在Hibernate中混合注释约定。请尝试将您的
@Id
@GeneratedValue
注释移动到getter,或将
@OneToMany
@manytone
移动到字段。

别担心,只需做一件事:删除Id上面的@Id和@generatorValue注释,并使用Id的getter方法
问题会解决的

别担心,只有一件事要做:删除Id上面的@Id注释和@generatorValue注释,并使用Id的getter方法
问题会解决的

谢谢你的回答。我将getter更改为getItemGroup()。但它仍然会出错,它现在的工作方式是将JPA相关的注释放在每个字段的正上方,而不是getter属性。谢谢@Taras。同样的例外@蒂哈扎维特正在工作。我将注释放在字段上方,而不是getter。这很好,但它也应该与getter一起工作。我想知道问题是什么:)谢谢你的回答。我将getter更改为getItemGroup()。但它仍然会出错,它现在的工作方式是将JPA相关的注释放在每个字段的正上方,而不是getter属性。谢谢@Taras。同样的例外@蒂哈扎维特正在工作。我将注释放在字段上方,而不是getter。这很好,但它也应该与getter一起工作。我想知道问题是什么:)