当我升级到java 11时,我的JPA命名查询无法编译

nbysray5  于 12个月前  发布在  Java
关注(0)|答案(1)|浏览(107)

我同样的JPQL查询在Java 8上工作,当我升级到Java 11时,它停止工作。我正在使用eclipselink实现。查询

<named-query name="XXDataHist.findLatestByObjectClassTypeAndObjectIdAndEventTime">

    <query>select obj from XXDataHist obj WHERE obj.objectId = :objectId AND
    obj.objectClassType = :classType AND
    obj.createTime &lt;= :createTime ORDER BY obj.id DESC</query>
</named-query>

它失败了,错误如下,

org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is 
javax.persistence.PersistenceException: Exception [EclipseLink-28019] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): 
org.eclipse.persistence.exceptions.EntityManagerSetupException|
Exception Description: Deployment of PersistenceUnit [defaultPU] failed.
Close all factories for this PersistenceUnit.|
Internal Exception: Exception [EclipseLink-0] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.JPQLException|
Exception Description: Problem compiling [select obj from XXDataHist obj where 
obj.objectId = :objectId and |             obj.objectClassType = :classType and |  
obj.createTime <= :createTime ORDER BY obj.id DESC]. |[16, 26] 
The abstract schema type 'XXDataHist' is unknown.
|[37, 49] The state field path 'obj.objectId' cannot be resolved to a valid type.
|[66, 85] The state field path 'obj.objectClassType' cannot be resolved to a valid type.
|[103, 117] The state field path 'obj.createTime' cannot be resolved to a valid type.
|[142, 148] The state field path 'obj.id' cannot be resolved to a valid type.

实体类:

@Entity
@Cacheable
@XmlRootElement
@Table(name = "x_data_hist")
public class XXDataHist implements java.io.Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @SequenceGenerator(name = "x_data_hist_SEQ", sequenceName = "x_data_hist_SEQ", allocationSize = 1)
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "x_data_hist_SEQ")
    @Column(name = "id")
    protected Long id;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "CREATE_TIME")
    protected Date createTime = DateUtil.getUTCDate();

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "UPDATE_TIME")
    protected Date updateTime = DateUtil.getUTCDate();

    @Column(name = "version")
    protected Long version;

    @Column(name = "obj_guid")
    protected String objectGuid;

    @Column(name = "obj_class_type")
    protected Integer objectClassType;

    @Column(name = "obj_id")
    protected Long objectId;

    @Column(name = "obj_name")
    protected String objectName;

    
    @Column(name = "action")
    protected String action;

    
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "from_time")
    protected Date fromTime;

    
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "to_time")
    protected Date toTime;

    
    @Column(name = "content")
    protected String content;

//constructor equals toString , getters and setters 
}

我只是想知道为什么它在Java 8中工作正常,而在Java 11中失败,我需要修复这个查询,如果它有任何问题,在Java 8中允许,但在Java 11中不允许。

相关问题