SQLQueryFactory.insert() requires a RelationalPath

1,213 views
Skip to first unread message

Volkan Yazıcı

unread,
Jul 8, 2015, 2:19:26 PM7/8/15
to quer...@googlegroups.com
Hello,

In the reference manual, it is stated that the following snippet should work:

QSurvey survey = QSurvey.survey;
SQLQueryFactory queryFactory = new SQLQueryFactory(configuration, dataSource);
queryFactory.insert(survey)
    .columns(survey.id, survey.name)
    .values(3, "Hello").execute();


That is, insert needs a parameter of type RelationalPath. However, the generated query types (e.g. QSurvey) does not implement RelationalPath, but EntityPathBase. Hence, insert() statement fails to compile. What might I be missing?

Best.

Used pom.xml is as follows:

<properties>
    <javax.persistence.api.version>2.1.0</javax.persistence.api.version>
    <querydsl.version>4.0.2</querydsl.version>
    <slf4j.log4j12.version>1.6.1</slf4j.log4j12.version>
    <slf4j.api.version>1.7.12</slf4j.api.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.eclipse.persistence</groupId>
        <artifactId>javax.persistence</artifactId>
        <version>${javax.persistence.api.version}</version>
    </dependency>
    <dependency>
        <groupId>com.querydsl</groupId>
        <artifactId>querydsl-sql</artifactId>
        <version>${querydsl.version}</version>
    </dependency>
    <dependency>
        <groupId>com.querydsl</groupId>
        <artifactId>querydsl-apt</artifactId>
        <version>${querydsl.version}</version>
    </dependency>
    <dependency>
        <groupId>org.hsqldb</groupId>
        <artifactId>hsqldb</artifactId>
        <version>2.3.3</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>${slf4j.api.version}</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>${slf4j.log4j12.version}</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>com.mysema.maven</groupId>
            <artifactId>apt-maven-plugin</artifactId>
            <version>1.1.3</version>
            <executions>
                <execution>
                    <goals>
                        <goal>process</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>target/generated-sources/java</outputDirectory>
                        <processor>com.querydsl.apt.jpa.JPAAnnotationProcessor</processor>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

Ruben Dijkstra

unread,
Jul 8, 2015, 2:25:31 PM7/8/15
to Querydsl on behalf of Marvin Froeder
Hello,

You seem to have mixed the SQL related SQLQueryFactory with JPA entity query objects (EntityPathBase).

Using JPAQueryFactory should do the trick, but as I see you depend on querydsl-sql, you should swap out the apt-maven-plugin for the maven plugin that is used for database metadata reverse engineering.


I hope this is of use.

Best regards,

Ruben Dijkstra
--
You received this message because you are subscribed to the Google Groups "Querydsl" group.
To unsubscribe from this group and stop receiving emails from it, send an email to querydsl+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Roy Jacobs

unread,
Jul 10, 2015, 9:42:44 AM7/10/15
to quer...@googlegroups.com
Is there a way to combine the two? Currently, generating a metamodel from JDBC requires a database during the build process whereas generating the metamodel based on JPA annotations does not. The latter is quite convenient for this reason.

However, during runtime it would be preferable to use 'raw' JDBC because we'd like to avoid the additional complexity of a system like Hibernate.

With regards,
Roy

timowest

unread,
Jul 20, 2015, 2:33:13 PM7/20/15
to quer...@googlegroups.com
You can for example populate an in memory database using JPA and export the schema afterwards for Querydsl SQL usage.

Uk Jo

unread,
Sep 9, 2015, 2:47:48 PM9/9/15
to Querydsl
Can you do give more elaborate explanation about your answer?

Actually, Like Roy Jacobs said, I want to combine the two or want to find the way without giving a specific datasource in maven plugin. And I am worried about that there is changes that make compile errors whenever I change the jdbc connection information. Is there other way to insert data with JPA? I wasted a lot of time finding the way to insert data in jpa but I couldn't. There are only things about Querydsl SQL.

2015년 7월 21일 화요일 오전 3시 33분 13초 UTC+9, timowest 님의 말:

timowest

unread,
Sep 9, 2015, 3:05:34 PM9/9/15
to Querydsl
You can also put your domain model to version control and update it on demand. For example write a test that ensures that the model in version control matches the one that is generated from JDBC.

What were your issues with insertions and JPA?
Reply all
Reply to author
Forward
0 new messages