Springframework (9)

zhaozj2021-02-16  111

6, ORM

(1) ORM

l ORM: Object-translational mapping

l Built-in support:

Ø jdo

Ø Ø Ibatis

Ø hibernate

(2) Hibernate configuration

l Define DataSource and Hibernate SessionFactory

...

Employee.hbm.xml

.... db2diact

(3) HibernateTemplate

l Create hibernateTemplate

SessionFactory sessionFactory = (sessionFactory) CTX.getBean ("sessionFactory");

HibernateTemplate Hibernate = new hibernateTemplate (sessionFactory);

l Loading and updating

Employee E = (Employee) Hibernate.Load (Employee.class, "000330");

E.SetFirstName ("Bob");

Hibernate.Update (e);

l Use convenient method to query

List Employees = Hibernate.Find ("from app.employee");

List list = hibernate.find

"from app.employee e where e.lastname =?",

"Lee",

Hibernate.string;

List list = hibernate.find

"from app.employee e where e.lastname =? and E.FIRSTNAME =?",

New string [] {"bob", "lee"}

New type [] {hibernate.string, hibernate.string});

l Use the callback method to query

List list = (list) hibernate.execute (new hibernateCallback () {public object Doinhibernate (session session)

Throws HibernateException {

List result = session.find ("from app.employee");

// do some further stuff with the result list

Return Result;

}

});

(4) Abnormal processing

l Pass hibernate is abnormal to the DataAccessException layer

l uses the same strategy as JDBC

转载请注明原文地址:https://www.9cbs.com/read-8687.html

New Post(0)