SELECT e.EE_ESERVICE_ID,
CASE
WHEN EXISTS
(SELECT 1
FROM WORKFLOWS w
WHERE w.WORKFLOW_ID = e.WORKFLOW_ID)
THEN
(SELECT i.I18ND_TRANSLATION
FROM WORKFLOWS w, I18N_DICTIONARY i
WHERE WORKFLOW_ID = e.WORKFLOW_ID
AND i.I18N_ID = w.WORKFLOW_NAME
AND i.I18N_LOCALE_ID = 1)
ELSE
COALESCE ('', '')
END
AS WORKFLOW_NAME
FROM ESERVICES e
StringBuffer hql = new StringBuffer("select e.eserviceId as eserviceId,"
+ " (case when exists(select 1 from Workflow w where w.workflowId = e.workflowId)"
+ " then (select i.i18ndTranslation from Workflow w,I18nDictionary i where w.workflowId = e.workflowId and i.i18nId = w.workflowName and i.i18nLocaleId = :localeId)"
+ " else coalesce('', '') end) as workflowName"
+ " from Eservice as e");
我知道我们可以直接从左连接实现它,但由于一些限制,我们使用交叉连接,所以我需要走这条路...
请分享您的想法,欢迎提出建议
更新1我们没有使用关联,这就是为什么我们严格交叉连接。
@Entity
@Table(name = "ESERVICES")
public class Eservice implements java.io.Serializable {
private static final long serialVersionUID = -4088905661029802626L;
public Eservice() {}
@Id
@SequenceGenerator(name = "escSequence", sequenceName = "SQ_ESERVICES",allocationSize=1)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "escSequence")
@Column(name = "EE_ESERVICE_ID", unique = true, nullable = false)
private BigDecimal eserviceId;
@Column(name = "WORKFLOW_ID")
private BigDecimal workflowId;
@Transient
private String workflowName;
// setter and getter
}
@Entity
@Table(name = "WORKFLOWS")
public class Workflow implements java.io.Serializable {
private static final long serialVersionUID = -4863237070153860617L;
public Workflow() {}
@Id
@SequenceGenerator(name = "wfSequence", sequenceName="SQ_WORKFLOWS", allocationSize=1)
@GeneratedValue(strategy=GenerationType.SEQUENCE , generator = "wfSequence")
@Column(name = "WORKFLOW_ID", unique = true, nullable = false)
private BigDecimal workflowId;
@Column(name = "I18N_WORKFLOW_NAME")
private BigDecimal workflowName;
// setter and getter
}
@Entity
@Table(name="I18N_DICTIONARY")
@Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
public class I18nDictionary implements Serializable{
/**
* The serialization runtime associates with each serializable class a version number called serialVersionUID.
*/
private static final long serialVersionUID = -2587075034303056842L;
@Id
@SequenceGenerator(name = "seqDictGenerator", sequenceName = "SQ_I18N_DICTIONARY",allocationSize=1)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seqDictGenerator")
@Column(name="I18N_DICT_ID", unique = true, nullable = false)
private BigDecimal i18nDictId;
@Column(name="I18N_ID")
private BigDecimal i18nId;
@Column(name="I18ND_TRANSLATION")
private String i18ndTranslation;
@Column(name="I18N_LOCALE_ID")
private BigDecimal i18nLocaleId;
// setter and getter
}
Query query = getSession()
.createQuery(hql.toString().trim())
.setBigDecimal("localeId", i18nLocale.getI18nLocaleId())
.setResultTransformer(Transformers.aliasToBean(Eservice.class));
List<Eservice> resultSet = query.list();
对我来说,你可以试试这个:
select e.eserviceId as eserviceId,
case
when e.workflowId is null then ''
else
(select i.i18ndTranslation from Workflow w,I18nDictionary i
where w.workflowId = e.workflowId
and i.i18nId = w.workflowName and i.i18nLocaleId = :localeId)
end as workflowName
from Eservice as e
编辑
试试这个:
String hql =
"select " + new Eservice.class.getName() +
"(e.eserviceId, " +
"case " +
" when e.workflowId is null then '' " +
" else " +
" (select i.i18ndTranslation from Workflow w,I18nDictionary i " +
" where w.workflowId = e.workflowId " +
" and i.i18nId = w.workflowName and i.i18nLocaleId = :localeId) " +
"end)" +
" from Eservice as e "
public Eservice(BigDecimal eserviceId, String workflowName) {
this.eserviceId = eserviceId;
this.workflowName = workflowName;
}
Query query = getSession().createQuery(hql.toString().trim())
.setBigDecimal("localeId", i18nLocale.getI18nLocaleId());
List<Eservice> resultSet = (List<Eservice>)query.list();
问题内容: 我正在使用multer npm模块将文件上传到我的应用程序。 我定义的multer功能是允许将一个文件上传到文件系统。运行期间一切正常;问题是我上传文件后出现以下错误。任何建议赞赏在哪里看。 app.js 索引库 问题答案: 我们必须确保具有name属性的type =文件应与传入的参数名称相同
我正在使用multer npm模块将文件上传到我的应用程序。 我定义的multer功能是允许将单个文件上载到文件系统。一切都在运行时工作;问题是在我上传文件后,我在下面遇到了一个错误。任何关于去哪里看的建议都很感激。
问题内容: 我已经开始研究 Node JS了 。 这是我的文件。 index.html app.js webpack.config.js 更新 bundle.js 因此,当我点击一个 app.js 并访问地址(localhost:3000)时,我在控制台中得到了错误。 bundle.js:1未捕获的SyntaxError:意外的令牌< 另外我的JS文件没有运行。有人可以建议一些解决办法吗? 提前致
我试图使用Spring Data进行查询,但我无法使其工作: 堆栈跟踪: 原因:java。lang.IllegalArgumentException:org。冬眠hql。内部的ast。QuerySyntaxException:意外的AST节点:第1行第49列附近的CASE[从Thing t中选择t,其中name LIKE:name和CASE WHEN(:minVal 原因:组织。冬眠hql。内部的
问题内容: 我不明白怎么了。我在其他论坛上讨论了翻译和通天塔。我需要做什么? 我的代码: 和错误 问题答案: ES6导入是最近引入的功能,并且Node的当前稳定版本尚不支持它们。Node.js问题跟踪器对此存在一个未解决的问题 -但在V8和Node添加对此功能的支持之前,您将需要使用编译器(最受欢迎的是babel)才能使用导入。 为了快速尝试转译,babel提供了基于Web的REPL。这段演示了您