Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.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 冬眠——”;外键引用<;表1>;从<;表2>;列的编号错误。应为2“;错误_Hibernate_Foreign Keys_Netbeans 6.9_Manytomanyfield_Hibernate Onetomany - Fatal编程技术网

Hibernate 冬眠——”;外键引用<;表1>;从<;表2>;列的编号错误。应为2“;错误

Hibernate 冬眠——”;外键引用<;表1>;从<;表2>;列的编号错误。应为2“;错误,hibernate,foreign-keys,netbeans-6.9,manytomanyfield,hibernate-onetomany,Hibernate,Foreign Keys,Netbeans 6.9,Manytomanyfield,Hibernate Onetomany,我一直在寻找这个问题的解决办法。我发现一些帖子讨论了导致这个问题的多对多关系,但我认为这不适用于我的情况,所以我在一个新帖子中发布了这个帖子 我有以下数据库设计:============================================================================== 用户表: PK USER_ID, 用户名唯一, 项目表: 主键项目_ID, FK物料\卖家->与user.user\u ID的多对一关系, FK物料买家->与user.user\

我一直在寻找这个问题的解决办法。我发现一些帖子讨论了导致这个问题的多对多关系,但我认为这不适用于我的情况,所以我在一个新帖子中发布了这个帖子

我有以下数据库设计:==============================================================================

用户表: PK USER_ID, 用户名唯一,

项目表: 主键项目_ID, FK物料\卖家->与user.user\u ID的多对一关系, FK物料买家->与user.user\u ID的多对一关系,

投标表(用户和项目之间的桥梁): PK BID_ID, FK投标人\u ID->与user.user\u ID的多对一关系, FK ITEM_ID->与ITEM.ITEM_ID的多对一关系,

类别表: PK CAT_ID,

项目\类别表(类别和项目之间的桥梁): 主键项目类别ID, FK ITEM_ID->与ITEM.ITEM_ID的多对一关系, FK CAT_ID->与category.CAT_ID的多对一关系,

==============================================================================

我正试图通过NetBeans使用hibernate进行设置。我找到了一个教程,它指导我设置hibernate.cfg、reveng和util文件,并向我展示了如何使用NetBeans工具生成POJO。在本教程中,您应该右键单击cfg文件并运行HQL查询,以确保一切正常工作。我用一个简单的表(上面的用户表)测试了这个过程,一切都正常。但是,当我尝试将所有内容组合在一起时,我得到以下错误:


org.hibernate.AnnotationException:引用GavelDB.Bid中的GavelDB.User的外键的列数错误。应该是2
位于org.hibernate.cfg.annotations.TableBinder.bindFk(TableBinder.java:276)
在org.hibernate.cfg.ToOneFkSecondPass.doSecondPass(ToOneFkSecondPass.java:89)上
在org.hibernate.cfg.AnnotationConfiguration.processFkSecondPassInOrder(AnnotationConfiguration.java:499)上
位于org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:304)
位于org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1286)
位于org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:859)

正如我之前所说的,我以前搜索这个问题的所有尝试都指向了复合键,但是我在这个设计中努力避免了它们,所以我不知道这会是什么问题。我不熟悉hibernate,所以我还没有从头开始编写文件的知识库。如果有人能给我一些见解,我将不胜感激。提前谢谢

以下是错误中提到的两个文件,供您参考:

BID.JAVA

package GavelDB;
// Generated Feb 10, 2011 12:41:04 PM by Hibernate Tools 3.2.1.GA

import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * Bid generated by hbm2java
 */
@Entity
@Table(name="bid"
    ,catalog="gavel1"
)
public class Bid  implements java.io.Serializable {


     private Integer bidId;
     private User user;
     private Item item;
     private Date bidDate;
     private double bidAmt;
     private Double bidMax;

    public Bid() {
    }


