??xml version="1.0" encoding="utf-8" standalone="yes"?>97国产suv精品一区二区62,a级大胆欧美人体大胆666,亚洲高清在线http://www.aygfsteel.com/wiflish/category/11471.htmlLoving Life! Loving Coding!zh-cnThu, 12 Apr 2007 22:11:29 GMTThu, 12 Apr 2007 22:11:29 GMT60Hibernate3的配|参数汇?http://www.aygfsteel.com/wiflish/archive/2007/04/12/110152.html想飞的鱼想飞的鱼Thu, 12 Apr 2007 05:28:00 GMThttp://www.aygfsteel.com/wiflish/archive/2007/04/12/110152.htmlhttp://www.aygfsteel.com/wiflish/comments/110152.htmlhttp://www.aygfsteel.com/wiflish/archive/2007/04/12/110152.html#Feedback0http://www.aygfsteel.com/wiflish/comments/commentRss/110152.htmlhttp://www.aygfsteel.com/wiflish/services/trackbacks/110152.htmlSQL方言 1、Hibernate JDBC属?/b>

属性名 用?
hibernate.connection.driver_class jdbc驱动c?/em>
hibernate.connection.url jdbc URL
hibernate.connection.username 数据库用?/em>
hibernate.connection.password 数据库用户密?/em>
hibernate.connection.pool_size q接池容量上限数?/em>
注:使用C3P0的properties样例代码Q?br />
hibernate.connection.driver_class = org.postgresql.Driver
hibernate.connection.url = jdbc:postgresql://localhost/mydatabase
hibernate.connection.username = myuser
hibernate.connection.password = secret
hibernate.c3p0.min_size=5
hibernate.c3p0.max_size=20
hibernate.c3p0.timeout=1800
hibernate.c3p0.max_statements=50
hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect

