Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » ClassCastException when trying to access OneToOne object
ClassCastException when trying to access OneToOne object [message #1009227] Thu, 14 February 2013 17:58 Go to next message
jm collin is currently offline jm collinFriend
Messages: 7
Registered: February 2013
Junior Member
Hello there,

I'm trying to use EclipseLink 2.4.0 with MongoDB 2.2 on JBoss AS 7.1.1.
All works fine but I ran into a error trying to do something very simple.

I have 2 entities AttachmentRequest (A) and Account (B).
A have a relation with B declared like that :
@Entity
@NoSql(dataType="ATTACHMENT_REQUEST", dataFormat=DataFormatType.MAPPED)
public class AttachmentRequest extends JPAMongoBaseToVoConvertible {
	@Id
	@Field(name="_id")
	@GeneratedValue
	private String id;
	
	...
	// Relations
	// The emitter of this AttachmentRequest. Must be unique and present
	@OneToOne(targetEntity=Account.class)
	private Account emitterAccount=null;
...

@Entity
@NoSql(dataType="account", dataFormat=DataFormatType.MAPPED)
@Table(uniqueConstraints = @UniqueConstraint(columnNames = "email"))
public class Account extends JPAMongoBaseEntity {
	@Id
	@Field(name="_id")
	@GeneratedValue
	private String id;



I create successfully the A entity and link successfully with a B entity (verified directly in MongoDB).

Now I just to list all A having a B.id = parameter.

I do a request like this :
TypedQuery<AttachmentRequest> q = em.createQuery("Select ar from AttachmentRequest ar join ar.emitterAccount em where em.id=:emitterId", AttachmentRequest.class);
q.setParameter("emitterId", emitterId);
AttachmentRequest ar = q.getSingleResult();


The result is this exception :
[EL Warning]: 2013-02-14 18:37:11.454--UnitOfWork(1885572122)--Exception [EclipseLink-6168] (Eclipse Persistence Services - 2.4.0.v20120608-r11652): org.eclipse.persistence.exceptions.QueryException
Exception Description: Query failed to prepare, unexpected error occurred: [java.lang.ClassCastException: org.eclipse.persistence.eis.mappings.EISOneToOneMapping cannot be cast to org.eclipse.persistence.mappings.OneToOneMapping].
Internal Exception: java.lang.ClassCastException: org.eclipse.persistence.eis.mappings.EISOneToOneMapping cannot be cast to org.eclipse.persistence.mappings.OneToOneMapping
Query: ReadAllQuery(referenceClass=AttachmentRequest jpql="Select ar from AttachmentRequest ar join ar.emitterAccount em where em.id=:emitterId")


Any help would be great appreciated because I'm blocked on this issue for 2 days.

Thank's in advance

Re: ClassCastException when trying to access OneToOne object [message #1009719 is a reply to message #1009227] Fri, 15 February 2013 15:29 Go to previous message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
Joins are not supported for MongoDB as stated here:
http://wiki.eclipse.org/EclipseLink/Examples/JPA/NoSQL#Step_6_:_Querying
you might try mapping the foreign key with a read-only basic mapping and accessing it in the query directly. Or adding a query key for the fk field as described here
http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Basic_JPA_Development/Querying/Query_Keys though I do not know how or if this will work with MongoDB.

Best Regards,
Chris

Previous Topic:How to clear cache?
Next Topic:Toplink 10.1.3.5.0 to EclipseLink 2.4
Goto Forum:
  


Current Time: Tue Mar 19 02:33:13 GMT 2024

Powered by FUDForum. Page generated in 0.02339 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top