从带有左外连接的 SQL 到 JPQL 或本机 SQL
大家好,我的问题与将带有左连接的 Sql 之一转换为 jpa 和实体结构有关,但我在这里坚持的是我的 sql
SELECT * FROM X_TABLE LEFT OUTER JOIN Y_TABLE ON TO_CHAR (X_TABLE.TIME1, 'HH24:MI') = TO_CHAR (Y_TABLE.TIME1, 'HH24:MI') AND TO_DATE(Y_TABLE.DATE1) = TO_DATE('10/10/2010','dd/MM/yyyy') AND Y_TABLE.Z_TABLE_ID =X_TABLE.Z_TABLE_ID, Z_TABLE Where X_TABLE.Z_TABLE_ID =Z_TABLE.ID
Y_TABLE 具有 X_table 的外键 但是当我用这个sql查询时,X_TABLE没有Y_TABLE的外键, 我的 Y_TABLE 列将存储在哪里?
Y_TABLE 和 X_TABLE 之间的关系是 ManyToOne , 所以在 Y_TABLE 实体中我有 @ManyToOne X_TABLE 字段, 当我通过映射在 X_TABLE 中反向映射此关系时 我有一个 Y_TABLE 列表 当我查询这个sql时,我只得到一行有两个表列?
但在实体意义上我有一个 Y_TABLE 列表?
我如何获得一个实体中的所有返回列,我应该做什么?
谢谢大家 我们一直在工作的系统如下
eclipselink 2.0.1,Glassfish 3.0.1,JSF 2
Hiya all, my problem is related to converting one of the Sql with left join into jpa and entity structure, but i am stucked with it here is my sql
SELECT * FROM X_TABLE LEFT OUTER JOIN Y_TABLE ON TO_CHAR (X_TABLE.TIME1, 'HH24:MI') = TO_CHAR (Y_TABLE.TIME1, 'HH24:MI') AND TO_DATE(Y_TABLE.DATE1) = TO_DATE('10/10/2010','dd/MM/yyyy') AND Y_TABLE.Z_TABLE_ID =X_TABLE.Z_TABLE_ID, Z_TABLE Where X_TABLE.Z_TABLE_ID =Z_TABLE.ID
Y_TABLE has foreign key of X_table
but when i query with this sql , X_TABLE which has no foreign key of Y_TABLE ,
where will my columns of Y_TABLE be stored in?
the relationship between Y_TABLE and X_TABLE is ManyToOne ,
so in the Y_TABLE entity i have @ManyToOne X_TABLE field,
when i map inversely this relationship in X_TABLE via mapped
i am having a Y_TABLE list
when i query this sql i am getting just a row with two tables columns?
but in entity meaning i am having a list of Y_TABLE?
how i can get the all returning columns in one entity, what should i do for that?
thanx all
system we have been working like below
eclipselink 2.0.1,Glassfish 3.0.1,JSF 2
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的查询看起来很复杂。也许首先解释一下你的对象模型,你想要做什么,以及你想从查询中返回什么。
你的函数使用看起来很奇怪,为什么你想比较你的时间作为字符和你的字符作为日期?
如果您的数据库非常神秘,您可以考虑定义一个视图并映射到它。
Your query seems very complex. Perhaps start by explaining your object model, and what you are trying to do, and what you want back from your query.
Your function usage seems odd, why do you want to compare your times as chars and your chars as dates?
If your database is very cryptic, you may consider defining a view and mapping to it instead.