JPA support for Java 8 new date and time API

For Hibernate 5.X just add <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-java8</artifactId> <version>${hibernate.version}</version> </dependency> and @NotNull @Column(name = “date_time”, nullable = false) protected LocalDateTime dateTime; will work without any additional effort. See https://hibernate.atlassian.net/browse/HHH-8844 UPDATE: Please have a look at Jeff Morin comment: since Hibernate 5.2.x it is enough <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId> <version>5.2.1.Final</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-…</artifactId> <version>4.3.1.RELEASE</version> </dependency> See … Read more

How to specify JPA 2.1 in persistence.xml?

According to the official documentation it must be (like yours): <persistence xmlns=”http://xmlns.jcp.org/xml/ns/persistence” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation=”http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd” version=”2.1″> … </persistence>

JPA Query selecting only specific columns without using Criteria Query?

Yes, like in plain sql you could specify what kind of properties you want to select: SELECT i.firstProperty, i.secondProperty FROM ObjectName i WHERE i.id=10 Executing this query will return a list of Object[], where each array contains the selected properties of one object. Another way is to wrap the selected properties in a custom object … Read more

org.hibernate.QueryException: illegal attempt to dereference collection

billProductSet is a Collection. As such, it does not have an attribute named product. Product is an attribute of the elements of this Collection. You can fix the issue by joining the collection instead of dereferencing it: SELECT count(*) FROM BillDetails bd JOIN bd.billProductSet bps WHERE bd.client.id = 1 AND bps.product.id = 1002