??xml version="1.0" encoding="utf-8" standalone="yes"?>欧美日韩国产影院,欧美在线欧美在线,欧美日韩1区http://www.aygfsteel.com/leekiang/category/22103.htmlMDA/MDD/TDD/DDD/DDDDDDDzh-cnFri, 04 Mar 2011 21:00:57 GMTFri, 04 Mar 2011 21:00:57 GMT60ibatishttp://www.aygfsteel.com/leekiang/archive/2011/02/26/345260.htmlleekiangleekiangSat, 26 Feb 2011 14:47:00 GMThttp://www.aygfsteel.com/leekiang/archive/2011/02/26/345260.htmlhttp://www.aygfsteel.com/leekiang/comments/345260.htmlhttp://www.aygfsteel.com/leekiang/archive/2011/02/26/345260.html#Feedback0http://www.aygfsteel.com/leekiang/comments/commentRss/345260.htmlhttp://www.aygfsteel.com/leekiang/services/trackbacks/345260.html<sqlMap namespace="bbs_define">
 (tng) (tng) (tng) <!?selectBySql ?gt;
 (tng) (tng) (tng) <select id="selectBySql" resultClass="java.util.HashMap"
 (tng) (tng) (tng) (tng) (tng) (tng) (tng) remapResults="true"
 (tng) (tng) (tng) (tng) (tng) (tng) (tng) parameterClass="java.util.HashMap">
 (tng) (tng) (tng) (tng) (tng) (tng) (tng) <isNotEmpty property="sql">$sql$</isNotEmpty>
 (tng) (tng) (tng) </select> (tng) (tng)
 (tng) (tng) (tng) <!?updateBySql ?gt;
 (tng) (tng) (tng) <update id="updateBySql" parameterClass="java.util.HashMap">
 (tng) (tng) (tng) (tng) (tng) (tng) (tng) <isNotEmpty property="sql">$sql$</isNotEmpty>
 (tng) (tng) (tng) </update> (tng) (tng)
</sqlMap>

其中最重要的设|是“remapResults="true"”。remapResults讄成trueQ表C结果字D可以是不定的。也是_(d)q次可返回“ID,NAME”两个字D,下次何返回“ID,NAME,TYPE_ID”三个字D,也可以返回??br />
用ibatis实现数据水^切分Q?br />http://code.google.com/p/shardbatis/
http://code.google.com/p/ibatis-sharding/

参考:(x)
1QIbatis的动态SQL http://hz.seraph.blog.163.com/blog/static/981677452008111902458957/
2Q用ibatis的一点小技?http://qa.taobao.com/?p=7371
3Qhttp://www.ibm.com/developerworks/cn/opensource/os-cn-ibatis/?ca=drs-tp4608
4Qhttp://itnewsvendor.appspot.com/2303004-ibatis_%E6%95%B4%E7%90%86_batis.html
5Qhttp://itnewsvendor.appspot.com/4633016-ibatis_2.x_%E6%97%A5%E5%BF%97.html
6Qhttp://blog.sina.com.cn/s/blog_63f93f510100i16h.html
7Qhttp://lijingyao8206.javaeye.com/blog/840204
8, http://qa.taobao.com/?p=7677
9Qhttp://blog.csdn.net/sunyujia/archive/2008/07/13/2646030.aspx
10QiBATIS不适合使用的四U情冉|?http://developer.51cto.com/art/200907/136897.htm
11Qhttp://blog.sina.com.cn/s/blog_63f93f510100i16h.html


leekiang 2011-02-26 22:47 发表评论
]]>
关于ORMhttp://www.aygfsteel.com/leekiang/archive/2010/02/14/313005.htmlleekiangleekiangSun, 14 Feb 2010 13:22:00 GMThttp://www.aygfsteel.com/leekiang/archive/2010/02/14/313005.htmlhttp://www.aygfsteel.com/leekiang/comments/313005.htmlhttp://www.aygfsteel.com/leekiang/archive/2010/02/14/313005.html#Feedback0http://www.aygfsteel.com/leekiang/comments/commentRss/313005.htmlhttp://www.aygfsteel.com/leekiang/services/trackbacks/313005.html (tng) http://codemonkeyism.com/orms/
2Qhttp://corte.si/posts/code/farewell-to-orms.html
3,http://andyhu1007.javaeye.com/blog/636063
http://blog.csdn.net/chelsea/archive/2009/12/28/5094652.aspx


leekiang 2010-02-14 21:22 发表评论
]]>
hibernate动态表http://www.aygfsteel.com/leekiang/archive/2010/01/03/308095.htmlleekiangleekiangSun, 03 Jan 2010 09:31:00 GMThttp://www.aygfsteel.com/leekiang/archive/2010/01/03/308095.htmlhttp://www.aygfsteel.com/leekiang/comments/308095.htmlhttp://www.aygfsteel.com/leekiang/archive/2010/01/03/308095.html#Feedback0http://www.aygfsteel.com/leekiang/comments/commentRss/308095.htmlhttp://www.aygfsteel.com/leekiang/services/trackbacks/308095.htmlHibernate动态模?dynamic models) 一对多映射的实?/a>
http://scnjl.blogbus.com/logs/35361929.html