2、Hibernate的数据源属?/b>
属性名 用?
hibernate.connection.datasource数据源JNDI名字
hibernate.jndi.urlJNDI提供者的URL (可?
hibernate.jndi.classJNDI InitialContextFactoryc?/em> (可?
hibernate.connection.username数据库用?/em> (可?
hibernate.connection.password数据库用户密?/em> (可?
注:应用E序服务器JNDI数据源的hibernate.properties样例代码Q?br />
hibernate.connection.datasource = java:/comp/env/jdbc/test
hibernate.transaction.factory_class = \
    org.hibernate.transaction.JTATransactionFactory
hibernate.transaction.manager_lookup_class = \
    org.hibernate.transaction.JBossTransactionManagerLookup
hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect

3?b>Hibernate配置属性(可选)

属性名 用?
hibernate.dialect 一个Hibernate Dialectcd允许Hibernate针对特定的关pL据库生成优化的SQL.

取?/span>full.classname.of.Dialect

hibernate.show_sql 输出所有SQL语句到控制台.

取?/span>true | false

hibernate.format_sql 在log和console中打印出更漂亮的sql.

取?/span>true | false

hibernate.default_schema 在生成的SQL? 给定的schema/tablespace附加于非全限定名的表名上.

取?/span>SCHEMA_NAME

hibernate.default_catalog 在生成的SQL? 给定的catalog附加于没全限定名的表名上.

取?/span>CATALOG_NAME

hibernate.session_factory_nameSessionFactory创徏后,自动用这个名字绑定到JNDI?

取?/span>jndi/composite/name

hibernate.max_fetch_depth 为单向关?一对一, 多对一)的外q接抓取Qouter join fetchQ树讄最大深? gؓ0意味着关闭默认的外连接抓?

取?/span> ?tt class="literal">0?tt class="literal">3之间取?

hibernate.default_batch_fetch_size 为Hibernate兌的批量抓取设|默认数?

取?/span> 的取gؓ4, 8, ?tt class="literal">16

hibernate.default_entity_mode 为由q个SessionFactory打开的所有Session指定默认的实体表现模?

取?/span>dynamic-map, dom4j, pojo

hibernate.order_updates 强制Hibernate按照被更新数据的主键QؓSQL更新排序。这么做减在高ƈ发系l中事务的死锁?

取?/span>true | false

hibernate.generate_statistics 如果开? Hibernate收集有助于性能调节的统计数?

取?/span>true | false

hibernate.use_identifer_rollback 如果开? 在对象被删除时生成的标识属性将被重设ؓ默认?

取?/span>true | false

hibernate.use_sql_comments 如果开? Hibernate在SQL中生成有助于调试的注释信? 默认gؓfalse.

取?/span>true | false


4?b>Hibernate JDBC和连?connection)属?br />
属性名 用?
hibernate.jdbc.fetch_size 非零|指定JDBC抓取数量的大?(调用Statement.setFetchSize()).
hibernate.jdbc.batch_size 非零|允许Hibernate使用JDBC2的批量更?

取?/span> ?tt class="literal">5?tt class="literal">30之间的?

hibernate.jdbc.batch_versioned_data 如果你想让你的JDBC驱动?tt class="literal">executeBatch()q回正确的行计数 , 那么此属性设?tt class="literal">true(开启这个选项通常是安全的). 同时QHibernateؓ自动版本化的数据使用扚wDML. 默认gؓfalse.

eg.true | false

hibernate.jdbc.factory_class 选择一个自定义?tt class="literal">Batcher. 多数应用E序不需要这个配|属?

eg.classname.of.Batcher

hibernate.jdbc.use_scrollable_resultset 允许Hibernate使用JDBC2的可滚动l果? 只有在用用h供的JDBCq接Ӟq个选项才是必要? 否则Hibernate会用连接的元数?

取?/span>true | false

hibernate.jdbc.use_streams_for_binary 在JDBCdbinary (二进??tt class="literal">serializable (可序列化) 的类型时使用?stream)(pȝU属?.

取?/span>true | false

hibernate.jdbc.use_get_generated_keys 在数据插入数据库之后Q允怋用JDBC3 PreparedStatement.getGeneratedKeys() 来获取数据库生成的key(?。需要JDBC3+驱动和JRE1.4+, 如果你的数据库驱动在使用Hibernate的标 识生成器旉到问题,请将此D为false. 默认情况下将使用q接的元数据来判定驱动的能力.

取?/span>true|false

hibernate.connection.provider_class 自定?tt class="literal">ConnectionProvider的类? 此类用来向Hibernate提供JDBCq接.

取?/span>classname.of.ConnectionProvider

hibernate.connection.isolation 讄JDBC事务隔离U别. 查看java.sql.Connection来了解各个值的具体意义, 但请注意多数数据库都不支持所有的隔离U别.

取?/span>1, 2, 4, 8

hibernate.connection.autocommit 允许被缓存的JDBCq接开启自动提?autocommit) (不徏?.

取?/span>true | false

hibernate.connection.release_mode 指定Hibernate在何旉放JDBCq接. 默认情况?直到Session被显式关闭或被断开q接?才会释放JDBCq接. 对于应用E序服务器的JTA数据? 你应当?tt class="literal">after_statement, q样在每ơJDBC调用后,都会d的释放连? 对于非JTA的连? 使用after_transaction在每个事务结束时释放q接是合理的. autoؓJTA和CMT事务{略选择after_statement, 为JDBC事务{略选择after_transaction.

取?/span>on_close | after_transaction | after_statement | auto

hibernate.connection.<propertyName> JDBC属?tt class="literal">propertyName传递到DriverManager.getConnection()中去.
hibernate.jndi.<propertyName> 属?tt class="literal">propertyName传递到JNDI InitialContextFactory中去.

5、Hibernate~存属?br />
属性名 用?
hibernate.cache.provider_class 自定义的CacheProvider的类?

取?/span>classname.of.CacheProvider

hibernate.cache.use_minimal_puts 以频J的L作ؓ代h, 优化二~存来最化写操? 在Hibernate3中,q个讄对的集群~存非常有用, 寚w缓存的实现而言Q默认是开启的.

取?/span>true|false

hibernate.cache.use_query_cache 允许查询~存, 个别查询仍然需要被讄为可~存?

取?/span>true|false

hibernate.cache.use_second_level_cache 能用来完全禁止用二U缓? 寚w些在cȝ映射定义中指?tt class="literal"><cache>的类Q会默认开启二U缓?

取?/span>true|false

hibernate.cache.query_cache_factory 自定义的实现QueryCache接口的类? 默认为内建的StandardQueryCache.

取?/span>classname.of.QueryCache

hibernate.cache.region_prefix 二~存区域名的前缀.

取?/span>prefix

hibernate.cache.use_structured_entries 强制Hibernate以更人性化的格式将数据存入二~存.

取?/span>true|false


6?b>Hibernate事务属?br />
属性名 用?
hibernate.transaction.factory_class 一?tt class="literal">TransactionFactory的类? 用于Hibernate Transaction API (默认?tt class="literal">JDBCTransactionFactory).

取?/span>classname.of.TransactionFactory

jta.UserTransaction 一个JNDI名字Q被JTATransactionFactory用来从应用服务器获取JTA UserTransaction.

取?/span>jndi/composite/name

hibernate.transaction.manager_lookup_class 一?tt class="literal">TransactionManagerLookup的类? - 当用JVMU缓存,或在JTA环境中用hilo生成器的时候需要该c?

取?/span>classname.of.TransactionManagerLookup

hibernate.transaction.flush_before_completion 如果开? session在事务完成后被自动清洗(flush). (在Hibernate和CMT一起用时很有?)

取?/span>true | false

hibernate.transaction.auto_close_session 如果开? session在事务完成前被自动关闭. (在Hibernate和CMT一起用时很有?)

取?/span>true | false


7?b>其他属?br />
属性名 用?
hibernate.query.factory_class 选择HQL解析器的实现.

取?/span>org.hibernate.hql.ast.ASTQueryTranslatorFactory or org.hibernate.hql.classic.ClassicQueryTranslatorFactory

hibernate.query.substitutions Hibernate查询中的W号映射到SQL查询中的W号 (W号可能是函数名或常量名?.

取?/span>hqlLiteral=SQL_LITERAL, hqlFunction=SQLFUNC

hibernate.hbm2ddl.auto ?tt class="literal">SessionFactory创徏Ӟ自动数据库schema的DDL导出到数据库. 使用 create-drop?在显式关?tt class="literal">SessionFactoryӞdrop掉数据库schema.

取?/span>update | create | create-drop

hibernate.cglib.use_reflection_optimizer 开启CGLIB来替代运行时反射机制(pȝU属?. 反射机制有时在除错时比较有用. 注意即关闭q个优化, Hibernateq是需要CGLIB. 你不能在hibernate.cfg.xml中设|此属?

取?/span>true | false


8?b>SQL方言
   Hibernate SQL方言 (hibernate.dialect)
RDBMS 方言
DB2org.hibernate.dialect.DB2Dialect
DB2 AS/400org.hibernate.dialect.DB2400Dialect
DB2 OS390org.hibernate.dialect.DB2390Dialect
PostgreSQLorg.hibernate.dialect.PostgreSQLDialect
MySQLorg.hibernate.dialect.MySQLDialect
MySQL with InnoDBorg.hibernate.dialect.MySQLInnoDBDialect
MySQL with MyISAMorg.hibernate.dialect.MySQLMyISAMDialect
Oracle (any version)org.hibernate.dialect.OracleDialect
Oracle 9i/10gorg.hibernate.dialect.Oracle9Dialect
Sybaseorg.hibernate.dialect.SybaseDialect
Sybase Anywhereorg.hibernate.dialect.SybaseAnywhereDialect
Microsoft SQL Serverorg.hibernate.dialect.SQLServerDialect
SAP DBorg.hibernate.dialect.SAPDBDialect
Informixorg.hibernate.dialect.InformixDialect
HypersonicSQLorg.hibernate.dialect.HSQLDialect
Ingresorg.hibernate.dialect.IngresDialect
Progressorg.hibernate.dialect.ProgressDialect
Mckoi SQLorg.hibernate.dialect.MckoiDialect
Interbaseorg.hibernate.dialect.InterbaseDialect
Pointbaseorg.hibernate.dialect.PointbaseDialect
FrontBaseorg.hibernate.dialect.FrontbaseDialect
Firebirdorg.hibernate.dialect.FirebirdDialect

9?b>Hibernate日志cd
cd 功能
org.hibernate.SQL 在所有SQL DML语句被执行时为它们记录日?
org.hibernate.type 为所有JDBC参数记录日志
org.hibernate.tool.hbm2ddl 在所有SQL DDL语句执行时ؓ它们记录日志
org.hibernate.pretty 在session清洗(flush)Ӟ为所有与其关联的实体(最?0?的状态记录日?
org.hibernate.cache 为所有二U缓存的zd记录日志
org.hibernate.transaction Z务相关的zd记录日志
org.hibernate.jdbc 为所有JDBC资源的获取记录日?
org.hibernate.hql.ast 为HQL和SQL的自动状态{换和其他关于查询解析的信息记录日?
org.hibernate.secure 为JAAS认证h做日?
org.hibernate ZQ何Hibernate相关信息做日?(信息量较? 但对查错非常有帮?




想飞的鱼 2007-04-12 13:28 发表评论
]]>
Hibernate回调与拦截机制——Hibernate深入出http://www.aygfsteel.com/wiflish/archive/2006/08/16/63966.html想飞的鱼想飞的鱼Wed, 16 Aug 2006 09:41:00 GMThttp://www.aygfsteel.com/wiflish/archive/2006/08/16/63966.htmlhttp://www.aygfsteel.com/wiflish/comments/63966.htmlhttp://www.aygfsteel.com/wiflish/archive/2006/08/16/63966.html#Feedback0http://www.aygfsteel.com/wiflish/comments/commentRss/63966.htmlhttp://www.aygfsteel.com/wiflish/services/trackbacks/63966.html1、实体对象implements Lifecycle接口QLifecycle接口代码Q?br />
public interface Lifecycle {
    
/**
     * 在实体对象Save/Insert操作之前触发.
     
*/
    
public boolean onSave(Session s) throws CallbackException;
    
    
/**
     * 在Session.update()操作之前触发.
     
*/
    
public boolean onUpdate(Session s) throws CallbackException;

    
/**
     * 在实体对象删除之前触?
     
*/
    
public boolean onDelete(Session s) throws CallbackException;

    
/**
     * 在实体对象加载之后触?
     
*/
    
public void onLoad(Session s, Serializable id);
}
实体对象通过实现Lifecycle接口Q即可以在特定的持久化阶D,触发特定的处理过E。比如在实体对象Tuser实现了Lifecycle接口的onSaveҎQ则在实体对象Tuser保存之前先执行onSaveҎ?br />
2、实体对象implements Validatable接口QValidatable接口代码Q?br />
public interface Validatable {
    
public void validate() throws ValidationFailure;
}
   Validatable接口定义了数据验证实现方式。实体对象实现Validatable接口Qƈ在validateҎ中对当前待保?/b>的数据进行验证,以保证数据的逻辑合法?׃该方法在实体对象生命周期内,可能被多ơ调用,所以此Ҏ最好只用于数据本n的逻辑合法性验证,而不要试囑֎实现数据业务逻辑的验??br />
以上2U方法都要求实现Hibernate中的Lifecycle或Validatable接口Q具有很大的侵入性,使得实体对象的移植很不方ѝHibernate又提供了一U拦截机Ӟ为对象持久化事g的捕获和处理提供了一个非侵入性的实现?br />
3、实现Interceptor接口Q在创徏sessionӞ指定加蝲Interceptor相应的实现类Q此session 的持久化操作都将首先l由此拦截器捕获处理。Interceptor(Hibernate3)接口代码Q?br />
package org.hibernate;

import java.io.Serializable;
import java.util.Iterator;

import org.hibernate.type.Type;

public interface Interceptor {
 
   
//对象初始化之前加?q里的entity处于刚被创徏的状?卛_性均未赋?.
    
public boolean onLoad(Object entity, Serializable id, Object[] state, String[] propertyNames,
            Type[] types) 
throws CallbackException;
   

    //Session.flush()Ҏq行脏数据检查时,如果发现PO状态改?则调用此Ҏ(卛_体对象更C前调?.
    public boolean onFlushDirty(Object entity, Serializable id, Object[] currentState,
           Object[] previousState, String[] propertyNames, Type[] types) 
throws CallbackException;
   
    //在实体对象被保存之前调用.
    
public boolean onSave(Object entity, Serializable id, Object[] state, String[] propertyNames,
           Type[] types) 
throws CallbackException;
   

    //在对象被删除之前调用.
    public void onDelete(Object entity, Serializable id, Object[] state, String[] propertyNames,
           Type[] types) 
throws CallbackException;
    
/**
     * Called before a collection is (re)created.
     
*/
    
public void onCollectionRecreate(Object collection, Serializable key) throws CallbackException;
    
/**
     * Called before a collection is deleted.
     
*/
    
public void onCollectionRemove(Object collection, Serializable key) throws CallbackException;
    
/**
     * Called before a collection is updated.
     
*/
    
public void onCollectionUpdate(Object collection, Serializable key) throws CallbackException;
   

    //Session执行flushҎ之前调用.
    public void preFlush(Iterator entities) throws CallbackException;
  

    //Session执行flushҎ之后调用.
    public void postFlush(Iterator entities) throws CallbackException;

    
/**
     * Called to distinguish between transient and detached entities. The return value determines the
     * state of the entity with respect to the current session.
     * <ul>
     * <li><tt>Boolean.TRUE</tt> - the entity is transient
     * <li><tt>Boolean.FALSE</tt> - the entity is detached
     * <li><tt>null</tt> - Hibernate uses the <tt>unsaved-value</tt> mapping and other heuristics to 
     * determine if the object is unsaved
     * </ul>
     * 
@param entity a transient or detached entity
     * 
@return Boolean or <tt>null</tt> to choose default behaviour
     
*/
    
public Boolean isTransient(Object entity);
    
/**
     * Called from <tt>flush()</tt>. The return value determines whether the entity is updated
     * <ul>
     * <li>an array of property indices - the entity is dirty
     * <li>an empty array - the entity is not dirty
     * <li><tt>null</tt> - use Hibernate's default dirty-checking algorithm
     * </ul>
     * 
@param entity a persistent entity
     * 
@return array of dirty property indices or <tt>null</tt> to choose default behaviour
     
*/
    
public int[] findDirty(Object entity, Serializable id, Object[] currentState,
             Object[] previousState, String[] propertyNames, Type[] types);
    
/**
     * Instantiate the entity class. Return <tt>null</tt> to indicate that Hibernate should use
     * the default constructor of the class. The identifier property of the returned instance
     * should be initialized with the given identifier.
     *
     * 
@param entityName the name of the entity
     * 
@param entityMode The type of entity instance to be returned.
     * 
@param id the identifier of the new instance
     * 
@return an instance of the class, or <tt>null</tt> to choose default behaviour
     
*/
    
public Object instantiate(String entityName, EntityMode entityMode,
           Serializable id) 
throws CallbackException;

    
/**
     * Get the entity name for a persistent or transient instance
     * 
@param object an entity instance
     * 
@return the name of the entity
     
*/
    
public String getEntityName(Object object) throws CallbackException;

    
/**
     * Get a fully loaded entity instance that is cached externally
     * 
@param entityName the name of the entity
     * 
@param id the instance identifier
     * 
@return a fully initialized entity
     * 
@throws CallbackException
     
*/
    
public Object getEntity(String entityName, Serializable id) throws CallbackException;
    
    
/**
     * Called when a Hibernate transaction is begun via the Hibernate <tt>Transaction</tt> 
     * API. Will not be called if transactions are being controlled via some other 
     * mechanism (CMT, for example).
     
*/
    
public void afterTransactionBegin(Transaction tx);
    
/**
     * Called before a transaction is committed (but not before rollback).
     
*/
    
public void beforeTransactionCompletion(Transaction tx);
    
/**     * Called after a transaction is committed or rolled back.
     
*/
    
public void afterTransactionCompletion(Transaction tx);

    
/**
     * Called when sql string is being prepared. 
     * 
@param sql sql to be prepared
     * 
@return original or modified sql
     
*/
    
public String onPrepareStatement(String sql);
}






想飞的鱼 2006-08-16 17:41 发表评论
]]>
Hibernate3 实体属性的延迟加蝲——Hibernate深入出http://www.aygfsteel.com/wiflish/archive/2006/08/15/63692.html想飞的鱼想飞的鱼Tue, 15 Aug 2006 07:54:00 GMThttp://www.aygfsteel.com/wiflish/archive/2006/08/15/63692.htmlhttp://www.aygfsteel.com/wiflish/comments/63692.htmlhttp://www.aygfsteel.com/wiflish/archive/2006/08/15/63692.html#Feedback0http://www.aygfsteel.com/wiflish/comments/commentRss/63692.htmlhttp://www.aygfsteel.com/wiflish/services/trackbacks/63692.html属性gq加载的实现Q?br />1、在实体映射文g中,通过property节点的lazy属性,可以为特定的属性制定gq加载策略?br />
<hibernate-mapping>
  
<class 
     
name="test.Tuser"
     table
="T_USER"
     batch-size
="5">
     
<id name="id" columen="id">
        
<generator class="native"/>
     
</id>
     
<property 
         
name="name"
         column
="name"/>
     
<property 
         
name="age"
         column
="age"/>
     
<property
         
name="resume"
         column
="resume"
         lazy
="true"/>                //q里个人简历(大文本字D)讄为gq加载?/span>
   
</class>
</hibernate-mapping>

2、配|了lazy属性之外,q要借助cd强器对二q制Class文gq行强化处理Qbuildtime bytecode instrumentation)。通过ANT调用Hibernatecd强器对TUser.class文gq行强化处理。脚本如下:
<project name="HibernateSample" default="instrument" basedir=".">
  
<property name="lib.dir" value="./lib"/>
  
<property name="classes.dir" value="./bin"/>
  
  
<path id="lib.class.path">
     
<fileset dir="${lib.dir}">
         
<include name="**/*.jar"/>
     
</fileset>
   
  
<target name="instrument">
     
<taskdef name="instrument"
         classname
="org.hibernate.tool.instrument.InstrumentTask">

        
<classpath path="${classes.dir}"/>
        
<classpath refid="lib.class.path"/>
     </
taskdef>
        
    
<instrument verbose="true">
       
<fileset dir="${classes.dir}/com.redsaga/hibernate/db/entity">
          
<include name="TUser.class"/>
       
</fileset>
    
</instrument>
 
</target>
</project>
  
注:脚本中涉及的配置路径Q根据项目目录修攏V?br />

想飞的鱼 2006-08-15 15:54 发表评论
]]>
Hibernate数据加蝲方式——hibernate深入出http://www.aygfsteel.com/wiflish/archive/2006/08/03/61544.html想飞的鱼想飞的鱼Thu, 03 Aug 2006 09:25:00 GMThttp://www.aygfsteel.com/wiflish/archive/2006/08/03/61544.htmlhttp://www.aygfsteel.com/wiflish/comments/61544.htmlhttp://www.aygfsteel.com/wiflish/archive/2006/08/03/61544.html#Feedback0http://www.aygfsteel.com/wiflish/comments/commentRss/61544.htmlhttp://www.aygfsteel.com/wiflish/services/trackbacks/61544.html1、即时加载(Immediate LoadingQ?br />   当实体加载完成后Q立卛_载与实体相关联的数据。即当实体加载完成后QHibernate自动立即d与实体相兌的数据,q且填充到实体对应的属性中。这U加载通常有多条select语句Q即select实体数据后,同时select实体相关联的数据?br />
2、gq加载(Lazy LoadingQ?br />   实体加蝲Ӟ其关联数据ƈ不是立即dQ而是当关联数据第一ơ被讉K时再q行dQ这U加载方式在W一ơ访问关联数据时Q必d同一个session中,否则会报session已关闭错误?br />   延迟加蝲通过在实体的hbm文g中的对应属性中讑֮lazy="true"实现。Hibernate3默认的加载方式是延迟加蝲。即默认lazy="true"Q主要用于one-to-many场合?br />
3、预先加载(Eager LoadingQ?br />   预先加蝲Ӟ实体及关联对象同时读取,与即时加载类|但是预先加蝲是?outer-join"通过一条select语句同时d?br />   注意Q当实体间关联比较复杂时Q比如多层关联,Hibernate生成?outer join SQL"可能q于复杂Q此时可以通过讑֮全局变量Qhibernate.max_fetch_depthQ限定join的层ơ(一般设定ؓ5层)?br />
4、批量加载(Batch LoadingQ?br />   对于x和gq加载,可以采用扚w加蝲q行优化?br />   扚w加蝲是通过扚w提交多个限定条gQ一ơ多个限定条件的数据d。同时在实体映射文g中的class节点Q通过配置"batch-size"参数打开扚w加蝲机制Qƈ限定每次扚w加蝲数据的数?一般来说该?lt;10较合?
 
比如Q  ?div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;">select * from test where id=1;
select 
* from test where id=2;  我们可以整合成一条语句:
select * from test where id=1 ro id=2;
  q就是所谓的扚w加蝲机制?br />



想飞的鱼 2006-08-03 17:25 发表评论
]]>
[转]Hibernate: could not initialize proxy - the owning Session was closedhttp://www.aygfsteel.com/wiflish/archive/2006/07/27/60362.html想飞的鱼想飞的鱼Thu, 27 Jul 2006 07:21:00 GMThttp://www.aygfsteel.com/wiflish/archive/2006/07/27/60362.htmlhttp://www.aygfsteel.com/wiflish/comments/60362.htmlhttp://www.aygfsteel.com/wiflish/archive/2006/07/27/60362.html#Feedback0http://www.aygfsteel.com/wiflish/comments/commentRss/60362.htmlhttp://www.aygfsteel.com/wiflish/services/trackbacks/60362.htmlhttp://www.javathinker.org/main.jsp?bc=hibernate/hibernate_essay_16.htm
本错误的产生原因及解?
 
延迟初始化错误(ERROR LazyInitializerQ是如何产生?

选自<<_NHibernateQJava对象持久化技术详?gt;> 作者:孙卫?/a> 来源:www.javathinker.org
如果转蝲Q请标明出处Q谢?/font>

延迟初始化错误是q用Hibernate开发项目时最常见的错误。如果对一个类或者集合配|了延迟索策略,那么必须当代理类实例或代理集合处于持久化状态(卛_于Session范围内)Ӟ才能初始化它。如果在游离状态时才初始化它,׃产生延迟初始化错误?/p>

下面把Customer.hbm.xml文g?lt;class>元素的lazy属性设为trueQ表CZ用gq检索策略:

<class name="mypack.Customer" table="CUSTOMERS" lazy="true">

当执行Session的load()ҎӞHibernate不会立即执行查询CUSTOMERS表的select语句Q仅仅返回Customercȝ代理cȝ实例Q这个代理类L以下特征Q?/p>

Q?Q?由Hibernate在运行时动态生成,它扩展了Customerc,因此它承了Customercȝ所有属性和ҎQ但它的实现对于应用E序是透明的?br /> Q?Q?当Hibernate创徏Customer代理cd例时Q仅仅初始化了它的OID属性,其他属性都为nullQ因此这个代理类实例占用的内存很?br /> Q?Q? 当应用程序第一ơ访问Customer代理cd例时Q例如调用customer.getXXX()或customer.setXXX()ҎQ, Hibernate会初始化代理cd例,在初始化q程中执行select语句Q真正从数据库中加蝲Customer对象的所有数据。但有个例外Q那是? 应用E序讉KCustomer代理cd例的getId()ҎӞHibernate不会初始化代理类实例Q因为在创徏代理cd例时OID存在了Q不? 到数据库中去查询?br />
? C:Hibernate采用CGLIB工具来生成持久化cȝ代理cRCGLIB是一个功能强大的Java字节码生成工P它能够在E序q行时动态生成扩? JavacL者实现Java接口的代理类。关于CGLIB的更多知识,请参考:http://cglib.sourceforge.net/?/i>

以下代码先通过Session的load()Ҏ加蝲Customer对象Q然后访问它的name属性:

tx = session.beginTransaction();
Customer customer=(Customer)session.load(Customer.class,new Long(1));
customer.getName();
tx.commit();

? q行session.load()Ҏ时Hibernate不执行Q何select语句Q仅仅返回Customercȝ代理cȝ实例Q它的OID?Q这 是由load()Ҏ的第二个参数指定的。当应用E序调用customer.getName()ҎӞHibernate会初始化Customer代理 cd例,从数据库中加载Customer对象的数据,执行以下select语句Q?/p>

select * from CUSTOMERS where ID=1;
select * from ORDERS where CUSTOMER_ID=1;

?lt;class>元素的lazy属性ؓtrueQ会影响Session的load()Ҏ的各U运行时行ؓQ下面D例说明?/p>

1Q如果加载的Customer对象在数据库中不存在QSession的load()Ҏ不会抛出异常Q只有当q行customer.getName()Ҏ时才会抛Z下异常:

ERROR LazyInitializer:63 - Exception initializing proxy
net.sf.hibernate.ObjectNotFoundException: No row with the given identifier exists: 1, of class:
mypack.Customer

2Q如果在整个Session范围内,应用E序没有讉KqCustomer对象Q那么Customer代理cȝ实例一直不会被初始化,Hibernate不会执行Mselect语句。以下代码试囑֜关闭Session后访问Customer游离对象Q?/p>

tx = session.beginTransaction();
Customer customer=(Customer)session.load(Customer.class,new Long(1));
tx.commit();
session.close();
customer.getName();

׃引用变量customer引用的Customer代理cȝ实例在Session范围内始l没有被初始化,因此在执行customer.getName()ҎӞHibernate会抛Z下异常:

ERROR LazyInitializer:63 - Exception initializing proxy
net.sf.hibernate.HibernateException: Could not initialize proxy - the owning Session was closed

由此可见QCustomer代理cȝ实例只有在当前Session范围内才能被初始化?/p>

3Qnet.sf.hibernate.Hibernatecȝinitialize()静态方法用于在Session范围内显式初始化代理cd例,isInitialized()Ҏ用于判断代理cd例是否已l被初始化。例如:

tx = session.beginTransaction();
Customer customer=(Customer)session.load(Customer.class,new Long(1));
if(!Hibernate.isInitialized(customer))
Hibernate.initialize(customer);
tx.commit();
session.close();
customer.getName();

以上代码在Session范围内通过Hibernatecȝinitialize()Ҏ昑ּ初始化了Customer代理cd例,因此当Session关闭后,可以正常讉KCustomer游离对象?/p>

4Q当应用E序讉K代理cd例的getId()ҎӞ不会触发Hibernate初始化代理类实例的行为,例如Q?/p>

tx = session.beginTransaction();
Customer customer=(Customer)session.load(Customer.class,new Long(1));
customer.getId();
tx.commit();
session.close();
customer.getName();

? 应用E序讉Kcustomer.getId()ҎӞ该方法直接返回Customer代理cd例的OID|无需查询数据库。由于引用变? customer始终引用的是没有被初始化的Customer代理cd例,因此当Session关闭后再执行customer.getName()ҎQ? Hibernate会抛Z下异常:

ERROR LazyInitializer:63 - Exception initializing proxy
net.sf.hibernate.HibernateException: Could not initialize proxy - the owning Session was closed






想飞的鱼 2006-07-27 15:21 发表评论
]]>
hibernate outer join属性浅?/title><link>http://www.aygfsteel.com/wiflish/archive/2006/07/19/59013.html</link><dc:creator>想飞的鱼</dc:creator><author>想飞的鱼</author><pubDate>Wed, 19 Jul 2006 08:17:00 GMT</pubDate><guid>http://www.aygfsteel.com/wiflish/archive/2006/07/19/59013.html</guid><wfw:comment>http://www.aygfsteel.com/wiflish/comments/59013.html</wfw:comment><comments>http://www.aygfsteel.com/wiflish/archive/2006/07/19/59013.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/wiflish/comments/commentRss/59013.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/wiflish/services/trackbacks/59013.html</trackback:ping><description><![CDATA[outer join=trueQhibernate对该兌q行外连接抓取;<br />outer join=false, hibernate对该兌不进行外q接抓取?br /><br />当在hibernate.cfg.xml配置文g中的属?br /><property name="hibernate.max_fetch_depth">0</property><br />讄?Ӟ从全局关闭外连接抓取,此时outer-join属性无效?br /><property name="hibernate.max_fetch_depth">2</property><br />讄?gt;0Ӟouter-join属性有效?br /><img src ="http://www.aygfsteel.com/wiflish/aggbug/59013.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/wiflish/" target="_blank">想飞的鱼</a> 2006-07-19 16:17 <a href="http://www.aygfsteel.com/wiflish/archive/2006/07/19/59013.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>hibernate复合主键需注意的一点小问题(hibernate3)http://www.aygfsteel.com/wiflish/archive/2006/06/30/55958.html想飞的鱼想飞的鱼Fri, 30 Jun 2006 06:40:00 GMThttp://www.aygfsteel.com/wiflish/archive/2006/06/30/55958.htmlhttp://www.aygfsteel.com/wiflish/comments/55958.htmlhttp://www.aygfsteel.com/wiflish/archive/2006/06/30/55958.html#Feedback0http://www.aygfsteel.com/wiflish/comments/commentRss/55958.htmlhttp://www.aygfsteel.com/wiflish/services/trackbacks/55958.html所以在q行复合主键映射旉指定复合主键中各字段的长度?br />


想飞的鱼 2006-06-30 14:40 发表评论
]]>
hibernate+mysql存中文问?/title><link>http://www.aygfsteel.com/wiflish/archive/2006/06/30/55916.html</link><dc:creator>想飞的鱼</dc:creator><author>想飞的鱼</author><pubDate>Fri, 30 Jun 2006 03:47:00 GMT</pubDate><guid>http://www.aygfsteel.com/wiflish/archive/2006/06/30/55916.html</guid><wfw:comment>http://www.aygfsteel.com/wiflish/comments/55916.html</wfw:comment><comments>http://www.aygfsteel.com/wiflish/archive/2006/06/30/55916.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.aygfsteel.com/wiflish/comments/commentRss/55916.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/wiflish/services/trackbacks/55916.html</trackback:ping><description><![CDATA[环境Qhibernate3.1 + mysql4.1 + mysql-connector-java-3.0.11-stable-bin.jar驱动<br />当将mysql的默认字W集讄成default-character-set=gbkQ插入中文字W时出现<br />例子Q?br />Hibernate: insert into book (bookpagenum, published, bookname, bookauthor) values (?, ?, ?, ?)<br />could not bind value '待插入的中文字符' to parameter: 2; String index out of range: 9<br /><br />q是mysql的mysql-connector-java-3.0.11-stable-bin.jar驱动问题。更换驱动就好了<br />(比如Qmysql-connector-java-3.1.13-bin.jar)<br /><br /><img src ="http://www.aygfsteel.com/wiflish/aggbug/55916.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/wiflish/" target="_blank">想飞的鱼</a> 2006-06-30 11:47 <a href="http://www.aygfsteel.com/wiflish/archive/2006/06/30/55916.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>hibernate属性配|一览表(摘自深入出hibernate)http://www.aygfsteel.com/wiflish/archive/2006/06/28/55504.html想飞的鱼想飞的鱼Wed, 28 Jun 2006 03:39:00 GMThttp://www.aygfsteel.com/wiflish/archive/2006/06/28/55504.htmlhttp://www.aygfsteel.com/wiflish/comments/55504.htmlhttp://www.aygfsteel.com/wiflish/archive/2006/06/28/55504.html#Feedback0http://www.aygfsteel.com/wiflish/comments/commentRss/55504.htmlhttp://www.aygfsteel.com/wiflish/services/trackbacks/55504.html 属性名
用??/b>
hibernate.dialect
数据库适配?dialect),用于对特定数据库提供支持Q其中包含了针对特定数据库特性的实现Q如hibernate数据cd到特定数据库数据cd的映等?
hibernate.default_schema
在生成的SQL中,schema/tablespace的全限定?br /> hibernate.session_factory_name
把SessionFactoryl定到JNDI中的名称
hibernate.max_fecth_depth
对单根联合(一对一、多对一Q,讄外连接的最大深度,如果?关闭默认的外连接抓取?
hibernate.jdbc.fetch_size
非零|用来讄JDBC获取的记录条数?
hibernate.jdbc.batch_size
非零|指定了Hibernateq行每次扚w提交阀倹{?/font>
hibernate.jdbc.use_scrollable_resultset
讄是否允许Hibernate使用JDBC2提供的可滚动l果集,只有在用用戯行提供的JDBCq接Ӟq个参数才是必需的。否则,Hibernate会根据连接的元数据(metadataQ自行判定?
hibernate.jdbc.use_streams_for_binary
是否在从JDBCdbinaryQ二q制Q或者serializable(可序列化)cdӞ使用stream(?
hibernate.jdbc.use_get_generated_keys
是否允许使用JDBC3的PreparedStatement.getGeneratedKeys()在插入后获取数据库自w生成的key。需?.0以上版本的JDBC驱动?.4或以上版本的JDKQ?br />默认情况下,Hibernate会根据JDBC Connection元数据进行自行判定?br /> hibernate.cglib.use_reflection_optimizer
是否使用CGLIB来代替运行时反射操作(pȝU别属性,默认为在可能旉使用CGLIB)
hibernate.jndi.<propertyName>
把propertyNameq个属性传递给JNDI InitialContextFactory?可?
hibernate.connection.isolation
事务隔离U别Q可选)
hibernate.connection.<propertyName>
把propertyNameq个JDBC属性传递给DriverManager.getConnection()
hibernate.connection.provider_class
指定一个自定义的ConnectionProvidercd
hibernate.cache.provider_class
指定一个自定义的CacheProvider~存提供者的cd
hibernate.cache.use_minimal_puts
是否优化W二U缓存操作,最化~存写入操作Q用于集群~存Q?
hibernate.cache.use_query_cache
是否打开查询~存Q依焉要针Ҏ个查询设|cacheable属性)
hibernate.cache.region_prefix
指定一个自定义的TransactionFactorycdQHibernate Transaction API会使用(默认是JDBCTransactionFactory)
jta.UserTransaction
JTATransactionFactory用来从应用服务器获取JTA UserTransaction的JNDI?
hibernate.transaction.manager_lookup_class
TransactionManagerLookup的类名——当在JTA环境中启用JVMU缓存时使用
hibernate.query.substitutions
把Hibernate查询中的一些短语替换成SQL短语Q短语可能ؓ函数或者字W)
hibernate.show_sql
是否把执行的SQL语句输出到控制台
hibernate.hbm2dll.auto
在SessionFactory创徏后,自动输出schema创徏语句到数据库Q和create-drop同时使用的话Q数据库schema会在SessionFactory昄关闭后被drop?


想飞的鱼 2006-06-28 11:39 发表评论
]]>
学习W记(深入出hibernate)http://www.aygfsteel.com/wiflish/archive/2006/06/22/54519.html想飞的鱼想飞的鱼Thu, 22 Jun 2006 08:42:00 GMThttp://www.aygfsteel.com/wiflish/archive/2006/06/22/54519.htmlhttp://www.aygfsteel.com/wiflish/comments/54519.htmlhttp://www.aygfsteel.com/wiflish/archive/2006/06/22/54519.html#Feedback0http://www.aygfsteel.com/wiflish/comments/commentRss/54519.htmlhttp://www.aygfsteel.com/wiflish/services/trackbacks/54519.html 解耦合设计目标Q?/span>

