I want to use QueryDSL with JDBC (Not JPA). So in pom.xml I put these dependencies and plugin:
<dependency> <groupId>com.mysema.querydsl</groupId> <artifactId>querydsl-core</artifactId> <version>3.7.4</version> </dependency> <dependency> <groupId>com.mysema.querydsl</groupId> <artifactId>querydsl-sql</artifactId> <version>3.7.4</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>1.6.1</version> </dependency> .... <plugins> <plugin> <groupId>com.mysema.querydsl</groupId> <artifactId>querydsl-maven-plugin</artifactId> <version>3.7.4</version> <executions> <execution> <goals> <goal>export</goal> </goals> </execution> </executions> <configuration> <jdbc.url>jdbc:mysql://localhost:8889/chebuoni</jdbc.url> <jdbc.driver>com.mysql.cj.jdbc.Driver</jdbc.driver> <jdbcUser>root</jdbcUser> <jdbcPassword>root</jdbcPassword> <packageName>it.group.myproject</packageName> <targetFolder>/target/generated-sources/java</targetFolder> </configuration> <dependencies> <dependency> <groupId>org.apache.derby</groupId> <artifactId>derby</artifactId> <version>10.13.1.1</version> </dependency> </dependencies> </plugin> </plugins> Maven can do its building without errors only if I out generic-export as goal, but in this case it does not create the Q class I need in order to use QueryDSL. I also have my class Person mapped with annotation @Entity in package it.group.myproject
********************** edit ********************** Following @Nikolas tips I was finally able to generate Q class, and I add in the pom this plugin:
<plugin> <groupId>com.querydsl</groupId> <artifactId>querydsl-maven-plugin</artifactId> <version>4.1.0</version> <configuration> <jdbc.url>jdbc:mysql://localhost:8889/myDB</jdbc.url> <jdbc.driver>com.mysql.cj.jdbc.Driver</jdbc.driver> <jdbc.user>root</jdbc.user> <jdbc.password>root</jdbc.password> <packageName>myPackage</packageName> <targetFolder>/target/generated-sources/java</targetFolder> <namePrefix>S</namePrefix> <imports> <import>java.io</import> <import>java.io.File</import> </imports> </configuration> <dependencies> <dependency> <groupId>org.apache.derby</groupId> <artifactId>derby</artifactId> <version>10.13.1.1</version> </dependency> </dependencies> </plugin> But still, there is the part of the entityManager that I don't know how to configure:
JPAQuery<?> queryFactory = new JPAQuery<Void>(entityManager); I read this tutorial --> https://examples.javacodegeeks.com/enterprise-java/jpa/jpa-entitymanager-example/ in which it seems I need a persistence.xml file so that I can do this:
EntityManagerFactory emf = Persistence.createEntityManagerFactory("jcg-JPA"); EntityManager em = emf.createEntityManager(); so I configured persistence and the entitymanager bean in this way:
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean"> <property name="persistenceUnitName" value="jcg-JPA" /> </bean> And this is persistence.xml
<?xml version="1.0" encoding="UTF-8"?> http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" version="2.0">
<persistence-unit name="jcg-JPA"> <provider>org.hibernate.ejb.HibernatePersistence</provider> <properties> <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" /> <property name="hibernate.hbm2ddl.auto" value="update" /> <property name="hibernate.connection.driver_class" value="com.mysql.cj.jdbc.Driver" /> <property name="hibernate.connection.username" value="root" /> <property name="hibernate.connection.password" value="root" /> <property name="hibernate.connection.url" value="jdbc:mysql://localhost:8889/myDB" /> </properties> </persistence-unit> But server fails at startup:
org.apache.catalina.core.StandardContext listenerStart GRAVE: Exception sending context initialized event to listener instance of class [org.springframework.web.context.ContextLoaderListener] java.lang.NoSuchMethodError: org.springframework.beans.factory.annotation.InjectionMetadata: method <init>()V not found at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.findPersistenceMetadata(PersistenceAnnotationBeanPostProcessor.java:351) at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessMergedBeanDefinition(PersistenceAnnotationBeanPostProcessor.java:295)