Skip to content

No viable alternative at input SELECT new Entity(*) #3895

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
dev-ducu opened this issue May 20, 2025 · 2 comments
Open

No viable alternative at input SELECT new Entity(*) #3895

dev-ducu opened this issue May 20, 2025 · 2 comments
Labels
status: waiting-for-triage An issue we've not yet triaged

Comments

@dev-ducu
Copy link

I am seeing this error with spring-data 3.5.0:

INFO  [2025-05-19 17:36:30,602] [] [kafka-producer-network-thread | producer-2] org.apache.kafka.clients.producer.internals.TransactionManager: [Producer clientId=producer-2] ProducerId set to 1 with epoch 0
java.lang.IllegalArgumentException: org.hibernate.query.SyntaxException: At 1:50 and token ')', no viable alternative at input 'SELECT new com.adswizz.domain.entity.CampaignDeal(*) FROM CampaignDeal cd LEFT JOIN FETCH cd.dealLibrary d LEFT JOIN FETCH d.publisher p WHERE cd.campaignId = :campaignId' [SELECT new com.adswizz.domain.entity.CampaignDeal() FROM CampaignDeal cd LEFT JOIN FETCH cd.dealLibrary d LEFT JOIN FETCH d.publisher p WHERE cd.campaignId = :campaignId]

when running the following query:

@Query("SELECT cd FROM CampaignDeal cd "
            + "LEFT JOIN FETCH cd.dealLibrary d "
            + "LEFT JOIN FETCH d.publisher p "
            + "WHERE cd.campaignId = :campaignId")`
List<CampaignDeal> findCampaignDealsForCampaign(Integer campaignId);

The entity definition is:

@Entity
@Table(name = "campaign_deals")
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class CampaignDeal {

    @EmbeddedId
    private CampaignDealId campaignDealId;

    @Column(name = "campaign_id", insertable = false, updatable = false)
    private Integer campaignId;

    @Column(name = "deal_library_id")
    private Integer dealLibraryId;

    @ToString.Exclude
    @EqualsAndHashCode.Exclude
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "deal_library_id", updatable = false, insertable = false, referencedColumnName = "id")
    private Deal dealLibrary;

    @Column(name = "publisher_id")
    private Integer publisherId;

    @ToString.Exclude
    @EqualsAndHashCode.Exclude
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "publisher_id", updatable = false, referencedColumnName = "affiliateid", insertable = false)
    private Publisher publisher;

    @Column(name = "type")
    @Enumerated(EnumType.STRING)
    private Type type;

    @Embeddable
    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    @Builder
    public static class CampaignDealId implements Serializable {

        private static final long serialVersionUID = 5373763488252554888L;

        @ManyToOne(fetch = FetchType.LAZY, targetEntity = Campaign.class)
        @JoinColumn(name = "campaign_id")
        @ToString.Exclude
        @EqualsAndHashCode.Exclude
        private Campaign campaign;

        @Column(name = "deal_id") //the dealID string, not the fk to deal_library
        private String dealId;

    }

    public enum Type {
        STRING,
        LIBRARY
    }
}

This used to work just fine until upgrading to the 3.5.0 version.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label May 20, 2025
@cpy-xcend
Copy link

Same issue after upgrading from 3.5.0

@christophstrobl
Copy link
Member

thank you for reporting - we'll have a look

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

No branches or pull requests

4 participants