    public Bid(User user, Item item, Date bidDate, double bidAmt) {
        this.user = user;
        this.item = item;
        this.bidDate = bidDate;
        this.bidAmt = bidAmt;
    }
    public Bid(User user, Item item, Date bidDate, double bidAmt, Double bidMax) {
       this.user = user;
       this.item = item;
       this.bidDate = bidDate;
       this.bidAmt = bidAmt;
       this.bidMax = bidMax;
    }

     @Id @GeneratedValue(strategy=IDENTITY)

    @Column(name="BID_ID", unique=true, nullable=false)
    public Integer getBidId() {
        return this.bidId;
    }

    public void setBidId(Integer bidId) {
        this.bidId = bidId;
    }
@ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="BIDDER_ID", nullable=false)
    public User getUser() {
        return this.user;
    }

    public void setUser(User user) {
        this.user = user;
    }
@ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="ITEM_ID", nullable=false)
    public Item getItem() {
        return this.item;
    }

    public void setItem(Item item) {
        this.item = item;
    }
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name="BID_DATE", nullable=false, length=19)
    public Date getBidDate() {
        return this.bidDate;
    }

    public void setBidDate(Date bidDate) {
        this.bidDate = bidDate;
    }

    @Column(name="BID_AMT", nullable=false, precision=22, scale=0)
    public double getBidAmt() {
        return this.bidAmt;
    }

    public void setBidAmt(double bidAmt) {
        this.bidAmt = bidAmt;
    }

    @Column(name="BID_MAX", precision=22, scale=0)
    public Double getBidMax() {
        return this.bidMax;
    }

    public void setBidMax(Double bidMax) {
        this.bidMax = bidMax;
    }

}
ITEM.JAVA

package GavelDB;
// Generated Feb 10, 2011 12:41:04 PM by Hibernate Tools 3.2.1.GA


import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

/**
 * User generated by hbm2java
 */
@Entity
@Table(name="user"
    ,catalog="gavel1"
    , uniqueConstraints = @UniqueConstraint(columnNames="USER_NAME") 
)
public class User  implements java.io.Serializable {


     private Integer userId;
     private String userName;
     private String pswd;
     private String email;
     private String street;
     private String city;
     private String state;
     private Integer zip;
     private Integer phone;
     private Set<Item> itemsForItemSeller = new HashSet<Item>(0);
     private Set<Item> itemsForItemBuyer = new HashSet<Item>(0);
     private Set<Bid> bids = new HashSet<Bid>(0);

    public User() {
    }


    public User(String userName) {
        this.userName = userName;
    }
    public User(String userName, String pswd, String email, String street, String city, String state, Integer zip, Integer phone, Set<Item> itemsForItemSeller, Set<Item> itemsForItemBuyer, Set<Bid> bids) {
       this.userName = userName;
       this.pswd = pswd;
       this.email = email;
       this.street = street;
       this.city = city;
       this.state = state;
       this.zip = zip;
       this.phone = phone;
       this.itemsForItemSeller = itemsForItemSeller;
       this.itemsForItemBuyer = itemsForItemBuyer;
       this.bids = bids;
    }

     @Id @GeneratedValue(strategy=IDENTITY)

    @Column(name="USER_ID", unique=true, nullable=false)
    public Integer getUserId() {
        return this.userId;
    }

    public void setUserId(Integer userId) {
        this.userId = userId;
    }

