- 浏览: 643261 次
- 性别:
- 来自: 杭州
文章分类
最新评论
-
HkEndless:
不好意思,请问这确定是回调机制吗。你的例子中只是将接口的实现类 ...
Spring CallBack回调机制介绍 -
hanmiao:
写的真乱啊,完全不知所云...
Java如何调用可执行文件和批处理命令 -
junia_1:
junia_1 写道 shock: ...
为什么要使用EJB -
junia_1:
shock:
为什么要使用EJB -
coollifer:
不错
SQL Server数据导入到Oracle中的方法
///////////////////////////////////////////////////////////////////////// import java.util.*; import java.sql.*; import org.hibernate.*; import org.hibernate.criterion.*; public class Main { public static void main(String[] args) { HibernateUtil.setup("create table Supplier ( id int, name VARCHAR);"); HibernateUtil.setup("create table Product ( id int, name VARCHAR, description VARCHAR, price double,supplierId int);"); prepareData(); Session session = HibernateUtil.currentSession(); Criteria crit = session.createCriteria(Product.class); crit.add(Restrictions.ilike("name","1", MatchMode.END)); List results = crit.list(); displayProductsList(results); HibernateUtil.checkData("select * from Supplier"); HibernateUtil.checkData("select * from Product"); } public static void displayProductsList(List list){ Iterator iter = list.iterator(); if (!iter.hasNext()){ System.out.println("No products to display."); return; } while (iter.hasNext()){ Product product = (Product) iter.next(); String msg = product.getSupplier().getName() + "\t"; msg += product.getName() + "\t"; msg += product.getPrice() + "\t"; msg += product.getDescription(); System.out.println(msg); } } private static void prepareData(){ Session session = HibernateUtil.currentSession(); Supplier supplier1 = new Supplier(); supplier1.setName("Supplier Name 1"); session.save(supplier1); Supplier supplier2 = new Supplier(); supplier2.setName("Supplier Name 2"); session.save(supplier2); Product product1 = new Product("Product 1","Name for Product 1", 2.0); product1.setSupplier(supplier1); supplier1.getProducts().add(product1); session.save(product1); Product product12 = new Product("Product 2","Name for Product 2", 22.0); product12.setSupplier(supplier1); supplier1.getProducts().add(product12); session.save(product12); Product product2 = new Product("Product 3", "Name for Product 3", 30.0); product2.setSupplier(supplier2); supplier2.getProducts().add(product2); session.save(product2); session.flush(); HibernateUtil.closeSession(); } } ///////////////////////////////////////////////////////////////////////// <?xml version='1.0' encoding='utf-8'?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <!-- Database connection settings --> <property name="connection.driver_class">org.hsqldb.jdbcDriver</property> <property name="connection.url">jdbc:hsqldb:data/tutorial</property> <property name="connection.username">sa</property> <property name="connection.password"></property> <!-- JDBC connection pool (use the built-in) --> <property name="connection.pool_size">1</property> <!-- SQL dialect --> <property name="dialect">org.hibernate.dialect.HSQLDialect</property> <!-- Echo all executed SQL to stdout --> <property name="show_sql">true</property> <!-- Mapping files --> <mapping resource="Product.hbm.xml"/> <mapping resource="Supplier.hbm.xml"/> </session-factory> </hibernate-configuration> ///////////////////////////////////////////////////////////////////////// public class Product { private int id; private Supplier supplier; private String name; private String description; private double price; public Product() { super(); } public Product(String name, String description, double price) { super(); this.name = name; this.description = description; this.price = price; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public Supplier getSupplier() { return supplier; } public void setSupplier(Supplier supplier) { this.supplier = supplier; } public double getPrice() { return price; } public void setPrice(double price) { this.price = price; } } ///////////////////////////////////////////////////////////////////////// <?xml version='1.0' encoding='utf-8'?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping> <class name="Supplier"> <id name="id" type="int"> <generator class="increment"/> </id> <property name="name" type="string"/> <bag name="products" inverse="true" cascade="all,delete-orphan"> <key column="supplierId"/> <one-to-many class="Product"/> </bag> </class> </hibernate-mapping> ///////////////////////////////////////////////////////////////////////// import java.util.ArrayList; import java.util.List; public class Supplier { private int id; private String name; private List products = new ArrayList(); public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public List getProducts() { return products; } public void setProducts(List products) { this.products = products; } }
发表评论
-
hibernate Restrictions用法 MatchMode.ANYWHERE
2012-07-14 15:50 3870方法 说明 Res ... -
hibernate3 大批量更新/删除数据 (update/delete)
2011-11-10 12:15 1343Hibernate3.0 采用新的基 ... -
hibernate lazy(延迟加载)
2011-10-12 02:20 886hibernate lazy策略可以使用在: * < ... -
一些关于Hibernate延迟加载的误区
2011-09-12 23:13 845首先是第一个误区:延迟加载只能作用于关联实体 看到这个是 ... -
org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling
2011-08-12 19:17 1211Hi I am facing a problem wit ... -
Criteria: Group By Criteria
2011-07-02 11:03 1254/////////////////////////////// ... -
Query Criteria Equal
2011-07-02 11:02 856/////////////////////////////// ... -
Criteria: Order
2011-07-02 10:59 736//////////////////////////// ... -
Criteria: Associations Sorting Criteria
2011-07-02 10:57 865//////////////////////////// ... -
hibernate的Query有没有setResultTransformer这个方法
2011-07-01 23:24 3044可以对原生SQL 查询使用ResultTransformer。 ... -
Hibernate中一级缓存、二级缓存及查询缓存的技术性总结
2011-06-21 17:31 1211一、 一级缓存 1. ... -
hibernate 保存 oracle 10g大数据字段
2011-06-14 04:01 1415Java代码 要点如下: ... -
Hibernate 错误原因总结
2011-06-14 00:10 13841、错误: object references an unsa ... -
MappingException提示Association references unmapped class错误的解决方法
2011-06-12 17:09 10出现如下错误信息时 Caused by: org.hibe ... -
Hibernate一对多关联映射的配置及其级联删除问题
2011-06-12 17:07 9首先举一个简单的一对多双向关联的配置: 一的一端:Quest ... -
Hibernate多对一关联映射原理、映射方法和数据的保存
2011-06-12 17:06 13Hibernate的多对一关联映射实现的基本原理就是: 在多 ... -
Hibernate一对多单向关联和双向关联映射方法及其优缺点
2011-06-12 17:05 11一对多关联映射和多对一关联映射实现的基本原理都是一样的,既是在 ... -
inverse = “true” example and explanation
2011-06-11 22:18 1088In Hibernate, only the “relatio ... -
ibatis和hibernate区别
2011-04-13 17:34 793ibatis:sql需要自己写 hibe ... -
Hibernate StackOverFlowError 异常出现的原因
2011-04-13 16:51 1242引起StackOverFlowError异常的一般是因为在程序 ...
相关推荐
补救性肝移植在肝癌切除术后患者中的临床价值及长期疗效分析,张彤,傅斌生,目的 探讨补救性肝移植在肝癌切除术后患者中的临床价值及长期疗效分析。方法 回顾性分析中山大学附属第三医院肝移植中心在2003年10�
UN - Manual of Tests and Criteria:2019(Rev7) - 最新英文电子版(536页).zip
UN - Manual of Tests and Criteria:2019(Rev7) - 最新英文电子版(536页).pdf
CRITERIA-1D / GEO CRITERIA-1D是一种农业水文学模型,用于模拟一维水通量,作物生长和作物需水量。可以在不同的详细级别定义土壤和作物参数。它需要每日农业气象数据作为输入:最低和最高气温,总降水量以及皮下...
Hibernate中的Criteria连表查询,包括单表属性查询,多表内连,以及左外连接查询
criteria的相关知识及其介绍,便于java编程中使用criteria进行相关操作。
Group Decision Making under Multiple Criteria Methods and Applications 多准则、多方法、多应用下的群体决策
安装npm install json-criteria --save用法节点// npm install babel --save// Once at the entrypoint of your app.require('babel/register')var test = require('json-criteria').testconsole.log(test( {foo:1},...
Hibernate中Criteria的完整用法
Hibernate中Criteria的完整用法
Mode matching of the pump beam with laser modes in laser diode (LD) end-pumped solid-state laser was experimentally studied. Considering both the mode-match degree and laser threshold, the effective ...
Hibernate的Criteria用法总结Hibernate的Criteria用法总结
由于已停产,因此ReactiveMongo-Criteria已迁移回其原始位置(此存储库)。 仅从该项目中提取的最初是从现已停用的扩展项目中提取的。 ReactiveMongo-Criteria应该与从0.12开始的版本保持API兼容,因为该库仅依赖于...
DetachedCriteria Criteria 使用方法 非常详细外加练习
整体总结Hibernate中的Criteria的用法!
Hibernate-Criteria_模糊查询
Symbian Signed Test Criteria Security Classification:Public Status:ISSUED Version:3.0.3 Last Revised Date:27th November 2008 Valid From:14th December 2008
hibernate criteria的使用方法
关于Hibernate操作持久化类的Criteria方式的书本方法