2Q?br />hibernate shards

3,
http://www.javaeye.com/topic/142404

4,
http://www.infoq.com/cn/articles/hibernate-custom-fields


leekiang 2010-01-03 17:31 发表评论
]]>
在一个单独的DAO中؜合用Hibernate ?JDBC http://www.aygfsteel.com/leekiang/archive/2009/12/18/306589.htmlleekiangleekiangFri, 18 Dec 2009 08:51:00 GMThttp://www.aygfsteel.com/leekiang/archive/2009/12/18/306589.htmlhttp://www.aygfsteel.com/leekiang/comments/306589.htmlhttp://www.aygfsteel.com/leekiang/archive/2009/12/18/306589.html#Feedback0http://www.aygfsteel.com/leekiang/comments/commentRss/306589.htmlhttp://www.aygfsteel.com/leekiang/services/trackbacks/306589.html Hibernate 的确通过 PersistentEnum 接口提供?jin)对标准?/span> 的支持,q得我们的域对象实C(jin)一个与 ShippingCompany 对象非常cM的结构。然而,我们可能对将域对象与某个特定的持久化实现q于耦合持保守态度。如果我们计划长期?/span> Hibernate Q这可能q不是一个太大的问题Q但是请谨慎考虑q个决策。如果我们?/span> ibatis Q那么我们就完全没那么幸q了(jin)Q它完全不支持标准化。谢天谢圎ͼ如果我们?/span> ORM Dq耦合或者完全没有这斚w的支持,q有个解x(chng)案——?/span> JDBC ?/span>

?/span> Spring 的支持,使用 JDBC 变得如此单,我们不会(x)再因为它的复杂性而将其的优先U打个折扣。可是,如果我们选择使用某个特定?/span> ORM 工具Q那么我们就很难用基?/span> JDBC ?/span> DAO 实现q行替换?jin)——目前我们就是这栗当我们同时在一个类中包含了(jin) JDBC ?/span> hibernate 代码Ӟ我们无法?/span> Spring 提供的支持。因为我们的 DAO 只能扩展 HibernateDaoSupport ?/span> JdbcDaoSupport 二者之一。幸q的是,q里有一个优雅的解决Ҏ(gu)Q它允许我们?/span> Hibernate ?/span> JDBC 代码装在同一个类之内Q而不?x)因此失?/span> Spring 的支持。这个方案的关键在于?/span> JDBC 代码装在内部类中,之后主?/span> DAO 的调用委托给q个内部cd完成。代码清?/span> 11-6 提供?jin)一个示例:(x)

代码清单 11-16. 在一个单独的 DAO 中؜合?/span> Hibernate ?/span> JDBC

package com.apress.prospring.ch11.canonicalization;

 (tng)

import org.springframework.jdbc.core.support.JdbcDaoSupport;

import org.springframework.orm.hibernate.support.HibernateDaoSupport;

 (tng)

public class MyDao extends HibernateDaoSupport {

 (tng)

 (tng) (tng) private MyJdbcDao innerDao;

 (tng)

 (tng) (tng) public MyDao() {

 (tng) (tng) (tng) (tng) (tng) innerDao = new MyJdbcDao();

 (tng) (tng) }

 (tng)

 (tng) (tng) public void update(MyDomainObject obj) {

 (tng) (tng) (tng) (tng) (tng) // use Hibernate to persist the data

 (tng) (tng) }

 (tng)

 (tng) (tng) public MyDomainObject getById(int someId) {

 (tng) (tng) (tng) (tng) (tng) return innerDao.getBy(someId);

 (tng) (tng) }

 (tng)

 (tng) (tng) private static class MyJdbcDao extends JdbcDaoSupport {

 (tng)

 (tng) (tng) (tng) (tng) (tng) public MyDomainObject getBy(int someId) {

 (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) // do some real processing

 (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) return null;

 (tng) (tng) (tng) (tng) (tng) }

 (tng) (tng) }

}

 (tng)

管q只是一个简单的实现Q我们也可以从中得到启发。所有的 JDBC 相关代码都被转移C个内部类中,而此内部cL展了(jin) JdbcDaoSupport , 所有的 Hibernate 相关功能都留在外部,外部cM然是 HibernateDaoSupport . 的子cR通过q个c,我们可以使用 Hibernate 完成域对象的持久化,但是我们可以查询功能交l嵌入的 JDBC DAO d成?/span>

在我们的应用中有效利用标准化 Q可以通过避免大量无谓对象的创建,从而极大提升内存(sh)用效率。如果我们必L新标准化对象相关的数据,同时我们?/span> DAO 中用了(jin) ORM 框架Q那么我们就可以?/span> ORM 无关的Ş式引入一?/span> JDBC 代码来加入标准化 支持?/span>


来源:Pro Spring中文?http://book.csdn.net/bookfiles/48/100481407.shtml

http://hi.baidu.com/%D3%F4%C3%C6%BB%A8%C9%FA%BD%B4/blog/item/7768d41e8c06ceffe0fe0ba6.html