    @Column(name="USER_NAME", unique=true, nullable=false)
    public String getUserName() {
        return this.userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    @Column(name="PSWD", length=30)
    public String getPswd() {
        return this.pswd;
    }

    public void setPswd(String pswd) {
        this.pswd = pswd;
    }

    @Column(name="EMAIL")
    public String getEmail() {
        return this.email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    @Column(name="STREET")
    public String getStreet() {
        return this.street;
    }

    public void setStreet(String street) {
        this.street = street;
    }

    @Column(name="CITY")
    public String getCity() {
        return this.city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    @Column(name="STATE")
    public String getState() {
        return this.state;
    }

    public void setState(String state) {
        this.state = state;
    }

    @Column(name="ZIP")
    public Integer getZip() {
        return this.zip;
    }

    public void setZip(Integer zip) {
        this.zip = zip;
    }

    @Column(name="PHONE")
    public Integer getPhone() {
        return this.phone;
    }

    public void setPhone(Integer phone) {
        this.phone = phone;
    }
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="userByItemSeller")
    public Set<Item> getItemsForItemSeller() {
        return this.itemsForItemSeller;
    }

    public void setItemsForItemSeller(Set<Item> itemsForItemSeller) {
        this.itemsForItemSeller = itemsForItemSeller;
    }
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="userByItemBuyer")
    public Set<Item> getItemsForItemBuyer() {
        return this.itemsForItemBuyer;
    }

    public void setItemsForItemBuyer(Set<Item> itemsForItemBuyer) {
        this.itemsForItemBuyer = itemsForItemBuyer;
    }
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="user")
    public Set<Bid> getBids() {
        return this.bids;
    }

    public void setBids(Set<Bid> bids) {
        this.bids = bids;
    }

}
package GavelDB;
//Hibernate Tools 3.2.1.GA于2011年2月10日12:41:04下午生成
导入java.util.HashSet;
导入java.util.Set;
导入javax.persistence.CascadeType;
导入javax.persistence.Column;
导入javax.persistence.Entity;
导入javax.persistence.FetchType;
导入javax.persistence.GeneratedValue;
导入静态javax.persistence.GenerationType.IDENTITY;
导入javax.persistence.Id;
导入javax.persistence.OneToMany;
导入javax.persistence.Table;
导入javax.persistence.UniqueConstraint;
/**
*由hbm2java生成的用户
*/
@实体
@表(name=“user”
,catalog=“gavel1”
,uniqueConstraints=@UniqueConstraint(columnNames=“USER\u NAME”)
)
公共类用户实现java.io.Serializable{
私有整数用户标识;
私有字符串用户名;
私有字符串pswd;
私人字符串电子邮件;
私家弦街;;
私人城市;
私有字符串状态;
私有整数压缩;
专用整数电话;
私有集itemsForItemSeller=新哈希集(0);
私有集itemsForItemBuyer=新哈希集(0);
私有集出价=新哈希集(0);
公共用户(){
}
公共用户(字符串用户名){
this.userName=用户名;
}
公共用户(字符串用户名、字符串pswd、字符串电子邮件、字符串街道、字符串城市、字符串状态、整数zip、整数电话、Set itemsForItemSeller、Set itemsForItemBuyer、Set bids){
this.userName=用户名;
this.pswd=pswd;
this.email=电子邮件;
这条街;
this.city=城市;
this.state=状态;
this.zip=zip;
this.phone=电话;
this.itemsForItemSeller=itemsForItemSeller;
this.itemsForItemBuyer=itemsForItemBuyer;
此参数为:投标=投标;
}
@Id@GeneratedValue(策略=标识)
@列(name=“USER\u ID”,unique=true,nullable=false)
公共整数getUserId(){
返回this.userId;
}
public void setUserId(整数userId){
this.userId=userId;
}
@列(name=“USER\u name”,unique=true,nullable=false)
公共字符串getUserName(){
返回此用户名;
}
public void setUserName(字符串用户名){
this.userName=用户名;
}
@列(name=“PSWD”,长度=30)
公共字符串getPswd(){
返回此.pswd;
}
公共void setPswd(字符串pswd){
this.pswd=pswd;
}
@列(name=“EMAIL”)
公共字符串getEmail(){
返回此电子邮件;
}
公用电子邮件(字符串电子邮件){
this.email=电子邮件;
}
@列(name=“STREET”)
公共字符串getStreet(){
返回这条街;
}
公共街道(字符串街){
这条街;
}
@列(name=“CITY”)
公共字符串getCity(){
返回这个城市;
}
公共城市(字符串城市){
this.city=城市;
}
@列(name=“STATE”)
公共字符串getState(){
返回此.state;
}