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,
Rick

On Fri, Jun 22, 2012 at 8:18 PM, markyo <mark_youwa...@yahoo.com> 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;
>    }
> ...
>



-- 
*Rick Curtis*

Reply via email to