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)]

查看:146
本文介绍了org.hibernate.MappingException:无法确定类型:java.util.Set,在表中:USERS,列:[org.hibernate.mapping.Column(invoices)]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,Hibernate无法确定表USERS的Set的类型。
我试图通过一对多的关系创建表INVOICES的外键。一个用户可以生成很多发票。
我的User.java如下所示。

  @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)
私人字符串名称;

@Column(name =Address)
私有字符串地址;

@Column(name =Designation)
私有字符串指定;


私人设置<发票>发票;

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

我试图在USERS表中使用INVOICE-ID作为外键。
我按照这里给出的指示
Hibernate:Annotation一对多(外键)

  @OneToMany 
@JoinColumn(name = INVOICE_ID,nullable = false)
public Set< Invoice> getInvoices(){
返回发票;
}

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

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

public void setRecurring_invoices(Set< RecurringInvoice> recurring_invoices){
this.recurring_invoices = recurring_invoices;
}
* /
// Getters和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(){
返回指定;
}

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

}

我的Invoice.java如下。

  @Entity 
@Table(name =INVOICES)
public class Invoice {


私人整数invoice_id;

@Column(name =Date_Created,nullable = false)
私人时间戳记dateCreated;

@Column(name =DESCRIPTION)
私有字符串描述;

@Column(name =Total_Amount)
private Double totalAmount;

@Column(name =Tax_Amount)
private Double taxAmount;

@Column(name =Due_Date)
私人时间戳dueDate;

@Column(name =deleted)
private boolean deleted;


private InvoiceItemsDetails invoiceItemsDetails;


私人客户端客户端;

@OneToOne
@JoinColumn(name =ID,nullable = false)
公共客户端getClient(){
返回客户端;
}

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,可更新= 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;
$
$ b @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 注释在字段上设置,则所有映射都应该在字段后面。尝试从 getInvoices()移动 @OneToMany
@JoinColumn(name =INVOICE_ID,nullable = false)
>到私人设置<发票>发票; 这个模式应该适用于您的发票类以及

I have a problem that Hibernate is unable to determine the type for Set at the table USERS. I am trying to create a foreign key of table INVOICES through one-to-many relationship. One User can generate many Invoices. My User.java is given below.

@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;*/

I am trying to use INVOICE-ID as foreign key in USERS table. I am following the instructions given here Hibernate: Annotation one-to-many (foreign-key)

    @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;
    }

}

My Invoice.java is given below.

@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;
    }


}

解决方案

If I remember correctly, Hibernate doesn't let you mix and match annotation in conjunction with field / getter. If your @Id annotation is set over a field, all your mappings should follow fields. Try moving @OneToMany @JoinColumn(name="INVOICE_ID", nullable=false) from getInvoices() to private Set<Invoice> invoices; This pattern should be applied to your Invoice class as well

这篇关于org.hibernate.MappingException:无法确定类型:java.util.Set,在表中:USERS,列:[org.hibernate.mapping.Column(invoices)]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