关于jpa:org.hibernate.MappingException:无法确定:java.util.Set的类型,在表:USERS,对于列:[org.hibernate.mapping.Column(invoices)]

org.hibernate.MappingException: Could not determine type for: java.util.Set, at table: USERS, for columns: [org.hibernate.mapping.Column(invoices)]

我有一个问题,就是Hibernate无法确定表用户设置的类型。我试图通过一对多关系创建表发票的外键。一个用户可以生成多个发票。下面给出了我的user.java。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
@Entity
@Table(name="USERS")
public class User {

    @Id
    @Column(name="User_Id",nullable=false)
    @GeneratedValue(strategy=GenerationType.AUTO)
    private Integer user_id;


    @Column(name="NAME")
    private String name;

    @Column(name="Address")
    private String address;

    @Column(name="Designation")
    private String designation;


    private Set<Invoice> invoices;

    /*@OneToMany
    @JoinColumn(name="Rec_Invoice_ID", nullable=false)
    private Set<RecurringInvoice> recurring_invoices;*/

我正在尝试使用invoice-id作为用户表中的外键。我遵守这里的指示休眠:注释一对多(外键)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
    @OneToMany
    @JoinColumn(name="INVOICE_ID", nullable=false)
    public Set<Invoice> getInvoices() {
        return invoices;
    }

    public void setInvoices(Set<Invoice> invoices) {
        this.invoices = invoices;
    }

/*   public Set<RecurringInvoice> getRecurring_invoices() {
        return recurring_invoices;
    }

    public void setRecurring_invoices(Set<RecurringInvoice> recurring_invoices) {
        this.recurring_invoices = recurring_invoices;
    }
*/
    // Getters and Setters
    public Integer getUser_id() {
        return user_id;
    }

    public void setUser_id(Integer user_id) {
        this.user_id = user_id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getDesignation() {
        return designation;
    }

    public void setDesignation(String designation) {
        this.designation = designation;
    }

}

下面给出了我的invoice.java。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
@Entity
@Table(name="INVOICES")
public class Invoice {


    private Integer invoice_id;

    @Column(name="Date_Created", nullable=false)
    private Timestamp dateCreated;

    @Column(name="DESCRIPTION")
    private String description;

    @Column(name="Total_Amount")
    private Double totalAmount;

    @Column(name="Tax_Amount")
    private Double taxAmount;

    @Column(name="Due_Date")
    private Timestamp dueDate;

    @Column(name="deleted")
    private boolean deleted;


    private InvoiceItemsDetails invoiceItemsDetails;


    private Client client;

    @OneToOne
    @JoinColumn(name="ID", nullable=false)
    public Client getClient() {
        return client;
    }

    public void setClient(Client client) {
        this.client = client;
    }

    public Date getDueDate() {
        return dueDate;
    }

    public void setDueDate(Timestamp dueDate) {
        this.dueDate = dueDate;
    }

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    @Column(name="INVOICE_ID", nullable=false, insertable=false,updatable=false)
    public Integer getInvoice_id() {
        return invoice_id;
    }

    public void setInvoice_id(Integer invoice_id) {
        this.invoice_id = invoice_id;
    }

    public Date getDateCreated() {
        return dateCreated;
    }

    public void setDateCreated(Timestamp dateCreated) {
        this.dateCreated = dateCreated;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Double getTotalAmount() {
        return totalAmount;
    }

    public void setTotalAmount(Double totalAmount) {
        this.totalAmount = totalAmount;
    }

    public Double getTaxAmount() {
        return taxAmount;
    }

    public void setTaxAmount(Double taxAmount) {
        this.taxAmount = taxAmount;
    }

    public boolean isDeleted() {
        return deleted;
    }

    public void setDeleted(boolean deleted) {
        this.deleted = deleted;
    }

    @OneToOne
    @JoinColumn(name="Invoice_Item_Detail_id", nullable=false)
    public InvoiceItemsDetails getInvoiceItemsDetails() {
        return invoiceItemsDetails;
    }

    public void setInvoiceItemsDetails(InvoiceItemsDetails invoiceItemsDetails) {
        this.invoiceItemsDetails = invoiceItemsDetails;
    }


}

如果我没记错的话,Hibernate不允许您将注释与field/getter混合和匹配。如果您的@Id注释是在字段上设置的,那么所有映射都应该遵循字段。试着把@OneToMany
@JoinColumn(name="INVOICE_ID", nullable=false)
getInvoices()移到private Set invoices;上,这个模式也应该应用到你的Invoice类。