Hibernate中持久化註解的java檔案在applicationContext.xml中的配置

來源:互聯網
上載者:User

標籤:style   io   ar   os   sp   java   檔案   資料   on   

之前用Hibernate操作資料庫,都是寫下.hbm.xml設定檔的.這段時間發現註解要比.hbm.xml方便很多時,決定用註解.


之前用.hbm.xml時,在applicationContext.xml裡配置是:

<bean id="sessionFactory"      class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">        <property name="dataSource" ref="dataSource"/>        <property name="mappingResources">            <list>                <!-- 以下列出所有的 PO 對應檔 -->                <value>com/linuxgroup/model/Message.hbm.xml</value>                <value>com/linuxgroup/model/Class.hbm.xml</value>            </list>        </property>        <property name="hibernateProperties">            <!-- 設定 Hibernate 屬性 -->            <value>                hibernate.dialect=org.hibernate.dialect.MySQLDialect                hibernate.hbm2ddl.auto=update            </value>        </property>    </bean>

在java中用註解,用的設定檔是:

<bean id="sessionFactory"          class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">        <property name="dataSource" ref="dataSource"/>        <!-- 包掃描的方式載入註解類 -->        <property name="packagesToScan">            <list>                <value>com.huihui.model</value>            </list>        </property>        <property name="hibernateProperties">            <!-- 設定 Hibernate 屬性 -->            <value>                hibernate.dialect=org.hibernate.dialect.MySQLDialect                hibernate.hbm2ddl.auto=update            </value>        </property>    </bean>



注意,
<value>com.huihui.model</value>

裡的是指載入com.huihui.model下的帶註解的java檔案,如果時com.huihui.model.*是指model下的子檔案夾下的帶註解的java檔案.


開始時,我理解成在model.*是指model下的所有帶註解的java檔案,搞了很長時間,鬱悶一直不能成功建表,檔案的包啊,運行環境啊,重新設定了一遍,最終竟是這個問題,


Hibernate中持久化註解的java檔案在applicationContext.xml中的配置

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.