之前用Hibernate操作数据库,都是写下.hbm.xml配置文件的.这段时间发现注解要比.hbm.xml方便很多时,决定用注解.
之前用.hbm.xml时,在applicationContext.xml里配置是:
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
com/linuxgroup/model/Message.hbm.xml
com/linuxgroup/model/Class.hbm.xml
hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.hbm2ddl.auto=update
在java中用注解,用的配置文件是:
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
com.huihui.model
hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.hbm2ddl.auto=update
注意,
com.huihui.model
里的是指加载com.huihui.model下的带注解的java文件,如果时com.huihui.model.*是指model下的子文件夹下的带注解的java文件.
开始时,我理解成在model.*是指model下的所有带注解的java文件,搞了很长时间,郁闷一直不能成功建表,文件的包啊,运行环境啊,重新配置了一遍,最终竟是这个问题,