Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » JPQL queries that worked in 2.6.4 don't work anymore in 2.7.0
JPQL queries that worked in 2.6.4 don't work anymore in 2.7.0 [message #1787013] Thu, 17 May 2018 10:29
Mario Koehler is currently offline Mario KoehlerFriend
Messages: 1
Registered: May 2018
Junior Member
We have an application that is running fine on Payara 4 with EclipseLink 2.6.4, but since we upgraded to Payara 5 and EclipseLink 2.7.0 we noticed that several of our named JPQL queries are no longer working and throw similar exceptions.

One example query looks like this:

SELECT an FROM ScoreCardFinder scf JOIN scf.assignmentNo an WHERE an.name=:name AND an.company=:company AND scf.scoreCard=:scoreCard


and throws the following exception:

Caused by: javax.persistence.PersistenceException: Exception [EclipseLink-26] (Eclipse Persistence Services - 2.7.0.v20170811-d680af5): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: Trying to get value for instance variable [id] of type [java.lang.Short] from the object [de.otto.cccs.customerscoring_common.entities.AssignmentNo].  The specified object is not an instance of the class or interface declaring the underlying field.
Internal Exception: java.lang.IllegalArgumentException: Can not set java.lang.Short field de.otto.cccs.customerscoring_common.entities.ScoreCardFinder.id to de.otto.cccs.customerscoring_common.entities.AssignmentNo
Mapping: org.eclipse.persistence.mappings.DirectToFieldMapping[id-->SCORECARDFINDER.ID]
Descriptor: RelationalDescriptor(de.otto.cccs.customerscoring_common.entities.ScoreCardFinder --> [DatabaseTable(SCORECARDFINDER)])
        at org.eclipse.persistence.internal.jpa.QueryImpl.getResultList(QueryImpl.java:491)
        at com.sun.enterprise.container.common.impl.QueryWrapper.getResultList(QueryWrapper.java:84)
        at de.otto.cccs.customerscoring_common.entities.repos.AssignmentNoRepository.findByNameAndCompanyAndScoreCard(AssignmentNoRepository.java:34)


It looks to me like EclipseLink somehow gets confused about the types of the ID field and confuses the two sides of the join, because the ID of ScoreCardFinder is of type Short whereas the ID of AssignmentNo is of type Integer.

The exception seems to imply that EclipseLink tries to get the variable [id] of type Short from the AssignmentNo entity. But that makes no sense, either it should try to get an Integer from AssignmentNo or a Short from ScoreCardFinder.

any hint to what is going on here would be greatly appreciated.

thanks in advance!

regards,
Mario

for reference i'll attach the source of the two entities below.

ScoreCardFinder:

package de.otto.cccs.customerscoring_common.entities;

import java.io.Serializable;
import java.util.Collection;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.QueryHint;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import javax.xml.bind.annotation.XmlTransient;

import org.eclipse.persistence.annotations.Cache;
import org.eclipse.persistence.annotations.CacheType;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.ToString;

@Entity
@Data
@EqualsAndHashCode(of = "id", callSuper=false)
@NoArgsConstructor
@RequiredArgsConstructor
@SequenceGenerator(name="SEQ_ScorecardFinder", initialValue=10, allocationSize=1)
@Cache(type=CacheType.FULL, size=250)
@Table(uniqueConstraints={
        @UniqueConstraint(columnNames = {"SCORINGVARIANT_ID", "ASSIGNMENTNO_ID"})
    }) 
