开发者

WrongClassException switching from eclipselink to Hibernate

I had a working code written in pure JPA and running on Glassfish v3.0.1 (eclipselink) I decided to switch persistence provider to hbernate 3.5.1-final and I'm experiencing exceptions in one query that had worked before.

All other queries( named queries) work fine. Could someone tell me what is wrong with the one below? I can't make it a named query because I need to sort the job by different parameters.

Why are the collections inside Job class not being queried?

Thanks for any help

javax.persistence.PersistenceException: org.hibernate.WrongClassException: Object with id: 16 was not of the specified subclass: mypackage.Job (Discriminator: )

Hibernate:

select job0_.id as id7_, job0_.version as version7_, job0_.created as creat ed7_, job0_.error_msg as error5_7_, job0_.priority as priority7_, job0_.retries as retries7_, job0_.status as status7_, job0_.subject as subject7_, job0_.user_id as user10_7_, job0_.DTYPE as DTYPE7_ from test_job job0_ where job0_.user_id=? order by job0_.created DESC limit ?

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();

Classes:

@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 ....
}


There is something completly wrong: the query: "SELECT e from Job e WHERE e.user = :user " would try to access a field "user" of class Job, but this class does not have such a field!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