Skip to content

Selecting only embeddedId property with JPQL fails #948

@AntonYudin

Description

@AntonYudin

The following JPQL query:

SELECT e.id.identity, e.id.type, e.id.created FROM Event e
gets translated into the following CQL:

SELECT "identity","type","created" FROM "events" LIMIT 100
But the returned List contains Event objects instead of arrays of Object
List<Object[]> list = query.getResultList();
The list is returned as a list of Event objects.

Another JPQL query that tries to get the whole key as an Object:
SELECT e.id FROM Event e
gets translated into the following CQL:
SELECT "id" FROM "events" LIMIT 100
and obviously fails because "id" is a compound/EmbeddedId field.

Here is the definition of the entity and the embedded class.

@Entity
@Table(name = "events")
@Inheritance(strategy = javax.persistence.InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "typed")
public class Event implements java.io.Serializable {

        @EmbeddedId
        @OrderBy("id.type ASC, id.created DESC")
        private EventId id;

        public EventId getId() {
                return id;
        }

        public void setId(final EventId value) {
                id = value;
        }
}
@Embeddable
public class EventId implements java.io.Serializable {


        @Column
        private java.util.UUID identity = null;

        public java.util.UUID getIdentity() {
                return identity;
        }

        public void setIdentity(final java.util.UUID value) {
                identity = value;
        }

        @Column
        private String type = null;

        public String getType() {
                return type;
        }

        public void setType(final String value) {
                type = value;
        }

        @Column
        private java.util.UUID created = null;

        public java.util.UUID getCreated() {
                return created;
        }

        public void setCreated(final java.util.UUID value) {
                created = value;
        }
}

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions