Skip to content

Take @Table/@Column annotations into account in JPA native queries #926

Closed

Description

@johnktims

I'm generating Q classes from JPA entities using the maven JPAAnnotationProcessor. Normally, I use JPAQuery and everything works but I needed to UNION two queries so I tried to use JPASQLQuery.

Entities with names that map directly to its corresponding table work fine but if it's different then the "table is not found".

Example:

@Table(name="user")
class User

works fine but

@Table(name="other_user")
class User

will still try to generate SQL that refers to a table named User and fail.

Activity

  1. added this to the 3.5.0 milestone on Sep 7, 2014
  2. timowest commented on Sep 30, 2014

    @timowest
    Member

    Released in 3.5.0

  3. schragmanuel commented on Nov 17, 2015

    @schragmanuel

    I'm seeing a problem related to this in Version 3.6.9:

    My entity has a many to one relation to another entity:

    @javax.persistence.ManyToOne(targetEntity = ch.ims.suisdata.core.model.address.Address.class)
    @javax.persistence.JoinColumn(name = "NADR_ID", nullable = true, updatable = false, insertable = false)
    private Address address;
    

    When i try to do a join, the on part is not mapped to the foreign key column:

    new JPASQLQuery(em, new OracleTemplates()).from(qEntity).leftJoin(qAddress).on(qEntity.address.eq(qAddress.));
    

    This results in the query:

    select ... left join ADRESSEN address on errorView.address = address
    

    but it should be

    select ... left join ADRESSEN address on errorView.NADR_ID = address.NID
    

    I'm not sure if I do something wrong in the syntax of the query or if it's a QueryDsl issue.

  4. viaco2ove commented on Oct 21, 2021

    @viaco2ove

    I'm seeing the same problem related to this in Version 4.40:

    Then I found the problem,need this dependency

    <dependency>
            <groupId>com.querydsl</groupId>
            <artifactId>querydsl-sql</artifactId>
            <version>${querydsl.version}</version>
        </dependency>
    

    spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions