欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

JPA字段映射问题

程序员文章站 2022-03-02 15:29:06
...
在mysql里面建了一个表

mysql> show columns from file_items;
+-----------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| item_name | varchar(100) | YES | | NULL | |
+-----------+--------------+------+-----+---------+----------------+
2 rows in set (0.03 sec)

jpa的映射类为

@Entity
@Table(name = "file_items")
public class ItemFile {
private int id;
private String itemName;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@Column(name="item_name")
public String getItemName() {
return itemName;
}
public void setItemName(String itemname) {
this.itemName = itemname;
}


}

在tomcat项目启动的时候报错:

Caused by: org.hibernate.MappingException: Could not determine type for: com.nbrc.model.ItemFile, for columns: [org.hibernate.mapping.Column(filename)]
at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:266)
at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:253)
at org.hibernate.mapping.Property.isValid(Property.java:185)
at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:440)
at org.hibernate.mapping.RootClass.validate(RootClass.java:192)
at org.hibernate.cfg.Configuration.validate(Configuration.java:1102)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1287)
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:915)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:730)

其他的类都没有问题,可能又是一个新手问题,不管非常郁闷,不知道错在哪里,不过原来的item_name这列的名字是叫filename,我看报这个错,改过来的,请问各位高手是什么原因了