引起:java.sql.SQLSyntaxErrorException:ORA-01722:JPA HIBERNATE HQL中的无效数字

时间:2015-01-16 08:27:18

标签: java spring oracle hibernate jpa

有这个课程

    @Entity
    public class PriorityAreaKeyword {

        public enum PriorityAreaKey {

            ALL     ("ALL",    "ALL DEVICES"),
            IOS     ("IOS",    "IOS"),
            ANDROID ("ANDROID","ANDROID");

            private final String name;

            private final String id;

            private PriorityAreaKey(String name, String id) {
                this.name = name;
                this.id = id;
            }

            public String getName() {
                return name;
            }

            public String getId() {
                return id;
            }
        }

        @Id
        private Long id;

        @Column(name = "key")
        @Enumerated(EnumType.STRING)
        private PriorityAreaKey key;


        public Long getId() {
            return id;
        }

        public void setId(Long id) {
            this.id = id;
        }

        public PriorityAreaKey getKey() {
            return key;
        }

        public void setKey(PriorityAreaKey key) {
            this.key = key;
        }

        public List<PriorityArea> getPriorityAreas() {
            return priorityAreas;
        }

        public void setPriorityAreas(List<PriorityArea> priorityAreas) {
            this.priorityAreas = priorityAreas;
        }
}

我在DAO这个方法运行正常:

@Override
    @SuppressWarnings("unchecked")
    public Set<PriorityArea> findPriorityAreas(PriorityAreaKey key) {

        String jpql = "from PriorityAreaKeyword as pak where pak.key = :key";

        Query query = entityManager.createQuery(jpql);
        query.setParameter("key", key);     
        List<PriorityArea> priorityAreas =  query.getResultList();
        return new HashSet<PriorityArea>(priorityAreas);
    }

我创建了一个像这样的视图v_report_beneficiary_list(id,email,priority_area_key)

/**
 *
 */
@Entity
@Table(name = "v_report_beneficiary_list")
public class ReportBeneficiaryItem {

    private Long id;
    private String email;
    private PriorityAreaKey priorityAreaKey;


    /**
     * @return the id
     */
    @Id
    public Long getId() {
        return id;
    }


    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }



    @Column(name = "email")
    public String getEmail() {
        return email;
    }


    public void setEmail(String email) {
        this.email = email;
    }


    @Column(name = "priority_area_key")
    public PriorityAreaKey getPriorityAreaKey() {
        return priorityAreaKey;
    }


    public void setPriorityAreaKey(PriorityAreaKey priorityAreaKey) {
        this.priorityAreaKey = priorityAreaKey;
    }

在DAO中,我创建了另一种方法:

@Su

ppressWarnings("unchecked")
    @Override
    public List<ReportBeneficiaryItem> findReportProposalXBeneficiary(ProposalExportFilter filter) {

        // Create basic query
        String jpql = "from " + ReportBeneficiaryItem.class.getName() + " b where b.priorityAreaKey = :key ";

        // Create and execute jpa query
        Query query = createQuery(jpql);

        query.setParameter("key",      filter.getPriorityAreaKey());

        return query.getResultList();
    }

这引发了我一个抛出异常:java.sql.SQLSyntaxErrorException:ORA-01722:无效的数字

1 个答案:

答案 0 :(得分:1)

@Enumerated(EnumType.STRING)上的ReportBeneficiaryItem#getPriorityAreaKey()上缺少PriorityAreaKeyword#key,因为它在数据库中为该字段预期数字(枚举索引),但找到字符串

@Column(name = "priority_area_key")
@Enumerated(EnumType.STRING)
public PriorityAreaKey getPriorityAreaKey() {
    return priorityAreaKey;
}