posts - 165, comments - 198, trackbacks - 0, articles - 1
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

hbn 笔记

Posted on 2007-08-09 14:30 G_G 阅读(381) 评论(3)  编辑  收藏 所属分类: hibernate


1.Criteria 的 or 

     public  List getFind(String[] dpids ) {
        Criteria cr 
=   getCriteriaBegin(Deptid. class );
        
        cr.add( Restrictions.or( 
                    Restrictions.eq(
" dpid " , dpids[ 0 ] ) , 
                    Restrictions.eq( 
" dpid "  ,dpids[ 1 ] ) )
                );
        
        
return  getCriteriaEnd(cr);
    }

2. 容器储存 (从表没主键) 1)Set  的 .xml
             引用  http://caterpillar.onlyfun.net/GossipCN/HibernateGossip/HibernateGossip.html
	<set name="emails" table="email">//email表 就 2列 id address
<key column="id"/> //email表的主键 也是主表的主键
  <element type="java.lang.String" column="address"/>
</set>
.java private Set emails; //存和外键同
2)List  的 .xml
<list name="items" table="item">
<key column="id"/> //为item表的 idINT(11) NOT NULL,
<index column="position"/> //为表的 position INT(11) NOT NULL,
<element type="java.lang.String" column="name"/>//为表的name VARCHAR(100) NOT NULL default ''
</list>
。。。。。
3. 列为对象
<set name="emails" table="email">
<key column="id"/>
<composite-element class="onlyfun.caterpillar.MailAddress">
<property name="address" column="address"/> //调用 getAddress()
</composite-element>
</set>



评论

# re: hbn 笔记  回复  更多评论   

2007-10-10 10:50 by G_G
源码分析
在 Factory中
private static final ThreadLocal threadLocal = new ThreadLocal();
的使用 可以参考
http://www.java3z.com/cwbwebhome/article/article2a/275.jsp?id=324

线程安全
Session session = (Session) threadLocal.get();
if (session == null) {
if (sessionFactory == null) {
try {
cfg.configure(CONFIG_FILE_LOCATION);
sessionFactory = cfg.buildSessionFactory();
}
catch (Exception e) {
System.err.println("%%%% Error Creating SessionFactory %%%%");
e.printStackTrace();
}
}
session = sessionFactory.openSession();
threadLocal.set(session);
}

return session;

# re: hbn 笔记  回复  更多评论   

2007-10-10 10:57 by G_G

hbn 加载文件

 ConfigHelper.getResourceAsStream
public static InputStream getResourceAsStream(String resource) {
String stripped
= resource.startsWith("/") ?
resource.substring(
1) : resource;

InputStream stream
=null;
ClassLoader classLoader
= Thread.currentThread().getContextClassLoader();
if (classLoader!=null) {
stream
= classLoader.getResourceAsStream( stripped );
}
if ( stream ==null ) {
Environment.
class.getResourceAsStream( resource );
}
if ( stream ==null ) {
stream
= Environment.class.getClassLoader().getResourceAsStream( stripped );
}
if ( stream ==null ) {
thrownew HibernateException( resource +" not found" );
}
return stream;
}

# re: hbn 笔记  回复  更多评论   

2007-10-12 16:21 by G_G
Configuration ->
//方法 doConfigure 有 dom4j用法
protected Configuration doConfigure(org.dom4j.Document doc)

只有注册用户登录后才能发表评论。


网站导航: