before using hibernate to manipulate the database, it is written down. Hbm.xml configuration file. This period of time found that the annotations are more convenient than the. Hbm.xml, the decision to use annotations.
before using. Hbm.xml, the configuration in Applicationcontext.xml is:
<bean id= "sessionfactory" class= "Org.springframework.orm.hibernate4.LocalSessionFactoryBean" > <property name= "DataSource" ref= "DataSource"/> <property name= "mappingresources" > <list > <!--The following list all PO mapping files-- <value>com/linuxgroup/model/Message.hbm.xml</value> <value>com/linuxgroup/model/Class.hbm.xml</value> </list> </property> < Property name= "Hibernateproperties" > <!--set Hibernate properties- - <value> Hibernate.dialect=org.hibernate.dialect.mysqldialect hibernate.hbm2ddl.auto=update </value> </property> </bean>
in Java with annotations, the configuration file is:
<bean id= "sessionfactory" class= "Org.springframework.orm.hibernate4.LocalSessionFactoryBean" > <property name= "DataSource" ref= "DataSource"/> <!--package scanning way Load annotation class-- <property name= " Packagestoscan "> <list> <value>com.huihui.model</value> </list> </property> <property name= "Hibernateproperties" > <!--Setting Hibernate Properties-- <value > hibernate.dialect=org.hibernate.dialect.mysqldialect hibernate.hbm2ddl.auto=update </ value> </property> </bean>
Note that
<value>com.huihui.model</value>
Refers to the annotated Java file under load Com.huihui.model, if com.huihui.model.* is the annotated Java file under the sub-folder under model.
At the beginning, I understand that in model.* refers to the model under the All annotated Java files, for a long time, depressed has been unable to build a table, file package Ah, run environment Ah, reconfigure again, eventually actually this problem,
Configuration of Java files for persistent annotations in hibernate in Applicationcontext.xml