@NamedQueries({
    @NamedQuery(name="ScoreCardFinder.findOne",
            query="SELECT scf FROM ScoreCardFinder AS scf WHERE scf.id=:id",
            hints={
                    @QueryHint(name="eclipselink.query-results-cache", value="true"),
                    @QueryHint(name="eclipselink.query-results-cache.size", value="250")
            }
    ),
    @NamedQuery(name="ScoreCardFinder.findByAssignmentNo",
        query="SELECT scf FROM ScoreCardFinder AS scf WHERE scf.assignmentNo=:assignmentNo",
        hints={
                @QueryHint(name="eclipselink.query-results-cache", value="true"),
                @QueryHint(name="eclipselink.query-results-cache.size", value="250")
        }
    ),
    @NamedQuery(name="ScoreCardFinder.findBy",
            query="SELECT scf "
                    + "FROM ScoreCardFinder AS scf "
                    + "JOIN scf.assignmentNo an "
                    + "JOIN an.assignmentNoFinders anf "
                    + "JOIN an.company c "
                    + "WHERE c.name=:companyName "
                    + "AND (:activationChannel=an.activationChannel OR an.activationChannel IS NULL) "
                    + "AND (anf.recruitmentCode=:recruitmentCode OR anf.recruitmentCode IS NULL) "
                    + "AND (anf.prospectRecruitmentCode=:prospectRecruitmentCode OR anf.prospectRecruitmentCode IS NULL) "
                    + "AND (:shopDomain=anf.shopDomain OR anf.shopDomain IS NULL) "
                    + "AND (:deviceType=anf.clientDeviceType OR anf.clientDeviceType IS NULL) "
                    + "AND anf.validFrom <= :now "
                    + "AND (anf.disableOn IS NULL OR anf.disableOn > :now) "
                    + "ORDER BY an.activationChannel DESC, anf.recruitmentCode DESC, anf.prospectRecruitmentCode DESC, anf.shopDomain DESC, anf.clientDeviceType DESC, anf.validFrom DESC"
                    ,

            hints={
                    @QueryHint(name="eclipselink.query-results-cache", value="true"),
                    @QueryHint(name="eclipselink.query-results-cache.size", value="250")
            }
    ),
    @NamedQuery(name="ScoreCardFinder.findByCompany",
        query="SELECT scf "
                + "FROM ScoreCardFinder AS scf "
                + "JOIN scf.assignmentNo an "
                + "JOIN an.assignmentNoFinders anf "
                + "WHERE an.company=:company "
                + "ORDER BY an.activationChannel, anf.recruitmentCode, anf.prospectRecruitmentCode, anf.validFrom DESC",

        hints={
                @QueryHint(name="eclipselink.query-results-cache", value="true"),
                @QueryHint(name="eclipselink.query-results-cache.size", value="250")
        }
    ),
    @NamedQuery(name="ScoreCardFinder.findByScoreCard",
        query="SELECT scf FROM ScoreCardFinder AS scf WHERE scf.scoreCard=:scoreCard",

        hints={
                @QueryHint(name="eclipselink.query-results-cache", value="true"),
                @QueryHint(name="eclipselink.query-results-cache.size", value="20")
        }
    )
})

@ToString(exclude={"custScoringResults","valueFinderSchedules"})
public class ScoreCardFinder extends CustomerScoringEntity implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @Column(length=4, nullable=false, updatable=false)
    @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="SEQ_ScorecardFinder")
    private Short id;

    @NonNull
    @ManyToOne(optional=false, cascade = CascadeType.PERSIST)
    private ScoreCard scoreCard;

    @NonNull
    @ManyToOne(optional=false)
    private AssignmentNo assignmentNo;

    @NonNull
    @ManyToOne(optional=false, cascade = CascadeType.PERSIST)
    private ScoringVariant scoringVariant;

    @OneToMany(mappedBy="scorecardFinder")
    private Collection<CustScoringResult> custScoringResults;

    @XmlTransient
    @ApiModelProperty(hidden=true)
    public Collection<CustScoringResult> getCustScoringResults() {
        return custScoringResults;
    }

    @OneToMany(mappedBy="scoreCardFinder")
    private Collection<ValueFinderSchedule> valueFinderSchedules;

    @XmlTransient
    @ApiModelProperty(hidden=true)
    public Collection<ValueFinderSchedule> getValueFinderSchedules() {
        return valueFinderSchedules;
    }

}


AssignmentNo:

