Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 350189

Summary: SingularAttribute instead of ListAttribute is generated in Metamodel for byte[]
Product: [WebTools] Dali JPA Tools Reporter: Kenneth Cheung <kennethc>
Component: GeneralAssignee: Neil Hauge <neil.hauge>
Status: RESOLVED INVALID QA Contact:
Severity: normal    
Priority: P3 CC: brian.vosburgh, kwsutter, michael.d.dick, neil.hauge
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Kenneth Cheung CLA 2011-06-23 16:40:22 EDT
Build Identifier: I3622I20110617_20110617_1025

Metamodel generation in Dali does not produce the correct results. It seems that an OpenJPA 2.0.2 snapshot is used. The problem occurs when the entity class contains a byte[] array field. The metamodel generation produces a SingularAttribute for that. After starting the application we get an exception with that SingularAttribute. Using an external OpenJPA 2.1 for the metamodel generation produces the correct ListAttribute.

Reproducible: Always

Steps to Reproduce:
1. Generate metamodel for a simple Entity bean:
@Entity

public class MyEntity implements Serializable {

	
	private byte[] byteArray;
	private static final long serialVersionUID = 1L;

	public MyEntity() {
		super();
	}   
	public byte[] getByteArray() {
		return this.byteArray;
	}

	public void setByteArray(byte[] byteArray) {
		this.byteArray = byteArray;
	}
   
}
2. The metamodel looks like:
@Generated(value="Dali", date="2011-06-23T16:28:03.000-0400")
@StaticMetamodel(MyEntity.class)
public class MyEntity_ {
	public static volatile SingularAttribute<MyEntity, byte[]> byteArray;
}
Comment 1 Kenneth Cheung CLA 2011-06-23 16:53:58 EDT
Actually please disregard the OpenJPA 2.0.2 part.
Comment 2 Brian Vosburgh CLA 2011-06-24 10:59:38 EDT
The JPA spec states the following in section 6.2.1:

For every persistent non-collection-valued attribute y declared by class X, where the type of y is Y, the metamodel class must contain a declaration as follows:

    public static volatile SingularAttribute<X, Y> y;  

For every persistent collection-valued attribute z declared by class X, where the element type of z is Z, the metamodel class must contain a declaration as follows:
[...]
    if the collection type of z is java.util.List, then
        public static volatile ListAttribute<X, Z> z;

A byte[] is not a Collection (or List). The bug is in your runtime (OpenJPA 2.1?) throwing an exception.
Comment 3 Michael Dick CLA 2011-06-30 12:10:27 EDT
Seems like an oversight in OpenJPA which handles all arrays as collections (well lists). I've opened an issue with OpenJPA to address this problem : https://issues.apache.org/jira/browse/OPENJPA-2025
Comment 4 Neil Hauge CLA 2011-06-30 13:42:08 EDT
Resolving as invalid.