我有一个用纯JPA编写并在Glassfish v3.0.1(eclipselink)上运行的代码
我决定将持久性提供程序切换到hbernate 3.5.1-final,并且我在之前运行过的一个查询中遇到异常。
所有其他查询(命名查询)工作正常。有人能告诉我下面的那个有什么问题吗?
我不能使它成为命名查询,因为我需要通过不同的参数对作业进行排序。
为什么没有查询Job类中的集合?
谢谢你的帮助
javax.persistence.PersistenceException:org.hibernate.WrongClassException:id为16的对象不属于指定的子类:mypackage.Job(Discriminator:)
休眠:
选择job0_.id为id7_,job0_.version为version7_, job0_.created as creat ed7_,job0_.error_msg为error5_7_, job0_.priority为priority7_, job0_.retries为retries7_, job0_.status作为status7_, job0_.subject as subject7_, job0_.user_id为user10_7_,job0_.DTYPE为来自test_job job0_的DTYPE7_ job0_.user_id =?按job0_.created DESC限制排序?
List foo; String qst = " SELECT e from Job e WHERE e.user = :user "; qst += " ORDER BY e." + orderBy; Query q = em.createQuery(qst); //TypedQuery +List q.setParameter("user", user); q.setMaxResults(length); q.setFirstResult(start); foo = q.getResultList();
类:
@Entity @Table @NamedQueries{} Job extends BaseEntity{ ... @ManyToMany(fetch = FetchType.EAGER) @JoinTable(name = "job_address", joinColumns = @JoinColumn(name = "job_id"), inverseJoinColumns = @JoinColumn(name = "address_id")) @NotNull protected Set FtpAddress> addresses; @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL) @JoinTable(name = "job_transmission", joinColumns = @JoinColumn(name = "job_id"), inverseJoinColumns = @JoinColumn(name = "transmission_id")) protected Set Transmission> transmissions; } @MappedSuperclass BaseEntity{ int id int version .... }
答案 0 :(得分:0)
有一些完全错误:查询:
"SELECT e from Job e WHERE e.user = :user "
会尝试访问Job类的字段“user”,但是这个类没有这样的字段!