package de.otto.cccs.customerscoring_common.entities;

import java.io.Serializable;
import java.util.Collection;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.QueryHint;
import javax.persistence.SequenceGenerator;
import javax.xml.bind.annotation.XmlTransient;

import org.eclipse.persistence.annotations.Cache;
import org.eclipse.persistence.annotations.CacheType;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.ToString;

@Entity
@Data
@EqualsAndHashCode(of = "id", callSuper=false)
@NoArgsConstructor
@RequiredArgsConstructor
@SequenceGenerator(name="SEQ_AssignmentNo", initialValue=10, allocationSize=1)
@Cache(type=CacheType.FULL, size=150)
@ToString(exclude={"assignmentNoFinders","scoreCardFinders"})
@NamedQueries({
    @NamedQuery(name="AssignmentNo.findOne",
            query="SELECT an FROM AssignmentNo AS an WHERE an.id=:id",
            hints={
                    @QueryHint(name="eclipselink.query-results-cache", value="true"),
                    @QueryHint(name="eclipselink.query-results-cache.size", value="100")
            }
    ),
    @NamedQuery(name="AssignmentNo.findByCompanyAndName",
                query="SELECT an FROM AssignmentNo AS an WHERE (:company IS NULL OR an.company=:company) AND (:name IS NULL OR an.name=:name)",
                hints={
                        @QueryHint(name="eclipselink.query-results-cache", value="true"),
                        @QueryHint(name="eclipselink.query-results-cache.size", value="50")
                }
    ),
    @NamedQuery(name="AssignmentNo.findByNameAndCompanyAndScoreCard",
        query="SELECT an FROM ScoreCardFinder scf JOIN scf.assignmentNo an WHERE an.name=:name AND an.company=:company AND scf.scoreCard=:scoreCard",
        hints={
                @QueryHint(name="eclipselink.query-results-cache", value="true"),
                @QueryHint(name="eclipselink.query-results-cache.size", value="50")
        }
    ),
    @NamedQuery(name="AssignmentNo.findAll",
                query="SELECT an FROM AssignmentNo AS an",
                hints={
                        @QueryHint(name="eclipselink.query-results-cache", value="true"),
                        @QueryHint(name="eclipselink.query-results-cache.size", value="1")
                }
    ),
})
public class AssignmentNo extends CustomerScoringEntity implements Serializable {

    private static final long serialVersionUID = 1L;

    public AssignmentNo(String name, ActivationChannel activationChannel, Company company) {
        super();
        if (name == null) throw new NullPointerException("name");
        this.name = name;
        this.activationChannel = activationChannel;
        if (company == null) throw new NullPointerException("company");
        this.company = company;
    }

    @Id
    @Column(length=6, nullable=false, updatable=false)
    @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="SEQ_AssignmentNo")
    private Integer id;

    @NonNull
    @Column(length = 50, nullable=false)
    private String name;

    @ManyToOne(optional=true, cascade = CascadeType.PERSIST)
    private ActivationChannel activationChannel;

    @NonNull
    @ManyToOne(optional=false)
    private Company company;

    @OneToMany(mappedBy="assignmentNo")
    private Collection<AssignmentNoFinder> assignmentNoFinders;

    @XmlTransient
    @ApiModelProperty(hidden=true)
    public Collection<AssignmentNoFinder> getAssignmentNoFinders() {
        return assignmentNoFinders;
    }

    @OneToMany(mappedBy="assignmentNo")
    private Collection<ScoreCardFinder> scoreCardFinders;

    @XmlTransient
    @ApiModelProperty(hidden=true)
    public Collection<ScoreCardFinder> getScoreCardFinders() {
        return scoreCardFinders;
    }
}
Previous Topic:joinTransaction() opens transaction?
Next Topic:Problem while doing Multithreading and using EntityManager
Goto Forum:
  


Current Time: Sun Nov 18 05:28:47 GMT 2018

Powered by FUDForum. Page generated in 0.01629 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top