support SQL arrays
Both Hibernate and EclipseLink have an @Array annotation for mapping Java arrays to SQL array types.
I therefore think we should add the following annotation to JPA:
@Target({FIELD, METHOD})
@Retention( RUNTIME )
public @interface Array {
/**
* The maximum length of the array.
*/
int length();
}
You could use it like this:
@Array(length=10)
String[] tags;
IMO we should leave fetch and optional to @Basic. Also, the length should maybe be optional with a reasonable default that allows vendor flexibility i.e. value 0.
IMO we should leave
fetchand optional to@Basic.
Ah yes, you're right. For some reason I thought that @Lob and @Enumerated worked this way. But I misremembered. We should be consistent with those annotations, and let this combine with @Basic.
Also, the
lengthshould maybe be optional with a reasonable default that allows vendor flexibility
That sounds like a recipe for unnecessary lack of portability to me.
That sounds like a recipe for unnecessary lack of portability to me.
I mean, unless you want to actually specify what the default is. But I have no intuition as to what would be a sensible default here.
The default could be the maximum possible size a DB allows. Since Oracle requires to specify array sizes, but other databases support just "unlimited" (within the bounds of row format limits) elements, a default to max might be nice. If Oracle users care about row size and perf (not sure if the max size affects that), they can specify a lower value.
The default could be the maximum possible size a DB allows.
Wouldn't that be extremely inefficient for small arrays?
Like I wrote, every DB other than Oracle supports unlimited size by default or doesn't even allow specifying a size limit in the column definition. To restrict the size, we'd have to emit a check constraint. I don't know if it is inefficient on Oracle to ask for an array of e.g. 10000 when only storing 1 element, but like I wrote, if users target Oracle, they will want to define that length anyway.
If I use this on a raw Collection, I need something like targetEntity, like in ie @OneToMany(targetEntity=...)
Yeah, Class<?> targetClass() default void.class; is probably appropriate.