日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
在Liferay中使用Hibernate

Liferay是一個開源的portal框架,它目前的基礎(chǔ)架構(gòu)是基于Struts,Spring和Hibernate的。我們在Liferay上開發(fā)應(yīng)用的時候,在需要使用數(shù)據(jù)庫的時候可以方便的使用Spring中提供的對Hibernate的支持。

目前成都創(chuàng)新互聯(lián)已為千余家的企業(yè)提供了網(wǎng)站建設(shè)、域名、網(wǎng)站空間網(wǎng)站托管運營、企業(yè)網(wǎng)站設(shè)計、丹寨網(wǎng)站維護等服務(wù),公司將堅持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長,共同發(fā)展。

具體步驟如下

1, 在你的ext開發(fā)環(huán)境的/ext/ext-web/docroot/WEB-INF/目錄下創(chuàng)建classes目錄,降hibernate.cfg.xml文件和你的hbm文件放在這里。
這是hibernate.cfg.xml文件的例子.

Java代碼

 
 
 
  1. < ?xml version="1.0" encoding="UTF-8"?>      
  2. < !DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">      
  3.      
  4. < hibernate-configuration>      
  5.    < session-factory>      
  6.      < property name="Hibernate.connection.driver_class">com.mysql.jdbc.Driver< /property>      
  7.      < property name="Hibernate.connection.password">luser< /property>      
  8.      < property name="Hibernate.connection.url">jdbc:mysql://localhost:3306/lportal< /property>      
  9.      < property name="Hibernate.connection.username">luser< /property>      
  10.      < property name="Hibernate.dialect">org.hibernate.dialect.MySQLDialect< /property>      
  11.      < property name="Hibernate.show_sql">true< /property>      
  12.      < mapping resource="example.hbm.xml"/>      
  13.    < /session-factory>      
  14. < /hibernate-configuration>     
  15.  
  16. < ?xml version="1.0" encoding="UTF-8"?> 
  17. < !DOCTYPE Hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> 
  18.  
  19. < hibernate-configuration>   
  20.   < session-factory>   
  21.     < property name="Hibernate.connection.driver_class">com.mysql.jdbc.Driver< /property> 
  22.     < property name="Hibernate.connection.password">luser< /property> 
  23.     < property name="Hibernate.connection.url">jdbc:mysql://localhost:3306/lportal< /property> 
  24.     < property name="Hibernate.connection.username">luser< /property> 
  25.     < property name="Hibernate.dialect">org.hibernate.dialect.MySQLDialect< /property> 
  26.     < property name="Hibernate.show_sql">true< /property> 
  27.     < mapping resource="example.hbm.xml"/> 
  28.   < /session-factory> 
  29. < /hibernate-configuration> 

example.hbm.xml是你定義的hbm文件,這里就不贅述了。

2,在你的DAOImpl類中使用Spring提供的HibernateTemplate,

Java代碼

 
 
 
  1. this.hibernateTemplate = new HibernateTemplate(sessionFactory);     
  2. this.hibernateTemplate = new HibernateTemplate(sessionFactory); 

sessionFactory是org.hibernate.SessionFactory,用于創(chuàng)建Session。

然后就可以進行數(shù)據(jù)庫操作了。

Java代碼

 
 
 
  1. //查詢      
  2. public YourPOJO getByPrimaryKey(final long yourId) {      
  3.         return (YourPOJO ) this.hibernateTemplate.execute(new HibernateCallback() {      
  4.             public Object doInHibernate(Session session) throws HibernateException, SQLException {      
  5.                  Criteria criteria = session.createCriteria(YourPOJO .class)      
  6.                          .add(Restrictions.eq("yourId", yourId));      
  7.                 return criteria.uniqueResult();      
  8.              }      
  9.          });      
  10.      }      
  11. //創(chuàng)建      
  12.     public void create(final YourPOJO pojo) {      
  13.         this.hibernateTemplate.save(pojo);      
  14.      }      
  15. //修改      
  16.     public void update(final YourPOJO pojo) {      
  17.         this.hibernateTemplate.saveOrUpdate(pojo);      
  18.      }      
  19. //刪除      
  20.     public void delete(final YourPOJO pojo) {      
  21.         this.hibernateTemplate.delete(pojo);      
  22.      }    

【編輯推薦】

  1. Hibernate基礎(chǔ)(2)
  2. Hibernate基礎(chǔ)(1)
  3. eclipse下生成HibernateDAO中的幾個方法
  4. hibernate中update與saveOrUpdate的區(qū)別
  5. Hibernate模糊查詢參數(shù)化的問題

名稱欄目:在Liferay中使用Hibernate
網(wǎng)頁路徑:http://m.5511xx.com/article/ccdpcpj.html