ArchiveOrangemail archive

users.openjpa.apache.org


(List home) (Recent threads) (2 other Apache OpenJPA lists)

Subscription Options

  • RSS or Atom: Read-only subscription using a browser or aggregator. This is the recommended way if you don't need to send messages to the list. You can learn more about feed syndication and clients here.
  • Conventional: All messages are delivered to your mail address, and you can reply. To subscribe, send an email to the list's subscribe address with "subscribe" in the subject line, or visit the list's homepage here.
  • Low traffic list: less than 3 messages per day
  • This list contains about 10,776 messages, beginning Jun 2007
  • 7 messages added yesterday
Report the Spam
This button sends a spam report to the moderator. Please use it sparingly. For other removal requests, read this.
Are you sure? yes no

ClassCast exception while iterating over an element collection of embeddables

Ad
markyo 1340414328Sat, 23 Jun 2012 01:18:48 +0000 (UTC)
When I try to iterate over a collection of embeddable objects, I get the
following exception:

java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to
com.kryterion.wa.core.model.ftp.FtpSubdirectory

I'm very confused by this...I have the Pro JPA 2 book and closely followed
its example of the Employee class and its element collection of embeddable
Vacation bookings.

When I look at the collection while debugging, I see that the subdirectories
field is an ArrayList proxy which has a field called elementData, which is
an Object array. When I inspect the first element of this Object array, I
see that it too is an Object array with three string elements (the path,
type, and description values). Basically, I don't see that OpenJPA loaded up
a collection of FtpSubdirectory objects as I would've expected, and hence
the class cast exception.

My mappings:

@Entity
@Table(name = "core_ftp_connection")
public class FtpConnection extends AbstractMultiNamedEntity {
    
    private static final long serialVersionUID = 1L;

...    
    
    @ElementCollection(targetClass = FtpSubdirectory.class, fetch =
FetchType.EAGER)
    @CollectionTable(name = "core_ftp_subdir", joinColumns =
@JoinColumn(name = "fk_ftp_connection_id"))
    private Collection<FtpSubdirectory> subdirectories = new
ArrayList<FtpSubdirectory>();
...

and

@Embeddable
public class FtpSubdirectory {
    
    @Column(name = "path")
    private String path;
    
    @Column(name = "type")
    @Enumerated(EnumType.STRING)
    private SubdirectoryType type;
    
    @Column(name = "description")
    private String description;
    
