Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » @AttributeOverrides gives me exception
@AttributeOverrides gives me exception [message #665600] Fri, 15 April 2011 08:40 Go to next message
rudibravo is currently offline rudibravoFriend
Messages: 17
Registered: December 2010
Junior Member
Hello

I'm in the process of updating my JPA libraries, and I'm getting a new error.


I have the following scenario (I tried to simplify it to the best)

@Entity
@DiscriminatorValue(value="0")
public class B extends A
{
	private C otherInstance = new C();

	public B() {}

	@Embedded
	@AttributeOverrides({
		@AttributeOverride(name="field1", column=@Column(name="B_FIELD_1")),
		@AttributeOverride(name="field2", column=@Column(name="B_FIELD_2"))
	})
	public C getOtherInstance()
	{
		return otherInstance;
	}
	public void setOtherInstance(C otherInstance)
	{
		this.otherInstance = otherInstance;
	}
}

@Entity
@Inheritance(strategy= InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="TYPE",
		discriminatorType=DiscriminatorType.INTEGER, length=1)
@Table(name="MY_TABLE")
public abstract class A implements Serializable
{
	
	private C cInstance = new C();

	@Embedded
	@AttributeOverrides({
		@AttributeOverride(name="field1", column=@Column(name="A_FIELD_1")),
		@AttributeOverride(name="field2", column=@Column(name="A_FIELD_2"))
	})
	public C getCInstance()
	{
		return cInstance;
	}
	public void setCInstance(C cInstance)
	{
		this.cInstance = cInstance;
	}

}

@Embeddable
public class C
{
	private int field1;
	private int field2;

	public C() {}

	public int getField1()
	{
		return field1;
	}
	public void setField1(int field1)
	{
		this.field1 = field1;
	}

	public int getField2()
	{
		return field2;
	}
	public void setField2(int field2)
	{
		this.field2 = field2;
	}
}


But when I try to do a simple query I get the following exception

#|2011-04-15T09:43:22.224+0200|WARNING|glassfish3.1|org.ecli pse.persistence.session.file:/F:/glassfish3/glassfish/domain s/domain1/applications/Application_jar|_ThreadID=30;_ThreadN ame=Thread-1;|
Local Exception Stack:
Exception [EclipseLink-27] (Eclipse Persistence Services - 2.2.0.v20110202-r8913): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: Trying to invoke the method [getField1] on the object [B]. The number of actual and formal parameters differs, or an unwrapping conversion has failed.
Internal Exception: java.lang.IllegalArgumentException: object is not an instance of declaring class
Mapping: org.eclipse.persistence.mappings.DirectToFieldMapping[field1-->MY_TABLE.B_FIELD_1]
Descriptor: RelationalDescriptor(my.package.C --> [DatabaseTable(MY_TABLE)])
at org.eclipse.persistence.exceptions.DescriptorException.illeg alArgumentWhileGettingValueThruMethodAccessor(DescriptorExce ption.java:654)
at org.eclipse.persistence.internal.descriptors.MethodAttribute Accessor.getAttributeValueFromObject(MethodAttributeAccessor .java:85)
at org.eclipse.persistence.internal.descriptors.MethodAttribute Accessor.getAttributeValueFromObject(MethodAttributeAccessor .java:61)
at org.eclipse.persistence.mappings.DatabaseMapping.getAttribut eValueFromObject(DatabaseMapping.java:523)
at org.eclipse.persistence.mappings.foundation.AbstractDirectMa pping.valueFromRow(AbstractDirectMapping.java:1273)
at org.eclipse.persistence.mappings.DatabaseMapping.readFromRow IntoObject(DatabaseMapping.java:1325)
at org.eclipse.persistence.internal.descriptors.ObjectBuilder.b uildAttributesIntoObject(ObjectBuilder.java:344)
at org.eclipse.persistence.mappings.AggregateObjectMapping.buil dAggregateFromRow(AggregateObjectMapping.java:362)
at org.eclipse.persistence.mappings.AggregateObjectMapping.read FromRowIntoObject(AggregateObjectMapping.java:1415)
at org.eclipse.persistence.internal.descriptors.ObjectBuilder.b uildAttributesIntoObject(ObjectBuilder.java:344)
at org.eclipse.persistence.internal.descriptors.ObjectBuilder.b uildProtectedObject(ObjectBuilder.java:821)
at org.eclipse.persistence.internal.descriptors.ObjectBuilder.b uildObject(ObjectBuilder.java:657)
at org.eclipse.persistence.internal.descriptors.ObjectBuilder.b uildWorkingCopyCloneNormally(ObjectBuilder.java:612)
at org.eclipse.persistence.internal.descriptors.ObjectBuilder.b uildObjectInUnitOfWork(ObjectBuilder.java:565)
at org.eclipse.persistence.internal.descriptors.ObjectBuilder.b uildObject(ObjectBuilder.java:497)
at org.eclipse.persistence.internal.descriptors.ObjectBuilder.b uildObject(ObjectBuilder.java:456)
at org.eclipse.persistence.queries.ObjectLevelReadQuery.buildOb ject(ObjectLevelReadQuery.java:723)
at org.eclipse.persistence.queries.ReadAllQuery.registerResultI nUnitOfWork(ReadAllQuery.java:742)
at org.eclipse.persistence.queries.ReadAllQuery.executeObjectLe velReadQuery(ReadAllQuery.java:423)
at org.eclipse.persistence.queries.ObjectLevelReadQuery.execute DatabaseQuery(ObjectLevelReadQuery.java:1080)
at org.eclipse.persistence.queries.DatabaseQuery.execute(Databa seQuery.java:808)
at org.eclipse.persistence.queries.ObjectLevelReadQuery.execute (ObjectLevelReadQuery.java:1040)
at org.eclipse.persistence.queries.ReadAllQuery.execute(ReadAll Query.java:383)
at org.eclipse.persistence.queries.ObjectLevelReadQuery.execute InUnitOfWork(ObjectLevelReadQuery.java:1126)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.int ernalExecuteQuery(UnitOfWorkImpl.java:2842)
at org.eclipse.persistence.internal.sessions.AbstractSession.ex ecuteQuery(AbstractSession.java:1521)
at org.eclipse.persistence.internal.sessions.AbstractSession.ex ecuteQuery(AbstractSession.java:1503)
at org.eclipse.persistence.internal.sessions.AbstractSession.ex ecuteQuery(AbstractSession.java:1477)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.executeRea dQuery(EJBQueryImpl.java:484)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.getResultL ist(EJBQueryImpl.java:741)
at com.sun.enterprise.container.common.impl.QueryWrapper.getRes ultList(QueryWrapper.java:195)
...
Caused by: java.lang.IllegalArgumentException: object is not an instance of declaring class
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.persistence.internal.descriptors.MethodAttribute Accessor.getAttributeValueFromObject(MethodAttributeAccessor .java:82)
... 141 more

Any ideas? It was working on previous versions (2.0.1.v20100213-r6600)

Thanks
Re: @AttributeOverrides gives me exception [message #665982 is a reply to message #665600] Mon, 18 April 2011 13:13 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

Seems to be a bug in the new protected cache in 2.2.
Please log this bug and vote for it. The issue is that aggregates are not being supported correctly, the parent cache key is used.

Normally the protected cache is not used however, definitely should not be used on anything that was support in 2.0, so this is odd.

The protected cache should only be used if you have enabled caching on some objects, and disabled it on others, have you done this? What cache settings have you set?



James : Wiki : Book : Blog : Twitter
Re: @AttributeOverrides gives me exception [message #665994 is a reply to message #665982] Mon, 18 April 2011 14:07 Go to previous messageGo to next message
rudibravo is currently offline rudibravoFriend
Messages: 17
Registered: December 2010
Junior Member
Hi James,
I'm using the default cache settings and yes, I've disabled cache on some entities, but not on those.

I'll report the bug than.
Thanks
Re: @AttributeOverrides gives me exception [message #666138 is a reply to message #665600] Tue, 19 April 2011 09:54 Go to previous messageGo to next message
rudibravo is currently offline rudibravoFriend
Messages: 17
Registered: December 2010
Junior Member
By the way, here is the link for the bug report, if anyone cares about it

https://bugs.eclipse.org/bugs/show_bug.cgi?id=343162

Cheers,
Rudi
Re: @AttributeOverrides gives me exception [message #666656 is a reply to message #665994] Thu, 21 April 2011 13:24 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

I assume that one of these objects has a reference to an object that you have disabled the cache on (or a reference to a reference). If you avoid having cached objects with references to non-cached objects, this should solve the issue.

You could try with all caching disabled, or all caching enabled to verify this is the cause of the error.


James : Wiki : Book : Blog : Twitter
Re: @AttributeOverrides gives me exception [message #669977 is a reply to message #666656] Thu, 12 May 2011 09:37 Go to previous message
rudibravo is currently offline rudibravoFriend
Messages: 17
Registered: December 2010
Junior Member
You were right James. I enabled the cache from a reference and now it works.

Thanks for the tip.
Previous Topic:EJB transaction does not rollback stored procedure changes
Next Topic:@Embeddable object how to discriminate for an object with blank field
Goto Forum:
  


Current Time: Thu Apr 18 12:03:47 GMT 2024

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

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

Back to the top