kundera icon indicating copy to clipboard operation
kundera copied to clipboard

Criteria API - support for EmbeddedId - cannot use Path<Entity> to access embedded key

Open AntonYudin opened this issue 7 years ago • 4 comments

It looks it is impossible to use Criteria API to query using EmbeddedId fields.

Root<Event> root = criteria.from(Event.class);
root.get(Event_.id).get(EvendId_.identity)

fails with a NullPointerException: Caused by: java.lang.NullPointerException at com.impetus.kundera.persistence.DefaultPath$PathCache.get(DefaultPath.java:285)

root.get("id").get("identity") fails with the following message: attribute of the given name and type is not present in the managed type, for name:identity at com.impetus.kundera.metadata.model.type.AbstractManagedType.checkForValid

Here are the entity and embedded key classes:

@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;
        }
}

It is possible to query using a regular JPA query: SELECT e FROM Event e WHERE e.id.identity = :p

Thanks.

AntonYudin avatar Jul 06 '17 23:07 AntonYudin

Hi @AntonYudin,

Please specify Kundera version, database name and version.

-Dev

devender-yadav avatar Jul 07 '17 09:07 devender-yadav

I'm using Kundera 3.8 and Cassandra 3.10.

AntonYudin avatar Jul 07 '17 13:07 AntonYudin

Hi @AntonYudin,

Are you still stuck with this issue?

-Dev

devender-yadav avatar Jul 31 '17 10:07 devender-yadav

I decided not to use kundera's Criteria API as it is not JPA compliant yet. I'm using JPQL instead, even though I prefer to use CriteriaAPI when I work with other JPA providers.

It seems kundera works well with very simple examples, but anything with Inheritance, CriteriaAPI, or embedded keys is not JPA compliant and requires some workarounds that make the code incompatible with other JPA providers.

I still like that most of the simple things work as expected and that kundera is able to generate and update schemas.

Thanks.

AntonYudin avatar Jul 31 '17 14:07 AntonYudin