leekiang 2009-12-18 16:51 发表评论
]]>
hibernate和jdbc事务l一控制http://www.aygfsteel.com/leekiang/archive/2009/12/11/305492.htmlleekiangleekiangThu, 10 Dec 2009 16:14:00 GMThttp://www.aygfsteel.com/leekiang/archive/2009/12/11/305492.htmlhttp://www.aygfsteel.com/leekiang/comments/305492.htmlhttp://www.aygfsteel.com/leekiang/archive/2009/12/11/305492.html#Feedback0http://www.aygfsteel.com/leekiang/comments/commentRss/305492.htmlhttp://www.aygfsteel.com/leekiang/services/trackbacks/305492.html 原理是保证?connection 的唯一性?br /> jdbc我是调spring的jdbcTemplate来操作,
l过试。在同一个数据源的情况下直接使用Hibernate的TxManager可以同步事务Q问题解冟?br /> ?br /> Rod Johnson的话Q?
引用
It is possible--and sometimes useful--to have coordinated transactions for both. Your JDBC transactions will be managed by the HibernateTransactionManager if you work with the same JDBC DataSource in the same transaction. That is, create the SessionFactory using Spring's SessionFactoryBean using the same DataSource that your JdbcTemplates use.

The only issue to watch, of course, is that you may be invalidating your Hibernate cache by JDBC changes. Generally I find it best to use JDBC to update only tables that don't have Hibernate mappings.

Juergen Hoeller的话Q?
引用
As Rod said, simply keep using HibernateTransactionManager, which auto-detects the DataSource used by Hibernate and seamlessly exposes Hibernate transactions as JDBC transactions for that DataSource. JDBC code that accesses the same DataSource via Spring will automatically participate in such transactions.

Note that you must specify the DataSource for Hibernate via LocalSessionFactoryBean's "dataSource" property to allow HibernateTransactionManager to auto-detect it. Alternatively, you can explicitly pass the DataSource to HibernateTransactionManager's "dataSource" property.
http://www.fireflow.org/redirect.php?tid=498

Rod Johnson在spring 论坛中有一句话很好的ȝ?jin)如何在试中处理hibernate~存:
Remember that you can clear the Hibernate session, removing objects already associated with it. This is often necessary before requerying in tests, and solves most (if not all) problems.
I typically use JDBC for verification. The pattern is
- do Hibernate operation
- flush Hibernate session
- issue JDBC query to verify results
That way I'm verifying what Hibernate did to the database in the same transaction.


leekiang 2009-12-11 00:14 发表评论
]]>
hibernate处理LOBhttp://www.aygfsteel.com/leekiang/archive/2009/07/31/289192.htmlleekiangleekiangThu, 30 Jul 2009 16:05:00 GMThttp://www.aygfsteel.com/leekiang/archive/2009/07/31/289192.htmlhttp://www.aygfsteel.com/leekiang/comments/289192.htmlhttp://www.aygfsteel.com/leekiang/archive/2009/07/31/289192.html#Feedback0http://www.aygfsteel.com/leekiang/comments/commentRss/289192.htmlhttp://www.aygfsteel.com/leekiang/services/trackbacks/289192.htmlOracle9iR2和Oracle10G以上版本已经可以直接q行clob的插入,条g查询Q模p查询了(jin)。这一点,你可以试一试,我这周周一刚刚? Oracle10.1.0.3 Linux x86上面试过Q不是whereq是likeQ就像varchar2一样处理?
另外Oracle JDBC Driver升到最新的版本Q即Oracle10.1.0版本同时发布的odjbc14.jarQ那么你直接可以对clobq行操作?br />也就是说Q如果你使用最新的Oracle JDBC DriverQ用比较新的Oracle版本Q你可以直接像操作varchar2那样操作clobQ没有Q何限制了(jin)?
4000字符的限制完全是因ؓ(f)Oracle的Thin Driver造成的,用OCI Driver是不?x)有q个问题的。也是_(d)q个限制与驱动相关与数据库无兟?
我试q?0g的驱动跑9i的数据库Q操作CLOB字段和操作varchar2一Pq且没有4000的限制。一换成9i的Driver错误依旧。。?i的没有测试过Q不q原理应该一栗?
像Robbin说的那样Q我用的是最新的最新的Oracle Database 10g (10.1.0.2.0) 驱动E序,数据库是Release 9.2.0.1.0 ,插入一?0万多字符的数据到clobcd的字D?抛出异常:Caused by: java.sql.SQLException: setString 只能处理于 32766 个字W的字符丌Ӏ我试了(jin)多次Q还是无法解冟?br />Robbin说的没错Q我试过?jin)在xxx.hbm.xml中将数据库中Clobcd的字D|成Hibernate?span style="color: red;">textcdQ没有Q何限Ӟ但是映射成java.lang.Stringcd却有32K大小的限制?
oracle 10g 的驱动的好
thin driver 也能利按照 String 方式处理 Clob 字段Q可以适用?8.16 以后的所有版?br />映射成text在同一列中有多个clob字段的时候有bugQ?
保存时会(x)后一个字D늚内容保存到前一个字D里面去Q不知道什么原因,我实在有些莫名其妙?
换成spring的ClobStringType后一切正?
l测试,使用 Oracle 10g ?JDBC 驱动Q可以把 LONG cd的字D当成超长的 VARCHAR2 cd字段看待?
注意Q数据库中应该?LONG 型,而不?CLOB cd。?CLOB cdQ如果有中文Q会(x)莫名其妙的丢掉一些字W。这应该?Oracle 的一?bug?
适用?Oracle 9.2 以上版本的数据库。(注意仅仅是?10g ?JDBC 驱动而已Q即 ojdbc14.jar 包)(j)