1?span style="font-family: "Times New Roman"; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">          应用层解耦合——应用逻辑与数据逻辑相分?/span>

           在业务系l的业务逻辑实现q程中,我们应该避免业务逻辑代码中؜杂数据访问代码,同样Q在数据讉K代码中,也应避免出现业务逻辑代码?/span>

2?span style="font-family: "Times New Roman"; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">          资源层解耦合——逻辑l构与物理结构相分离

              底层l构变动的情况下Q尽量避免对上层l构产生影响?/span>          

              物理l构Q这里指的是我们无法控制的系l层面,如底层数据库接口?/span>

 

        DAO Q?/span> Data Accesssor Object Q模式是 Data Accessor 模式?/span> Active Domain Object 模式的组合,其中 Data Accessor 模式实现了数据访问与业务逻辑的分,?/span> Active Domain Object 模式实现了业务数据的对象化封装?/span>

        DAO Accessor 模式Q将数据讉K的实现机制加以封装,与数据的使用代码相分,从外部来看, DAO Accessor 提供了黑盒式的数据存取接口?/span>

    Domain Object 提供了对所面向领域内对象的装?/span>



想飞的鱼 2006-06-22 16:42 发表评论
]]>
hibernate中inverse=true_解http://www.aygfsteel.com/wiflish/archive/2006/06/15/53032.html想飞的鱼想飞的鱼Thu, 15 Jun 2006 09:16:00 GMThttp://www.aygfsteel.com/wiflish/archive/2006/06/15/53032.htmlhttp://www.aygfsteel.com/wiflish/comments/53032.htmlhttp://www.aygfsteel.com/wiflish/archive/2006/06/15/53032.html#Feedback0http://www.aygfsteel.com/wiflish/comments/commentRss/53032.htmlhttp://www.aygfsteel.com/wiflish/services/trackbacks/53032.html映射文g如下Q?br />
<!-- Person.hbm.xml -->
<
hibernate-mapping package="events">
  
