openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Goodenough <david.goodeno...@btconnect.com>
Subject Re: Please make Exceptions more useful...
Date Wed, 02 Apr 2008 15:49:48 GMT
On Wednesday 02 April 2008, Patrick Linskey wrote:
> Hi,
>
> Can you post the full stack trace?
>
> -Patrick
>
> On Wed, Apr 2, 2008 at 7:59 AM, David Goodenough
>
> <david.goodenough@btconnect.com> wrote:
> > On Wednesday 02 April 2008, David Goodenough wrote:
> >  > I just got an error message which said:-
> >  >
> >  > Exception in thread "main" <openjpa-1.0.2-r420667:627158 nonfatal
> >  > general error> org.apache.openjpa.persistence.PersistenceException:
> >  > java.util.Date cannot be cast to java.util.Collection
> >  >
> >  > In this (and the accompanying stack trace) there is no indication
> >  > which Date object cannot be cast to a Collection.  Yes from the stack
> >  > trace I know that I was trying to persist a particular root object,
> >  > but I have no idea which class and field this error refers to.  Simply
> >  > adding the class and field would make debugging so much easier.
> >  >
> >  > Then once I know which Date field it might be, I can start to try to
> >  > work out why it wanted to cast it to a collection.  Presumably this
> >  > was it was trying to map this to a particular table, or to a set of
> >  > objects of a given type, and again it would be useful to know what
> >  > application object as opposed to raw java class it was trying to map
> >  > to.
> >  >
> >  > David
> >
> >  Well I dug a little further into this one, and I am confused.  It does
> > indeed have a Date object that is it trying to cast as a Collection.
> >
> >  From the FieldMapping object current at the time when it fails the field
> >  in question is uk.co.dga.bm.jpa.Role.roles, and its definition is:-
> >
> >         @OneToMany(fetch=FetchType.LAZY,cascade=CascadeType.ALL) private
> > List<Role> roles;
> >
> >  Which is (quite properly) a Collection, and is not a date (yes I know, I
> >  should not be using CascadeType.ALL, but at least here is does include
> >  PERSIST.  As it happens this list is empty.
> >
> >  There is a Date, but it is in a superclass, its my @Version.  The
> > superclass is declared:-
> >
> >  @MappedSuperclass public class Basic extends Observed {
> >         @Version @Temporal(TemporalType.TIMESTAMP) private Date version;
> >
> >  and there is the version field as well.  The outer class is declared:-
> >
> >  @Entity @Table(name="Roles") public class Role extends Basic {
> >
> >  All of which looks right to my untrained eye.  My guess is that for some
> >  reason the system is getting confused about which class it is looking
> > at, the outer one or the super class but I do not know.  I have tried
> > clearing the binaries out from the Eclipse project, and rebuilding
> > everything, but that did not help.
> >
> >  Is this a known problem (in which case is there a workaround), if not
> >  what do you need to help track it down.
> >
> >  David

Exception in thread "main" <openjpa-1.0.2-r420667:627158 nonfatal general 
error> org.apache.openjpa.persistence.PersistenceException: java.util.Date 
cannot be cast to java.util.Collection
        at org.apache.openjpa.kernel.BrokerImpl.persist(BrokerImpl.java:2411)
        at org.apache.openjpa.kernel.BrokerImpl.persist(BrokerImpl.java:2225)
        at 
org.apache.openjpa.kernel.DelegatingBroker.persist(DelegatingBroker.java:1005)
        at 
org.apache.openjpa.persistence.EntityManagerImpl.persist(EntityManagerImpl.java:541)
        at uk.co.dga.bm.loader.CreateUser.run(CreateUser.java:55)
        at uk.co.dga.bm.loader.CreateUser.main(CreateUser.java:67)
Caused by: java.lang.ClassCastException: java.util.Date cannot be cast to 
java.util.Collection
        at 
org.apache.openjpa.kernel.SingleFieldManager.persist(SingleFieldManager.java:267)
        at 
org.apache.openjpa.kernel.StateManagerImpl.cascadePersist(StateManagerImpl.java:2859)
        at org.apache.openjpa.kernel.BrokerImpl.persist(BrokerImpl.java:2406)
        ... 5 more

David

Mime
View raw message