You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by markyo <ma...@yahoo.com> on 2012/06/23 03:18:20 UTC
ClassCast exception while iterating over an element collection of
embeddables
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;
}
...
--
View this message in context: http://openjpa.208410.n2.nabble.com/ClassCast-exception-while-iterating-over-an-element-collection-of-embeddables-tp7580378.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.
Re: ClassCast exception while iterating over an element collection of embeddables
Posted by Rick Curtis <cu...@gmail.com>.
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 <cu...@gmail.com> 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 <ma...@yahoo.com>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*
>
>
--
*Rick Curtis*
Re: ClassCast exception while iterating over an element collection of embeddables
Posted by Rick Curtis <cu...@gmail.com>.
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 <ma...@yahoo.com>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*
Re: ClassCast exception while iterating over an element collection of embeddables
Posted by Mark Youwanes <ma...@yahoo.com>.
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
Re: ClassCast exception while iterating over an element collection of embeddables
Posted by Rick Curtis <cu...@gmail.com>.
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 <ma...@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*