    public String getPath() {
        return path;
    }
...
Rick Curtis 1340547236Sun, 24 Jun 2012 14:13:56 +0000 (UTC)
Mark -

Can we see the code that shows how you are getting a FtpConnection? Also,
what version of OpenJPA are you running and how are you enhancing your
Entities?

One note, I'm pretty certain you can get rid of the 'targetClass =
FtpSubdirectory.class' attribute of your ElementCollection annotation.

Thanks,
RickOn Fri, Jun 22, 2012 at 8:18 PM, markyo  wrote:

> When I try to iterate over a collection of embeddable objects, I get the
> following exception:
>
> java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to
> com.kryterion.wa.core.model.ftp.FtpSubdirectory
>
> I'm very confused by this...I have the Pro JPA 2 book and closely followed
> its example of the Employee class and its element collection of embeddable
> Vacation bookings.
>
> When I look at the collection while debugging, I see that the
> subdirectories
> field is an ArrayList proxy which has a field called elementData, which is
> an Object array. When I inspect the first element of this Object array, I
> see that it too is an Object array with three string elements (the path,
> type, and description values). Basically, I don't see that OpenJPA loaded
> up
> a collection of FtpSubdirectory objects as I would've expected, and hence
> the class cast exception.
>
> My mappings:
>
> @Entity
> @Table(name = "core_ftp_connection")
> public class FtpConnection extends AbstractMultiNamedEntity {
>
>    private static final long serialVersionUID = 1L;
>
> ...
>
>    @ElementCollection(targetClass = FtpSubdirectory.class, fetch =
> FetchType.EAGER)
>    @CollectionTable(name = "core_ftp_subdir", joinColumns =
> @JoinColumn(name = "fk_ftp_connection_id"))
>    private Collection<FtpSubdirectory> subdirectories = new
> ArrayList<FtpSubdirectory>();
> ...
>
> and
>
> @Embeddable
> public class FtpSubdirectory {
>
>    @Column(name = "path")
>    private String path;
>
>    @Column(name = "type")
>    @Enumerated(EnumType.STRING)
>    private SubdirectoryType type;
>
>    @Column(name = "description")
>    private String description;
>
>    public String getPath() {
>        return path;
>    }
> ...
>
Mark Youwanes 1342885543Sat, 21 Jul 2012 15:45:43 +0000 (UTC)
Hi Rick,

I'm using OpenJPA 2.2.0 and build-time enhancement. The ftp connection is 
getting retrieved eagerly as a member of a ClientRegion object:

@Entity
@Table(name = "client_region")
public class ClientRegion extends AbstractNamedEntity {
    
    private static final long serialVersionUID = 1L;
    
    public static final String FIND_ALL_BY_CLIENT_NAME_QUERY = 
"ClientRegion.findAllByClientName";
    public static final String CLIENT_NAME_QUERY_PARAM = "clientName";
    public static final String STATUS_QUERY_PARAM = "status";
    
    @Enumerated(EnumType.STRING)
    @Column(name = "STATUS")
    private Status status = ACTIVE;
    
    @ManyToOne
    @JoinColumn(name = "fk_client_id")
    private Client client;
    
    @Column(name = "brand")
    private String brand;
    
    @ManyToMany(cascade = {
            CascadeType.MERGE, CascadeType.PERSIST
    }, fetch = FetchType.EAGER)
    @JoinTable(name = "core_client_ftp_connection", joinColumns = 
@JoinColumn(name = "fk_client_region_id"), inverseJoinColumns = 
@JoinColumn(name = "fk_ftp_connection_id"))
    private Collection<FtpConnection> ftpConnections = 
new ArrayList<FtpConnection>();

....

I'm using Spring Data JPA to access the objects.

I appreciate your help on this.



Mark
Rick Curtis 1343051108Mon, 23 Jul 2012 13:45:08 +0000 (UTC)
Mark -

Is there any way that you could put together a small standalone unit test
that recreates this issue? I am unable to put a test together that
demonstrates the ClassCastException.

Thanks,
RickOn Fri, Jul 20, 2012 at 9:05 PM, Mark Youwanes wrote:

> Hi Rick,
>
> I'm using OpenJPA 2.2.0 and build-time enhancement. The ftp connection is
> getting retrieved eagerly as a member of a ClientRegion object:
>
> @Entity
> @Table(name = "client_region")
> public class ClientRegion extends AbstractNamedEntity {
>
>     private static final long serialVersionUID = 1L;
>
>     public static final String FIND_ALL_BY_CLIENT_NAME_QUERY =
> "ClientRegion.findAllByClientName";
>     public static final String CLIENT_NAME_QUERY_PARAM = "clientName";
>     public static final String STATUS_QUERY_PARAM = "status";
>
>     @Enumerated(EnumType.STRING)
>     @Column(name = "STATUS")
>     private Status status = ACTIVE;
>
>     @ManyToOne
>     @JoinColumn(name = "fk_client_id")
>     private Client client;
>
>     @Column(name = "brand")
>     private String brand;
>
>     @ManyToMany(cascade = {
>             CascadeType.MERGE, CascadeType.PERSIST
>     }, fetch = FetchType.EAGER)
>     @JoinTable(name = "core_client_ftp_connection", joinColumns =
> @JoinColumn(name = "fk_client_region_id"), inverseJoinColumns =
> @JoinColumn(name = "fk_ftp_connection_id"))
>     private Collection<FtpConnection> ftpConnections =
> new ArrayList<FtpConnection>();
>
> ....
>
> I'm using Spring Data JPA to access the objects.
>
> I appreciate your help on this.
>
>
>
> Mark
>
>
>
>
>
Rick Curtis 1343051896Mon, 23 Jul 2012 13:58:16 +0000 (UTC)
Sorry, I missed that you opened a JIRA already... I'll try to take a look
sometime in the coming days.On Mon, Jul 23, 2012 at 8:44 AM, Rick Curtis  wrote:

> Mark -
>
> Is there any way that you could put together a small standalone unit test
> that recreates this issue? I am unable to put a test together that
> demonstrates the ClassCastException.
>
> Thanks,
> Rick
>
>
> On Fri, Jul 20, 2012 at 9:05 PM, Mark Youwanes wrote:
>
>> Hi Rick,
>>
>> I'm using OpenJPA 2.2.0 and build-time enhancement. The ftp connection is
>> getting retrieved eagerly as a member of a ClientRegion object:
>>
>> @Entity
>> @Table(name = "client_region")
>> public class ClientRegion extends AbstractNamedEntity {
>>
>>     private static final long serialVersionUID = 1L;
>>
>>     public static final String FIND_ALL_BY_CLIENT_NAME_QUERY =
>> "ClientRegion.findAllByClientName";
>>     public static final String CLIENT_NAME_QUERY_PARAM = "clientName";
>>     public static final String STATUS_QUERY_PARAM = "status";
>>
>>     @Enumerated(EnumType.STRING)
>>     @Column(name = "STATUS")
>>     private Status status = ACTIVE;
>>
>>     @ManyToOne
>>     @JoinColumn(name = "fk_client_id")
>>     private Client client;
>>
>>     @Column(name = "brand")
>>     private String brand;
>>
>>     @ManyToMany(cascade = {
>>             CascadeType.MERGE, CascadeType.PERSIST
>>     }, fetch = FetchType.EAGER)
>>     @JoinTable(name = "core_client_ftp_connection", joinColumns =
>> @JoinColumn(name = "fk_client_region_id"), inverseJoinColumns =
>> @JoinColumn(name = "fk_ftp_connection_id"))
>>     private Collection<FtpConnection> ftpConnections =
>> new ArrayList<FtpConnection>();
>>
>> ....
>>
>> I'm using Spring Data JPA to access the objects.
>>
>> I appreciate your help on this.
>>
>>
>>
>> Mark
>>
>>
>>
>>
>>
>
>
> --
> *Rick Curtis*
>
>
Home | About | Privacy