av国内精品久久久久影院,成人做爰A片免费播放金桔视频,欧美内射rape视频,亚洲国产精品一区二区久久,色综合久久中文字幕无码

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

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


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

  下面通(tong)過(guo)例子來理解本地SQL。

  例(li)子:查詢用戶和租(zu)房的信息

  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 -->

  &lt;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 -->

  <!-- &lt;property name=&quot;cache.provider_class">org.hibernate.cache.NoCacheProvider</property> -->

  &lt;!-- 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=&quot;cn/jbit/hibernate/entity/User.hbm.xml" />

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

  <mapping resource=&quot;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工(gong)具類

  */

  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(&quot;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同號) | 

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

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