<class name="Person" table="person">
      
<id name="id" column="person_id">
          
<generator class="native"/>
      
</id>
      
<property name="age" length="0"/>
      
<property name="firstname"/>
      
<property name="lastname"/>
      
<set name="events" table="person_event">
          
<key column="person_id"/>
          
<many-to-many column="event_id" class="events.Event"/>
      
</set>
  
</class>
</hibernate-mapping>

<!-- Event.hbm.xml -->
<
hibernate-mapping>
  
<class name="events.Event" table="events">
      
<id name="id" column="event_id">
            
<generator class="native"/>
      
</id>
      
<property name="date" column="events_date" type="timestamp"/>
      
<property name="title" column="events_title"/>
      
<set name="participants" table="person_event" inverse="true">
          
<key column="event_id"/>
          
<many-to-many column="person_id" class="events.Person"/>
      
</set>
  
</class>
</hibernate-mapping>

inverse=true的含? 由双向关联另一方维护该兌,己方不维护该兌(只能q行查询操作)。在上述代码中,由Person方维护该<many-to-many>关系Q示例代码如?以向Person参与的Event中加入新的EventZ)Q?br />
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();
        session.beginTransaction();
        Person p 
= (Person) session.load(Person.class, personId);
        Event e 
= (Event) session.load(Event.class, eventId);
        p.getEvents().add(e);//执行该代码时Qhibernate会向中间?person_event中插入person_id和event_id记录Q如果换?font color="#a52a2a">e.getParticipants().add(p)
