Configuration of Java files for persistent annotations in hibernate in Applicationcontext.xml

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.