参考:(x)
* Oracle JDBC 驱动下蝲地址 http://www.oracle.com/technology/software/tech/java/sqlj_jdbc/index.html
* Handling CLOBs - Made easy with Oracle JDBC 10g http://www.oracle.com/technology/sample_code/tech/java/codesnippet/jdbc/clob10g/handlingclobsinoraclejdbc10g.html


leekiang 2009-07-31 00:05 发表评论
]]>
HibernateException: Unexpected row count: 0 expected: 1http://www.aygfsteel.com/leekiang/archive/2009/07/22/287818.htmlleekiangleekiangWed, 22 Jul 2009 03:13:00 GMThttp://www.aygfsteel.com/leekiang/archive/2009/07/22/287818.htmlhttp://www.aygfsteel.com/leekiang/comments/287818.htmlhttp://www.aygfsteel.com/leekiang/archive/2009/07/22/287818.html#Feedback0http://www.aygfsteel.com/leekiang/comments/commentRss/287818.htmlhttp://www.aygfsteel.com/leekiang/services/trackbacks/287818.htmlorg.hibernate.HibernateException: Unexpected row count: 0 expected: 1
 (tng) (tng)  (tng)at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:32)

 (tng) (tng)  (tng)先用对象操作得到Person p = get(Person.class,35);
 (tng) (tng)  (tng)直连得到connection,执行delete person where id=35
 (tng) (tng)  (tng)
 (tng) (tng)  (tng)事务提交前hibernate?x)对对象q行(g)查,看属性是否有变化Q如果有变化׃(x)执行update操作?br /> (tng) (tng)  (tng)事务Ҏ(gu)内既有对象操作,又有sqlӞ往往sql先执行,
 (tng) (tng)  (tng)id=35的记录已l被删了(jin)Q再执行update 35时就?x)报那个臭名昭著的HibernateException: Unexpected row count: 0 expected: 1Q不能同步数据库状?br /> (tng) (tng)  (tng)Z么有的记录删除时?x)updateQ有的却没有Q开始一直没扑ֈ原因Q因为update语句太长?jin)?br /> (tng) (tng)  (tng)后来灉|一动,在映里加了(jin)dynamic-update="true"Qupdate语句变成?jin)可qupdate Person set zd=? where ID=?
 (tng) (tng)  (tng)一查AbstractPerson,发现getZd()被修改了(jin)Q?br /> (tng) (tng)  (tng) (tng) (tng)  (tng)public String getZd() {
 (tng) (tng)  (tng) (tng) (tng)  (tng)if (zd != null)
 (tng) (tng)  (tng) (tng) (tng)  (tng) (tng) (tng)  (tng)return zd;
 (tng) (tng)  (tng) (tng) (tng)  (tng)else
 (tng) (tng)  (tng) (tng) (tng)  (tng) (tng) (tng)  (tng)return "";
 (tng) (tng)  (tng) (tng) (tng) }
 (tng) (tng) (tng) q样凡是zd为null的记录,删除旉?x)报错?br /> (tng) (tng)  (tng)
 (tng) (tng)  (tng)ȝQ?1)HQL和sqlq时要心(j)Q一不小?j)就出现数据不同步,有空看看事务的处?br /> (tng) (tng)  (tng) (tng) (tng) (tng) (tng) (tng) (2)映射的类里的getҎ(gu)不要随便修改

leekiang 2009-07-22 11:13 发表评论
]]>
hibernate异常"Found shared references to a collection"http://www.aygfsteel.com/leekiang/archive/2008/10/31/237908.htmlleekiangleekiangFri, 31 Oct 2008 14:11:00 GMThttp://www.aygfsteel.com/leekiang/archive/2008/10/31/237908.htmlhttp://www.aygfsteel.com/leekiang/comments/237908.htmlhttp://www.aygfsteel.com/leekiang/archive/2008/10/31/237908.html#Feedback2http://www.aygfsteel.com/leekiang/comments/commentRss/237908.htmlhttp://www.aygfsteel.com/leekiang/services/trackbacks/237908.html假定,ParentcL一个Set属性,里面攄是Son。如果查?from Parent",某个Parent哪怕一个Son都没有,那个Set属性不?x)?f)nullQ而是一个空集合?br />q时候如果你Parent newP=new Parent();然后BeanUtils.copyPropertis(newP,origP);最后就?x)报hibernate异常"Found shared references to a collection"?br />?hibernate在什么时机发?两个对象׃n一个集?的情늚Q我q边的例子是在下一ơ查询时发现的?br />
原因:
BeanUtils.copyPropertis是浅拯Q导致这两个对象引用的Set是同一个Set,q在hibernate中是不允许的Q参见Hibernate referenceW?章的"Two entities may not share a reference to the same collection instance"?br />q种问题常见于复制对象时?br />如何解决:newP.setSonSet(null);
q有原因可能是ƈ发操?http://www.aygfsteel.com/fastzch/archive/2006/12/22/89520.html

