Rising Sun

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  148 随笔 :: 0 文章 :: 22 评论 :: 0 Trackbacks

1问题: hibernate不用外键作查询:
1.1最终解办法: 利用hibernate 的视图功能
Hibernate3增加了视图功能

1. 定义hbm

    <class name="Customer" table="customer">        
        
<id name="id" unsaved-value="0" column="id">
            
<generator class="hilo"/>
        
</id>        
        
<property name="name"  not-null="true"/>        
    
</class>
    
    
<class name="Supplier" table="supplier">        
        
<id name="id" unsaved-value="0" column="id">
            
<generator class="hilo"/>
        
</id>
        
<property name="name" not-null="true"/>            
    
</class>
    
    
<class name="All" mutable="false">    
        <subselect>
            select id, name from customer
            union 
            select id, name from supplier
        
</subselect>
        
        
<synchronize table="customer"/>
        
<synchronize table="supplier"/>
        
        
<id name="id" unsaved-value="0" column="id">
            
<generator class="hilo"/>
        
</id>        
        
<property name="name"/>        
    
</class>


2. 定义POJO

pulic class Customer {
    
public Integer id;
    
public String name;
}


pulic 
class Supplier {
    
public Integer id;
    
public String name;
}


pulic 
class All {
    
public Integer id;
    
public String name;
}


3. 查询

List all = session.createQuery("from All").list();
注意:黄色地区


解决办法二

1.2 在数据表里 建视图, 把视图当表操作.

解决办法三
1.3 设外键=没说,,哈哈

总结,不用外键.为了建表方便.  

To Be Continued……



posted on 2007-09-04 11:02 brock 阅读(296) 评论(0)  编辑  收藏 所属分类: hibernate+struts+spring

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


网站导航: