错误代码如下log4j:WARN No appenders could be found for logger (org.hibernate.cfg.annotations.Version). 
log4j:WARN Please initialize the log4j system properly. 
%%%% Error Creating SessionFactory %%%% 
org.hibernate.AnnotationException: Illegal attempt to map a non collection as a @OneToMany, @ManyToMany or @CollectionOfElements: ynu.edu.cn.Pricetype.machinesById 
其他的错误代码就不发了.....@Entity 
@Table(catalog = "wangba", name = "pricetype") 
public class Pricetype { 
private int id;@Id 
@Column(name = "ID", nullable = false, length = 10) 
public int getId() { 
return id; 
}public void setId(int id) { 
this.id = id; 
}private double price;@Basic 
@Column(name = "price", length = 4, precision = 2) 
public double getPrice() { 
return price; 
}public void setPrice(double price) { 
this.price = price; 
}private ArrayList<Machine> machinesById;@OneToMany(mappedBy = "pricetypeByPricetype") 
public ArrayList<Machine> getMachinesById() { 
return machinesById; 
}public void setMachinesById(ArrayList<Machine> machinesById) { 
this.machinesById = machinesById; 
}}上面是用idea自动生成的,我把collection改成了arraylist类型..程序中的HibernateSessionFactory类,似乎是myeclipse自动生成的单件模式的类,我把它拷过来,并将其中的Configuration改成了AnnotationConfiguration,其他基本没变....不知道是什么原因...希望大家指点一下...第一次自己写hibernate程序......

解决方案 »

  1.   

    应该是ArrayList <Machine>不能被识别为Collection
    这里用了泛型,和Collection没有继承关系了
      

  2.   

    呵呵,此问题已经解决.....问下
    我这个产生的应该跟javabean没区别吧...
    为什么
                    <c:forEach var="pricetype" items="${priceTypes}">
                        <optgroup label="${pricetype.price}元的机器区">
    利用javabean时没有错误,可是现在我用hibernate产生的东西(类似javabean)就出现错误说
    _jspx_exception = {java.lang.NumberFormatException@4033}"java.lang.NumberFormatException: For input string: \"price\""
    希望指点下!!!
      

  3.   

    是类型转化的错误。你传来的是一个String  ,在转化为double的时候发生错误。
    检查你的数据。
      

  4.   

    NumberFormatException 
    "price" 是字符串,不能转化为 Number 哦!你参数赋值错了。
      

  5.   

    可我的price
    private   double   price; @Basic   
    @Column(name   =   "price",   length   =   4,   precision   =   2)   
    public   double   getPrice()   {   
    return   price;   
    } public   void   setPrice(double   price)   {   
    this.price   =   price;   
    } 那该怎么改呢???
      

  6.   

    问一下,hibernate产生的那个类似javabean的东西到底与真正的javabean有什么区别???
    呵呵,好像hibernate产生的不能直接赋值哦...
        ArrayList<Pricetype> priceTypes = (ArrayList<Pricetype>) application.getAttribute("priceTypes");
        pricetype = new Pricetype();
        pricetype = priceTypes.get(0);//出错红色的部分也是一个hibernate产生的javabean的类的集合...所以这样也就导致jstl也会出错....但是还是不清楚怎么改...
      

  7.   

    application.getAttribute("priceTypes"); ????之前怎么setAttribute的?
      

  8.   

    log4j:WARN No appenders could be found for logger (org.hibernate.cfg.annotations.Version).
    log4j:WARN Please initialize the log4j system properly
    这个问题要怎么解决啊  
      

  9.   

    应该是ArrayList <Machine>不能被识别为Collection 
    这里用了泛型,和Collection没有继承关系了 
      

  10.   


    这个我会   没有log4j文件 对于这个annotations版本