参?
http://markmail.org/message/fszouomkeicjynw2
http://blog.csdn.net/programeyonger/archive/2008/01/31/2075304.aspx
http://www.javaeye.com/topic/99505


leekiang 2008-10-31 22:11 发表评论
]]>
Session,SessionFactory,Connetion{?/title><link>http://www.aygfsteel.com/leekiang/archive/2008/03/11/185503.html</link><dc:creator>leekiang</dc:creator><author>leekiang</author><pubDate>Tue, 11 Mar 2008 14:43:00 GMT</pubDate><guid>http://www.aygfsteel.com/leekiang/archive/2008/03/11/185503.html</guid><wfw:comment>http://www.aygfsteel.com/leekiang/comments/185503.html</wfw:comment><comments>http://www.aygfsteel.com/leekiang/archive/2008/03/11/185503.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/leekiang/comments/commentRss/185503.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/leekiang/services/trackbacks/185503.html</trackback:ping><description><![CDATA[1,有时q箋(hu)调多个DaoҎ(gu)时会(x)报连接关闭,原因往往是关闭session不当?br /> (tng) 不要用session.close(),q样?x)同一个线E的下一个DaoҎ(gu)里执?br /> (tng) HibernateSessionFactory.getSession()时取到的是已l被关闭的session,当然?x)报错?jin)?br /><br />2QConnection conn =session.connection();<br /> (tng) q个conn一定要执行conn.close()?<br /><br />3,<br />http://hi.baidu.com/sodarfish/blog/item/b996a3df9224d217622798ec.html<br />在通常的情况下使用DriverManager.getConnection()得到的是一个Connection的实例,当你调用它的closeQ)(j)? 法时?x)关闭StateMent和ResultSet。但是我们在使用q接池的q程中,通过q接池得到ConnectionQ当我们调用 Connection的closeQ)(j)ӞConnectionq不是被关闭?jin),而是回到?jin)连接池中,它以后还(sh)(x)被其他的代码取出来使用Q如果我们没有关 闭stmt和rs的话Q只?x)ɾpȝ中的stmt和rs来多。所以在使用q接池后Q调用conn.closeQ)(j)前应先将rs和stmt关闭?br /><br /> 至于Z么调用close()之后不是直接关闭此连接,而是q回l?span class="hilite1">q接?/span>Q这是因为dbcp使用委派模型来实现Connection接口?jin)?<br /><br />http://nymph.blogdriver.com/nymph/180989.html#comment<br /> http://www.javaeye.com/topic/9317?page=1<br /> http://www.javaeye.com/topic/48048?page=1<br /><a target="_blank" href="/wangdei1/archive/2008/10/05/232515.html">Hibernate中的session 事务处理机制</a><br /> (tng) <br /><img src ="http://www.aygfsteel.com/leekiang/aggbug/185503.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/leekiang/" target="_blank">leekiang</a> 2008-03-11 22:43 <a href="http://www.aygfsteel.com/leekiang/archive/2008/03/11/185503.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>hibernate杂记http://www.aygfsteel.com/leekiang/archive/2008/02/16/180148.htmlleekiangleekiangFri, 15 Feb 2008 21:04:00 GMThttp://www.aygfsteel.com/leekiang/archive/2008/02/16/180148.htmlhttp://www.aygfsteel.com/leekiang/comments/180148.htmlhttp://www.aygfsteel.com/leekiang/archive/2008/02/16/180148.html#Feedback0http://www.aygfsteel.com/leekiang/comments/commentRss/180148.htmlhttp://www.aygfsteel.com/leekiang/services/trackbacks/180148.htmlselect new Map(a.id as id,a.name as name,b.type as type) from A a,B b where
a.id=b.aId;
...
List mapList=query.list();
....

在jsp面可以和用普通的JavaBean一L(fng)方式输出
<c:forEach items="${mapList}" var="m">
<tr> <td>
<c:out value="${m.id}"/> </td> <td>
<c:out value="${m.name}"/> </td>
<td> <c:out value="${m.type}"/> </td> </tr>
</c:forEach>
q样的处理也是很z的

select new MyObj(id,name,deptid,deptName) from tb_usr,tb_dept where .....
q种方式要求MyObjcL对应的构造方?br />
2.HQL supports subqueries in the where clause. We can’t think of many good uses
for subqueries in the from clause, although select clause subqueries might be a
nice future extension.
不支持from后的子查询,支持where子查?br />http://blog.zol.com.cn/655/article_654256.html

3Q?String sql="select {fi.*} from FuncInfo fi " +
 (tng) (tng) "left join RoleSubFunc rsf on fi.FuncId=rsf.FuncId "+
 (tng) (tng) (tng) (tng) (tng) (tng) "left join RoleInfo ri on rsf.RoleId=ri.RoleId "+
 (tng) (tng) (tng) (tng) (tng) (tng) "left join UserRole ur on ri.RoleId=ur.RoleId "+
 (tng) (tng) (tng) (tng) (tng) (tng) "where ur.UserId='"+userId+"'";//可以无限向上扄U?br /> (tng)List list =session.createSQLQuery(sql).addEntity("fi", FuncInfo.class).list();

4,Z么Hibernate 3中的HQL无法查询汉字
使用同样的代码和配置文gQ在Hibernate 2上完全没有问题,在Hibernate 3中,使用如下HQL查询Q无法得到正的l果集:(x)
String hql = "from story where title like '%汉字%'";
Query q = session.createQuery(hql);
但用下面的HQL查询Q却可以得到正确l果集:(x)
String hql = " from story where title like '%english%'";
Query q = session.createQuery(hql);
{:(x)如果采用的是拼接HQL的方式,从Hibernate 2升到Hibernate 3实?x)出现汉字ؕ码问题。在控制C可以看到QSQL的汉字部分变成了(jin)qQ?br />[DEBUG] 2005-08-14 14:33:58 org.hibernate.SQL - "select story0_.content from story as story0_ where story0_.title like '%&–°é?amp;&Št&€?
在Hibernate中,查询时应量使用占位W的写法Q如下)(j)Q这h可以避免q问题Q又可以避免潜在的SQL注入dQ?br />getHibernate().find("from story where title like ? ", "%汉字%")
??update TbTest set name='张三' "也会(x)有类似的问题,要改为占位符的写?br />http://xqfy1983.blog.sohu.com/61054398.html

