JPA Criteria Query distinct

I got it. The problem was my CriteraQuery needed to be of type String. This works: CriteriaBuilder builder = em.getCriteriaBuilder(); CriteriaQuery<String> query = builder.createQuery(String.class); Root<RuleVar> ruleVariableRoot = query.from(RuleVar.class); query.select(ruleVariableRoot.get(RuleVar_.varType)).distinct(true);

JPA OneToMany : List vs Set

I faced this problem not so long ago… I found this article: Performance Antipatterns of One To Many Association in Hibernate https://fedcsis.org/proceedings/2013/pliks/322.pdf in short: Bag semantics -> List / Collection + @OneToMany -> One Element Added: 1 delete, N inserts , One Element Removed: 1 delete, N inserts List semantics -> List + @OneToMany + … Read more

JPA Hibernate Persistence exception [PersistenceUnit: default] Unable to build Hibernate SessionFactory

The issue is that you are not able to get a connection to MYSQL database and hence it is throwing an error saying that cannot build a session factory. Please see the error below: Caused by: java.sql.SQLException: Access denied for user ”@’localhost’ (using password: NO) which points to username not getting populated. Please recheck system … Read more

How to use Spring Boot with MySQL database and JPA?

I created a project like you did. The structure looks like this The Classes are just copy pasted from yours. I changed the application.properties to this: spring.datasource.url=jdbc:mysql://localhost/testproject spring.datasource.username=root spring.datasource.password=root spring.datasource.driverClassName=com.mysql.jdbc.Driver spring.jpa.hibernate.ddl-auto=update But I think your problem is in your pom.xml: <?xml version=”1.0″ encoding=”UTF-8″?> <project xmlns=”http://maven.apache.org/POM/4.0.0″ xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation=”http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd”> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.4.1.RELEASE</version> </parent> <artifactId>spring-boot-sample-jpa</artifactId> … Read more

Tool to Execute JPQL Queries?

Until Eclipse Dali gets a generic JPQL editor you can use Hibernate Tools. Hibernate Tools works with Dali and provides a HQL/JPQL query editor which uses Hibernate to execute the queries. An alternative would be to use the JPA Query Tool [JQT], an Interactive JPA query editor and runner. It might be closer to what … Read more

JPA – create-if-not-exists entity?

I’d like to write a method like <T> T getOrCreate(Class<T> klass, Object primaryKey) This won’t be easy. A naive approach would be to do something like this (assuming the method is running inside a transaction): public <T> T findOrCreate(Class<T> entityClass, Object primaryKey) { T entity = em.find(entityClass, primaryKey); if ( entity != null ) { … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)