小记

来源:互联网 发布:算法4和算法导论哪个好 编辑:程序博客网 时间:2024/06/05 06:20

ORACLE查询表的字段数量:

在mysql中可以通过desc 表名 来查看表字段的数量。可以在oracle里面,没有这个语法。

解决办法是用如下语句:select   count(1) from   user_col_comments where   table_name   =   upper( '表名字');


Hibernate之FlushMode的五种状态:

1.NEVEL      ---废弃了

2.MANUAL   ---手动

3.AUTO        ---自动

4.COMMIT   ---提交

5.always      ---一直

其中,当为1,2两种状态时,hibernate会将事务设置为readonly,所以在增加、删除或修改操作过程中会出现如下错误:

org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.NEVER) - turn your Session into FlushMode.AUTO or remove 'readOnly' marker from transaction definition

解决方法为:(1) 配置事务,spring会读取事务中的各种配置来覆盖hibernate的session中的FlushMode;

                        (2) 先编程式修改FlushMode,比如session.setFlushMode(FlushMode.AUTO); 这样hibernate就会自动去除readonly限制;

                        (3) 直接修改opensessioninviewfilter过滤器的配置,配置过滤器的时候配置 openSession org.springframework.orm.hibernate3.support.OpenSessionInViewFilter flushMode AUTO

当为状态3时:设置成auto之后,当程序进行查询、提交事务或者调用session.flush()的时候,都会使缓存和数据库进行同步,也就是刷新数据库

当为状态4时:提交事务或者session.flush()时,刷新数据库;查询不刷新

当为状态5时:每次进行查询、提交事务、session.flush()的时候都会刷数据库

而3与5的区别为:

      当hibernate缓存中的对象被改动之后,会被标记为脏数据(即与数据库不同步了)。当session设置为FlushMode.AUTO时,hibernate在进行查询的时候会判断缓存中的数据是否为脏数据,是则刷数据库,不是则不刷,而always是直接刷新,不进行任何判断。很显然auto比always要高效得多

0 0