浏览 2979 次
锁定老帖子 主题:JPA字段映射问题
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2008-03-05
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,我看报这个错,改过来的,请问各位高手是什么原因了 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2008-03-05
没什么特别
@Entity @Table(name = "file_items") public class ItemFile { @Id @Column(name = "ID") @GeneratedValue(strategy=GenerationType.AUTO) private int id; private String itemName; 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; } } |
|
返回顶楼 | |
发表时间:2008-03-05
annoation 都写在属性上面, 比写在get上面清楚
|
|
返回顶楼 | |