Dave
Dave

Reputation: 19260

How do I include JPA 2.1 functionality in my Maven project?

I’m using Maven 3, JPA 2.1, and Hibernate 4.3.5.Final. I want to use JPA 2.1 because it offers several features, most notably adding conditions to left outer join clauses. I have included the following dependencies in my Maven project …

    <dependency>
        <groupId>org.hibernate.javax.persistence</groupId>
        <artifactId>hibernate-jpa-2.1-api</artifactId>
        <version>1.0.0.Final</version>
    </dependency>   
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
        <version>4.3.2.Final</version>
        <exclusions>
            <exclusion>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-api</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>4.3.6.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-ehcache</artifactId>
        <version>4.3.6.Final</version>
    </dependency>

However, when I try and compile the following, I get a compilation error (“cannot find symbol”) on the “.on(“ clause.

    final CriteriaBuilder cb = m_entityManager.getCriteriaBuilder();
    CriteriaQuery<Message> query = cb.createQuery(Message.class);
    Root<Message> messageRoot = query.from(Message.class);
    final Join<Message, Group> groupJoin = messageRoot.join(Message_.group);
    final Join<Message, MessageReadDate> msgReadDateJoin = messageRoot.join(Message_.messageReads, JoinType.LEFT);
    msgReadDateJoin.on(msgReadDateJoin.get(MessageReadDate_.recipient), recipient);

What libraries do I need to include in my Maven project to get JPA 2.1 and hence the “join.on” functionality?

Upvotes: 3

Views: 12486

Answers (1)

Zeus
Zeus

Reputation: 6566

It could be a maven issue. Usually happens if the jars that it downloaded are corrupted for some reason. Delete the .m2 folder repository and do mvn install again, it should bring all the enw jars and compilation should work.

m2 folder here

Upvotes: 1

Related Questions