5,使用Hibernate.DATEӞ得到的时间不带分U?br /> (tng) 可以考虑使用Hibernate.CALENDAR,实际cd是java.util.GregorianCalendar,然后再getTime()
6,
报表查询 (tng) select new Table(t1.a,t2.b ...) (tng) from .....
 (tng) select new Object(vo.id,vo.name) from VO vo
 (tng) q种写法需事先写好构造方?br />7,List cats = sess.createSQLQuery("select {cat.*} from cats cat")
 (tng)  (tng)  (tng)  (tng) .addEntity("cat", Cat.class);
 (tng)  (tng)  (tng)  (tng) .setMaxResults(50);
 (tng)  (tng)  (tng)  (tng) .list();
8,貌似hibernated或修改对?如果字符串类型的属性的gؓ(f)I字W串(大小?),则自动当null处理
9,如果在hbm中某属性设为not nullQ然后如果po中的该属性ؓ(f)nullQ则hibernate?x)抛异?br /> (tng) 但如果在hbm中设|属性的长度Q而实际的长度过?jin),hibernate不会(x)抛异?br />10,如果要生成得sql不是每次都包括所有的列,可配|参数实?
<class name="onlyfun.caterpillar.User" table="T_USER"
dynamic-insert="true"
dynamic-update="true">
来源:http://caterpillar.onlyfun.net/Gossip/HibernateGossip/DynamicSQL.html
但ƈ不是讄?jin)dynamic-update=true׃(x)有效果,要生效是有条件的.
(1)同一session内,对已lpersisit的对象进行update?br /> 但有一奇怪现?例如memo字段原来为空Qo.setMemo(null)Q生成的update的sqlq是?x)有set memo=null的语?不知道ؓ(f)什?br /> (2)不同session之间Qupdate传入的对象是另一个session中的persist对象Q然后merge
http://qbar.qq.com/u2011541/19.htm
http://xuliangyong.javaeye.com/blog/74696
11,
http://yuonch.javaeye.com/blog/89859
http://yuonch.javaeye.com/blog/90727

12,

session.createQuery("delete from Company where id=1").executeUpdate();
q种写法必须配置org.hibernate.hql.ast.ASTQueryTranslatorFactory,否则?x)?br />

HibernateQueryException: query must begin with SELECT or FROM
?a >http://czg185960.spaces.live.com/blog/cns!32A09070624FB42C!208.entry


leekiang 2008-02-16 05:04 发表评论
]]>
升到hibernate3.2http://www.aygfsteel.com/leekiang/archive/2007/10/09/151197.htmlleekiangleekiangMon, 08 Oct 2007 18:03:00 GMThttp://www.aygfsteel.com/leekiang/archive/2007/10/09/151197.htmlhttp://www.aygfsteel.com/leekiang/comments/151197.htmlhttp://www.aygfsteel.com/leekiang/archive/2007/10/09/151197.html#Feedback0http://www.aygfsteel.com/leekiang/comments/commentRss/151197.htmlhttp://www.aygfsteel.com/leekiang/services/trackbacks/151197.html1,从Hibernate 3.0.x/3.1.x升到最新的3.2版,一定要注意Q?.2版的很多sql函数如count(), sum()的唯一q回值已l从Integer变(sh)ؓ(f)LongQ如果不升代码Q会(x)得到一个ClassCastException?/p>

q个变化主要是ؓ(f)?jin)兼容JPAQ可以在hibernate.org的最新文档中扑ֈ说明?/p>

Hibernate Team也提供了(jin)一个与原来兼容的解x(chng)案:(x)

 (tng) Configuration classicCfg = new Configuration();
 (tng) classicCfg.addSqlFunction( "count", new ClassicCountFunction());
 (tng) classicCfg.addSqlFunction( "avg", new ClassicAvgFunction());
 (tng) classicCfg.addSqlFunction( "sum", new ClassicSumFunction());
 (tng) SessionFactory classicSf = classicCfg.buildSessionFactory();

?/p>

int (tng)count (tng)= (tng)((Integer)q.uniqueResult()).intValue();

