- 浏览: 41457 次
最新评论
-
soartju:
貌似不支持集群,多个应用如果取到了某个时间的同一个id,岂不是 ...
hibernate中自定义主键(集群) -
tkl211:
请问你查询后 PagingToolbar 的总数改变么?
ExtJS 实战-CRUD+分页+复杂查询+排序
文章列表
public class PropertiesFile {
private Properties prop ; public PropertiesFile() { prop = new Properties(); } public PropertiesFile(String filePath,String propertiesName) { prop = new Properties(); try{ FileInputStream inputFile = new FileInputStream(filePath+propertiesName); ...
现在做的项目有一个需求:在不多维护一张表的情况下,自动生成主键,同sequence一样,而且要有一定的规范.比如,现在我们的规范是 yymmddhhmmss+四位流水号.没有办法,只好对hibernate的主键生成做自定义.下面是我的代码,请多多指教.声明,我的hibernate的版本是:hibernate3.2自定义的时候,只对两个地方做了修改,一个是自己写了一个java类,实现了 hibernate的IdentifierGenerator和Configurable ,另外一个地方就是对*.hbm.xml文件做修改.一.先说对*.hbm.xml做的修改吧,东西比较少.原始的配置文件中,主键 ...
在HIBERNATE中,identity ,sequence ,native 是数据局提供的主键生成方式,往往也不是我们需要,而且在程序跨数据库方面也体现出不足.还有基于算法的生成方式生成出来的主键基本都是字符串的.
我们现在需要一种生成方式:使用Long作为主键类型,需要自动增,支持集群.那么我们需要自定义一个我们的主键生成器才能实现了.
主键生成器代码 类:
package com.ta.jiang; import java.io.Serializable; import java.sql.Connection; import java.sql.Pre ...
自定义主键生成策略,由@GenericGenerator实现。hibernate在JPA的基础上进行了扩展,可以用一下方式引入hibernate独有的主键生成策略,就是通过@GenericGenerator 加入的。比如说,JPA标准用法
Java代码
@Id
@GeneratedValue(GenerationType.AUTO)
@Id
@GeneratedValue(GenerationType.AUTO)
就可以用hibernate特有以下用法来实现
Java代码
@GeneratedValue(generator ...
将当前主键的值单独保存到一个数据库的表中,主键的值每次都是从指定的表中查询来获得,这种生成主键的方式也是很常用的。这种方法生成主键的策略可以适用于任何的数据库,不必担心不同数据库不兼容造成的问题。
使用以下SQL脚本创建一个表“tb_generator”,并插入两条数据,SQL脚本如下所示。
CREATE TABLE tb_generator (
id int(20) unsigned NOT NULL auto_increment,
gen_name varchar(255) NOT NULL,
gen_value int(20) NOT NULL,
PRIMAR ...
本文使用的是Oracle9i数据库,hibernate3.0,spring2.0,jdk6。
首先在数据库中定义函数。
1.以下是数据库中定义的函数:
create or replace function Get_Djbh return varchar2 is Result varchar2(10); nNum Number(10); begin Select SDJLCK_SEQ.Nextval Into nNum From dual; Result : ...
Session s=this.getSessionFactory().openSession(); Connection con=s.connection(); String procedure = "select * from fmt( ' "+companyid+ " ') "; stmt = con.prepareCall(procedure);
stmt.execute....
hibernate3.0以上提供了两种方式执行存储过程。
第一种 :用JDBC 方式
Session session =HibernateSessionFactory.getSession(); //获取hibernate会话
Connection conn = session.connection(); // 用session对象获取连接
ResultSet rs =null;
try { CallableStatement call = conn.prepareCall("{Call pro_getManager(?,?)}");
call.se ...
http://www.sunxin.org/forum/thread/22985.html
public enum CustomerType { BRONZE, SILVER, GOLD}
It's time to create some bean definitions. Since I have 3 datasources where everything is the same except for the port number, I created a parent bean so that the shared properties can be inherited. Then, I added the 3 bean definitions t ...