日期:2014-05-19  浏览次数:20695 次

<property name="hbm2ddl.auto">update</property>的问题
原来的Student类里有 id,age,name 三个属性,后来增加一个属性 goal,为什么不能在数据库的表里增加一列呢?我在相应的映射文件里也加入了那个属性。
产生如下错误:
Exception in thread "main" org.hibernate.InvalidMappingException: Could not parse mapping document from resource com/hibernate/model/Student.hbm.xml
at org.hibernate.cfg.Configuration.addResource(Configuration.java:616)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1635)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1603)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1582)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1556)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1476)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1462)
at StudentTest.main(StudentTest.java:20)
Caused by: org.hibernate.PropertyNotFoundException: field [goal] not found on com.hibernate.model.Student
at org.hibernate.property.DirectPropertyAccessor.getField(DirectPropertyAccessor.java:145)
at org.hibernate.property.DirectPropertyAccessor.getField(DirectPropertyAccessor.java:137)
at org.hibernate.property.DirectPropertyAccessor.getGetter(DirectPropertyAccessor.java:160)
at org.hibernate.util.ReflectHelper.getter(ReflectHelper.java:241)
at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:229)
at org.hibernate.mapping.SimpleValue.setTypeUsingReflection(SimpleValue.java:302)
at org.hibernate.cfg.HbmBinder.createProperty(HbmBinder.java:2193)
at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder.java:2170)
at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder.java:2060)
at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:381)
at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:295)
at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:166)
at org.hibernate.cfg.Configuration.add(Configuration.java:716)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:551)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:613)
... 7 more
如果从原有属性中去掉一个属性后,表中的结构也没有改变。
请高手指点啊,谢谢了!

------解决方案--------------------
Caused by: org.hibernate.PropertyNotFoundException: field [goal] not found on com.hibernate.model.Student
你在映射文件配置的属性好像 在com.hibernate.model.Student类中没有定义
------解决方案--------------------
贴一下pojo类跟映射xml