Ҏ(gu) (tng)int (tng)count (tng)= (tng)((Number)q.uniqueResult()).intValue(); (tng)q样可以两个版本同时兼?

2,hibernate3.2要求ehcache1.2

3,session.createSQLQuery(sql).executeUpdate();q个hibernate3.0.5不支?而hibernate3.2支持

 (tng) session.createSQLQuery(fsql).addScalar("singlevalue",
 (tng) (tng) (tng)  (tng) (tng) (tng)  (tng) (tng) (tng)  (tng) (tng) (tng)  (tng) (tng) (tng)  (tng) (tng) (tng) Hibernate.DOUBLE).uniqueResult();q个C(jin)3.2׃需要addScalar?

4,session.createSQLQuery(sql).addEntity(Class class);hibernate3.0.5不支持,单个参数的addEntityҎ(gu)

5Qhibernate3.2可以对原生sql 查询使用ResultTransformer。这?x)返回不受Hibernate理的实体?br />sess.createSQLQuery("SELECT NAME, BIRTHDATE FROM CATS")
 (tng) (tng) (tng) (tng) (tng) (tng) (tng) .setResultTransformer(Transformers.aliasToBean(CatDTO.class))

或setResultTransformer(new AliasToBeanResultTransformer(CatDTO.class))
上面的查询将?x)返回CatDTO的列?它将被实例化q且NAME和BIRTHDAY的值注入对应的属性或者字Dc(din)?
http://bbs.xml.org.cn/blog/more.asp?name=lhwork&id=15351

但必L意,Ҏ(gu)一个列都必addScalar("列名")

6QsetResultTransformer与addEntity的一个区别是前者支持查L的列Q后者必ȝselect * from users的Ş式或select {a.*},{b.*} from a,b where ....?br />

7,Map vs. Object[]

Since you can also use a transformer that return a Map from alias to value/entity (e.g. Transformers.ALIAS_TO_MAP), you are no longer required to mess with index based Object arrays when working with a result.

List iter = s.createQuery(
"select e.student.name as studentName," +
" e.course.description as courseDescription" +
"from Enrolment as e")
.setResultTransformer( Transformers.ALIAS_TO_MAP )
.iterate();

String name = (Map)(iter.next()).get("studentName");

Again, this works equally well for Criteria, HQL and native SQL.

 (tng)



leekiang 2007-10-09 02:03 发表评论
]]>
hibernate问题http://www.aygfsteel.com/leekiang/archive/2007/09/28/148919.htmlleekiangleekiangThu, 27 Sep 2007 19:51:00 GMThttp://www.aygfsteel.com/leekiang/archive/2007/09/28/148919.htmlhttp://www.aygfsteel.com/leekiang/comments/148919.htmlhttp://www.aygfsteel.com/leekiang/archive/2007/09/28/148919.html#Feedback0http://www.aygfsteel.com/leekiang/comments/commentRss/148919.htmlhttp://www.aygfsteel.com/leekiang/services/trackbacks/148919.html
2,执行以下语句时hibernate3.0.5?x)报??.2不会(x)
sql="select 1+1 from dual";
session.createSQLQuery(sql).uniqueResult()
报错:addScalar() or addEntity() (tng)must be called on a sql query before executing the query.

3,<many-to-one> 的lazy讄为trueӞget子对象不?x)把该父对象抓过?但可以手动写代码抓取父对?br />?Son son =(Son)this.getHibernateTemplate().get(Son.class, id);
 (tng) (tng) (tng)  (tng) (tng) 然后执行 son.getParent().getName();
 (tng) (tng) q样不仅仅会(x)抓取到name,其他所有的属性如age,sex{都?x)取刎ͼ即用p.getParent().getAge()辑ֈ?jin)同L(fng)效果Q后台都执行?jin)select * from parent where id=? (tng) (tng) 注意用p.getParent()仅能得到parent的id.
 (tng) (tng) q时debug查看parent对象的内存快?看到的是一个用cglib实现的代理对?
Hibernate通过使用CGLIB,来实现动态构造一个目标对象的代理cd象,q且在代理类对象中包含目标对象的所有属性和Ҏ(gu)Q而且所有属性均被赋gؓ(f)null。通过调试器显C的内存快照Q我们可以看出此时真正的User对象Q是包含在代理对象的CGLIB$CALBACK_0.target属性中Q当调用son.getName()Ҏ(gu)Q这旉过CGLIB赋予的回调机Ӟ实际上调用CGLIB$CALBACK_0.getName()Ҏ(gu)Q当调用该方法时QHibernate?x)首先检查CGLIB$CALBACK_0.target属性是否ؓ(f)nullQ如果不为空Q则调用目标对象的getNameҎ(gu)Q如果ؓ(f)I,则会(x)发v数据库查询,生成cMq样的SQL语句Qselect * from parent where id=??来查询数据,q构造目标对象,q且它赋值到CGLIB$CALBACK_0.target属性中?br />q样Q通过一个中间代理对象,Hibernate实现?jin)实体的延迟加蝲Q只有当用户真正发v获得实体对象属性的动作Ӟ才真正会(x)发v数据库查询操作?br /> (tng) (tng) (tng) <many-to-one> 的lazy讄为false?抓取父对象没有采用代理机制?br />
4,用session.close()Q执行多ơ查询后报session is closed的错?而hibernateSessionFactory.closeSession()没有q个问题Q这是什么原?