的话Q该代码不会被执行Q即hibernate不会向表person_event中插入记录?br />        session.getTransaction().commit();

要注意的一点:在双向关联的关系中,映射的column(和table)的D一?卌用相同的表名和列?Q不然设|ؓinverse="true"的这方将失去q个双向关系Q而变成了一个单向关联?br />

想飞的鱼 2006-06-15 17:16 发表评论
]]>hibernate中inverse属性的一个设|规则?/title><link>http://www.aygfsteel.com/wiflish/archive/2006/06/15/52955.html</link><dc:creator>想飞的鱼</dc:creator><author>想飞的鱼</author><pubDate>Thu, 15 Jun 2006 03:30:00 GMT</pubDate><guid>http://www.aygfsteel.com/wiflish/archive/2006/06/15/52955.html</guid><wfw:comment>http://www.aygfsteel.com/wiflish/comments/52955.html</wfw:comment><comments>http://www.aygfsteel.com/wiflish/archive/2006/06/15/52955.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/wiflish/comments/commentRss/52955.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/wiflish/services/trackbacks/52955.html</trackback:ping><description><![CDATA[ <font color="#ff0000"> <b>The rules you have to remember are straightforward:  </b> </font> <br /> <font color="#0000ff">  All bi-directional associations need one side as inverse. <br />  In a one-to-many association it has to be the many-side, <br />  In many-to-many association you can pick either side, there is no difference.</font> <img src ="http://www.aygfsteel.com/wiflish/aggbug/52955.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/wiflish/" target="_blank">想飞的鱼</a> 2006-06-15 11:30 <a href="http://www.aygfsteel.com/wiflish/archive/2006/06/15/52955.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>hibernate配置属性hbm2dll.auto初步理解http://www.aygfsteel.com/wiflish/archive/2006/05/26/48375.html想飞的鱼想飞的鱼Fri, 26 May 2006 08:59:00 GMThttp://www.aygfsteel.com/wiflish/archive/2006/05/26/48375.htmlhttp://www.aygfsteel.com/wiflish/comments/48375.htmlhttp://www.aygfsteel.com/wiflish/archive/2006/05/26/48375.html#Feedback0http://www.aygfsteel.com/wiflish/comments/commentRss/48375.htmlhttp://www.aygfsteel.com/wiflish/services/trackbacks/48375.html1、validateQ验证hbm2dll映射?br />2、updateQ检查更新hbm2dll映射?br />3、createQ先drop数据库,在create数据库?br />4、create-dropQ先drop数据库,在create数据库,当SessionFactory关闭Ӟ又drop数据库?br />

想飞的鱼 2006-05-26 16:59 发表评论
]]>
վ֩ģ壺 ζ| | Ʊ| | Դ| ͨ| | | | ͨ| | | ͨ| | | ͨ| Ϫ| | | | | | ʯׯ| Ӣɳ| ӥ̶| | | ƽ| ͨ| | | | ߱| | | ˳| | | | ۳| |