Spring Integration Hibernate

Source: Internet
Author: User

1. What does Spring integration Hibernate integrate?

1). There is an IOC container to manage Hibernate's sessionfactory
2). Let Hibernate use a declarative transaction on Spring

2. Integration steps:

1). Join Hibernate
①. Jar Package
②. Adding hibernate configuration files: Hibernate.cfg.xml
③. Write A. hbm.xml file that corresponds to the persistence class.

2). Join Spring
①. Jar Package
②. Adding a Spring configuration file

3). Integration.

3. Writing code

One: Configure Hibernate

1, Hibernate.cfg.xml

    

1 <?XML version= "1.0" encoding= "UTF-8"?>2 <!DOCTYPE hibernate-configuration Public3 "-//hibernate/hibernate Configuration DTD 3.0//en"4 "Http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">5 <hibernate-configuration>6     <session-factory>7         <!--Configure basic properties for Hibernate -8         <!--1. The data source needs to be configured in the IOC container, so there is no need to configure the data source here -9         <!--2. The associated. Hbm.xml is also configured in the IOC container when the Sessionfactory instance is configured -Ten         <!--3. Configure the basic properties of Hibernate: Dialect, SQL display and formatting, strategies for generating data tables, and level two caching. - One          A         < Propertyname= "Hibernate.dialect">Org.hibernate.dialect.MySQL5InnoDBDialect</ Property> -         < Propertyname= "Hibernate.show_sql">True</ Property> -         < Propertyname= "Hibernate.format_sql">True</ Property> the          -         < Propertyname= "Hibernate.hbm2ddl.auto">True</ Property> -         <!--Configure Hibernate level two cache-related properties. - -     </session-factory> + </hibernate-configuration>

2. Persistent objects use the Hibernate tool to generate

1  Packagecom.jxsm.entities;2 3  Public classUName {4     Private intID;5     PrivateString name;6     PrivateString ISBN;7      Public intgetId () {8         returnID;9     }Ten      Public voidSetId (intID) { One          This. ID =ID; A     } -      PublicString GetName () { -         returnname; the     } -      Public voidsetName (String name) { -          This. Name =name; -     } +      PublicString getisbn () { -         returnISBN; +     } A      Public voidSETISBN (String ISBN) { at          This. ISBN =ISBN; -     } -       -}
1 <?XML version= "1.0"?>2 <!DOCTYPE hibernate-mapping Public "-//hibernate/hibernate mapping DTD 3.0//en"3 "Http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">4 <!--Generated 2015-7-30 17:29:41 by Hibernate Tools 3.4.0.CR1 -5 <hibernate-mapping>6     <classname= "Com.jxsm.entities.UName"Table= "UNAME">7         <IDname= "id"type= "int">8             <columnname= "ID" />9             <Generatorclass= "Identity" />Ten         </ID> One         < Propertyname= "Name"type= "Java.lang.String"> A             <columnname= "NAME" /> -         </ Property> -         < Propertyname= "ISBN"type= "Java.lang.String"> the             <columnname= "ISBN" /> -         </ Property> -     </class> - </hibernate-mapping>

Not finished!!

Spring Integration Hibernate

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.