5,ORA-01466: 无法L?- 表定义已更改
原因是系l时间修攚w成的,其他原因详见
http://www.orafaq.com/usenet/comp.databases.oracle.server/2007/03/31/1586.htm

6,
spring的一个方法上有事务,先用hibernate加蝲一个对象,接着改变对象的某个属性的|
再用sqlL据库查对应的记录Q然后才提交?br />用sqlL时发现对应的字段也改变(sh)(jin)Q这是怎么回事Q?br />

 (tng) (tng)


leekiang 2007-09-28 03:51 发表评论
]]>
hibernate扚w处理(?http://www.aygfsteel.com/leekiang/archive/2007/09/27/148688.htmlleekiangleekiangThu, 27 Sep 2007 06:22:00 GMThttp://www.aygfsteel.com/leekiang/archive/2007/09/27/148688.htmlhttp://www.aygfsteel.com/leekiang/comments/148688.htmlhttp://www.aygfsteel.com/leekiang/archive/2007/09/27/148688.html#Feedback0http://www.aygfsteel.com/leekiang/comments/commentRss/148688.htmlhttp://www.aygfsteel.com/leekiang/services/trackbacks/148688.htmlQ?Q原?
 (tng)当首ơ作InsertupdatedeleteselectӞC生的object在session关闭之前自动装载到sessionU别的缓存区Q如果,AP使用?jin)二U缓存,同样也会(x)装入CU缓存。所以当数据量大Ӟ׃(x)出现outofmemory情况?
 (tng)
Q?Q解x(chng)?
 (tng)
(A)扚w插入QBatch insertsQ?扚w更新QBatch updatesQ?
必须通过l常的调?Session session = sessionFactory.openSession(); Transaction tx = session.beginTransaction(); String hqlUpdate = "update Customer set name = :newName where name = :oldName"; int updatedEntities = s.createQuery( hqlUpdate ) .setString( "newName", newName ) .setString( "oldName", oldName ) .executeUpdate(); tx.commit(); session.close();
执行一个HQL Session session = sessionFactory.openSession(); Transaction tx = session.beginTransaction(); String hqlDelete = "delete Customer where name = :oldName"; int deletedEntities = s.createQuery( hqlDelete ) .setString( "oldName", oldName ) .executeUpdate(); tx.commit(); session.close();

leekiang 2007-09-27 14:22 发表评论
]]>
mant-to-one not-foundhttp://www.aygfsteel.com/leekiang/archive/2007/06/08/122947.htmlleekiangleekiangFri, 08 Jun 2007 14:48:00 GMThttp://www.aygfsteel.com/leekiang/archive/2007/06/08/122947.htmlhttp://www.aygfsteel.com/leekiang/comments/122947.htmlhttp://www.aygfsteel.com/leekiang/archive/2007/06/08/122947.html#Feedback0http://www.aygfsteel.com/leekiang/comments/commentRss/122947.htmlhttp://www.aygfsteel.com/leekiang/services/trackbacks/122947.htmlmant-to-one元素有一个属?not-found?br>用来指定引用的外键不存在时将如何处理Q?br>exceptionQ默认)(j)抛出异常
ignore 忽略
Hibernate采用默认的抛出异常来处?/span>

leekiang 2007-06-08 22:48 发表评论
]]>
摘录http://www.aygfsteel.com/leekiang/archive/2007/04/29/114590.htmlleekiangleekiangSun, 29 Apr 2007 07:55:00 GMThttp://www.aygfsteel.com/leekiang/archive/2007/04/29/114590.htmlhttp://www.aygfsteel.com/leekiang/comments/114590.htmlhttp://www.aygfsteel.com/leekiang/archive/2007/04/29/114590.html#Feedback0http://www.aygfsteel.com/leekiang/comments/commentRss/114590.htmlhttp://www.aygfsteel.com/leekiang/services/trackbacks/114590.html摘录?nbsp;http://www.javaeye.com/topic/73047?page=7
    在实际用Hibernate的例子中Q我比较們֐于用单个的POQPO的逻辑关系q序保证。当然这U设计不W合 Hibernate的思想Q不q我的目的是解决问题Q根据实际经验来看,q样做在目中更有实际h(hun)倹{我用Hibernate的目的只是不惛_那么多Jdbc操作Q我不打用他来装我的业务关系。我的业务逻辑体现是在数据库设计上体现。而程序开发的时候,表的关系是遵循模型设计开发,模型设计中会(x)强制要求开发h员必遵守模型的关系规则。虽然这P?x)在代码中有很多不雅的代码(比v在PO表达对象关系来说Q,但是我觉得更可控?/p>

leekiang 2007-04-29 15:55 发表评论
]]>
վ֩ģ壺 | | | ݳ| ̺| | | Զ| Զ| | Ұ| ͭ| | | | Ȫ| | | ʯ¥| ӱ| SHOW| | | | ʮ| | | â| | | ͼľ| | | | ʳ| Ϣ| տ| ȳ| | ӱ| |