免费看欧美黑人毛片-免费看毛片网站-免费看毛片的网站-免费看久久-中文字幕日韩欧美-中文字幕日韩精品一区

您現在的位置:首頁 > IT認證 > JAVA >

Java基礎知識:Hibernate本地SQL查詢


本地SQL查詢來完善HQL不能涵蓋所有的查詢特性

  下面通過例子來理解本地SQL。

  例子:查詢用戶和租房的信息

  1.配置文件

  hibernate.cfg.xml

  <?xml version='1.0' encoding='utf-8'?>

  <!DOCTYPE hibernate-configuration PUBLIC

  "-//Hibernate/Hibernate Configuration DTD 3.0//EN"

  "/hibernate-configuration-3.0.dtd">

  <hibernate-configuration>

  <session-factory>

  <!-- Database connection settings -->

  <property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>

  <property name="connection.url">jdbc:oracle:thin:@OWEYOJ5DU7AAHZZ:1521:ORCL</property>

  <property name="ername">jbit</property>

  <property name="connection.password">bdqn</property>

  <!-- JDBC connection pool (use the built-in) -->

  <property name="connection.pool_size">1</property>

  <!-- SQL dialect -->

  <property name="dialect">org.hibernate.dialect.OracleDialect</property>

  <!-- Enable Hibernate's automatic session context management -->

  <property name="current_session_context_class">thread</property>

  <!-- Disable the second-level cache -->

  <!-- <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property> -->

  <!-- Echo all executed SQL to stdout --> <property name="show_sql">true</property>

  <!-- Drop and re-create the database schema on startup -->

  <property name="hbm2ddl.auto">update</property>

  <mapping resource="cn/jbit/hibernate/entity/User.hbm.xml" />

  <mapping resource="cn/jbit/hibernate/entity/House.hbm.xml" />

  <mapping resource="cn/jbit/hibernate/entity/Street.hbm.xml" />

  <mapping resource="cn/jbit/hibernate/entity/Type.hbm.xml" />

  <mapping resource="cn/jbit/hibernate/entity/District.hbm.xml" />

  </session-factory>

  </hibernate-configuration>

  2.hibernate工具類

  HibernateUtil.java

  package cn.jbit.hibernate.util;

  import org.hibernate.HibernateException;

  import org.hibernate.Session;

  import org.hibernate.SessionFactory;

  import org.nfiguration;

  /*

  * hibernate工具類

  */

  public class HibernateUtil {

  private static Configuration configuration;

  private static final SessionFactory sessionFactory;

  static{

  try { configuration=new Configuration();

  nfigure();

  sessionFactory=configuration.buildSessionFactory();

  }

  catch (Throwable ex) {

  // Make sure you log the exception, as it might be swallowed

  System.err.println("Initial SessionFactory creation failed." + ex);

  throw new ExceptionInInitializerError(ex);

  }

  }

  public static SessionFactory getSessionFactory() {

  return sessionFactory;

  }

  public Session getSession() throws HibernateException{

  return getSessionFactory().getCurrentSession();

  }

  }

  實體類

  User,java

  package cn.jbit.hibernate.entity;

  import java.util.Set;

  public class User implements java.io.Serializable {

  private static final long serialVersionUID = 1L;

  private Integer id;

  private String name;

  private String password;

  private String telephone;

  private String username;

  private String isadmin;

  private Set<House> house; //get&set方法

  public Integer getId() {

  return id;

  }

  public void setId(Integer id) {

  this.id = id;

  }

  public String getName() {

  return name;

  }

  public void setName(String name) {

  this.name = name;

  }

  public String getPassword() {

  return password;

  }

  public void setPassword(String password) {

  this.password = password;

  }

  public String getTelephone() {

  return telephone;

  }

  public void setTelephone(String telephone) {

  this.telephone = telephone;

  }

  public String getUsername() {

  return username;

  }

  public void setUsername(String username) {

  ername = username;

  }

  public String getIsadmin() {

  return isadmin;

  }

  public void setIsadmin(String isadmin) {

  this.isadmin = isadmin;

  }

  public Set<House> getHouse() {

  return house;

  } public void setHouse(Set<House> house) {

  this.house = house;

  }

  public static long getSerialversionuid() {

  return serialVersionUID;

  }

  }

  實體類

  House.java

  package cn.jbit.hibernate.entity;

  import java.util.Date;

  public class House {

  private Integer id;

  private Integer type_id;

  private Integer user_id;

  private Integer street_id;

  private String description;

  private Date date

相關文章

無相關信息
更新時間2022-09-16 10:07:22【至頂部↑】
聯系我們 | 郵件: | 客服熱線電話:4008816886(QQ同號) | 

付款方式留言簿投訴中心網站糾錯二維碼手機版

電話:
付款方式   |   給我留言   |   我要糾錯   |   聯系我們




主站蜘蛛池模板: 古天乐电影大全| 天堂av| 最可爱的人 电影| 燃冬海报| 第一财经直播电视直播| 日本电影致命诱惑| 向团组织靠拢的打算| 丁丁历险记电影| 黄视频免费看网站| 100克米饭多大一碗图片| 鸽子公母鉴别图解| 大决战全部演员表介绍图片| 假面骑士电王| 悄悄问圣僧女儿美不美| 七寸照片| 姬诚| cetv3中国教育电视台直播| 解决问题五上数学| 诱惑的艺术| 三上数学思维导图简单又漂亮| 美女xxx69爽爽免费观妞| 生死瞬间演员表| 一级特黄新婚之夜| 黄视频免费观看网站| 男士发型2024流行发型图片| 风花雪月1977版| 小头儿子大头爸爸| 笼中女电影| 林岚| 我要逃亡1988国语版免费观看| 4人免费剧本及答案| g71编程实例及解释| 贾林| 大国崛起思维导图| 特级做a爰片毛片免费看| 黄影| 培根《谈读书》原文及翻译| 成年黄色在线观看| 高清影视图库| 培根《谈读书》原文及翻译| 黄子华最新电影|