You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by "Daniele Pirola (JIRA)" <ji...@apache.org> on 2014/04/11 15:05:19 UTC
[jira] [Commented] (OPENJPA-2488) select with fixed column doesn't
run
[ https://issues.apache.org/jira/browse/OPENJPA-2488?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13966467#comment-13966467 ]
Daniele Pirola commented on OPENJPA-2488:
-----------------------------------------
I found a "dirty" workaround.
Mapping table Dual with the real column found in Oracle (named dummy) and then add this line to force the insert of the table name in the query
criteria.orderBy(builder.asc(root.get(Dual_.dummy)));
the query builded is
SELECT CURRENT_TIMESTAMP FROM Dual d ORDER BY d.dummy
not the optimal but it's work
> select with fixed column doesn't run
> ------------------------------------
>
> Key: OPENJPA-2488
> URL: https://issues.apache.org/jira/browse/OPENJPA-2488
> Project: OpenJPA
> Issue Type: Bug
> Affects Versions: 2.2.2
> Reporter: Daniele Pirola
>
> Suppose to have a mapped Entity named Dual and want to retrieve the sysdate from the db.
> If you try this code:
> Timestamp ts;
> CriteriaBuilder builder = entityManager.getCriteriaBuilder();
> CriteriaQuery<Timestamp> criteria = builder.createQuery(Timestamp.class);
> criteria.select(builder.currentTimestamp());
> criteria.from(Dual.class);
> ts =entityManager.createQuery(criteria).setMaxResults(1).getSingleResult();
> openjpa build a query like this:
> SELECT CURRENT_TIMESTAMP FROM WHERE ROWNUM <= ?
> without the table Dual specified.
> This is the Dual class but the error always happens with other real table:
> @Entity
> @Table(name = "DUAL")
> @Access(AccessType.FIELD)
> public class Dual implements Serializable {
> @Id
> @Column(name = "DATE_VALUE")
> @Temporal(TemporalType.TIMESTAMP)
> private Date date;
> public Date getDate() {
> return date;
> }
> public void setDate(Date date) {
> this.date = date;
> }
> }
--
This message was sent by Atlassian JIRA
(v6.2#6252)