首页 新闻 会员 周边

@Formula 问题,请大神给看看那

0
悬赏园豆:20 [已解决问题] 解决于 2019-12-20 11:07
public class A implements Serializable
{
    private static final long serialVersionUID = 1L;
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Long id;
    
    @Formula(value = "(select cs.bid  from B cs where cs.id=id and      cs.bid=? )")
    @JsonIgnore
    private Long bid;
  .......

 

字段bid 是B表的 ,所以我在 A表 建立了一个虚拟列 ,可以根据 这个字段做查询.

我是想 如何 将 bid     传到

@Formula(value = "(select cs.bid  from B cs where cs.id=id and      cs.bid=? )") 问号的地方

这里来 作为一个条件 ,然后可以查询?  不知大神们 有什么建议 或者好的方法

萤火虫的春天的主页 萤火虫的春天 | 初学一级 | 园豆:186
提问于:2014-08-14 10:40
< >
分享
最佳答案
0

参考Hibernate Parameter Binding Examples:

String hql = "from Stock s where s.stockCode = ? and s.stockName = ?";
List result = session.createQuery(hql)
.setString(0, "7277")
.setParameter(1, "DIALOG")
.list();
收获园豆:10
dudu | 高人七级 |园豆:30994 | 2014-08-14 10:50

关键是,我这里 做查询的时候 使用的 JPA .

就是直接把 查询条件 放到封装好的function ,不能自己写SQL语句,所以 就不能像你那样写了

萤火虫的春天 | 园豆:186 (初学一级) | 2014-08-14 10:58
其他回答(1)
0

在@Formula Sql中 已经有了 cs.id=id 这个条件 其实已经和A关联了,那 cs.bid这个自身字段可以不用了。

收获园豆:10
god bless you | 园豆:218 (菜鸟二级) | 2014-08-26 10:45
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册