I have a class which im trying to implement, (similar to the example in 'Java Persistence with Hibernate' 6.3.3)
public class Property
private Collection<FileAttachment> images = new ArrayList<FileAttachment>();
cannot be cast to java.lang.Long
The JPA 2.0 specification does not provide a way to define the Id in the Embeddable. However, to delete or update a element of the ElementCollection mapping, some unique key is normally required. Otherwise, on every update the JPA provider would need to delete everything from the CollectionTable for the Entity, and then insert the values back. So, the JPA provider will most likely assume that the combination of all of the fields in the Embeddable are unique, in combination with the foreign key (JoinColumn(s)). This however could be inefficient, or just not feasible if the Embeddable is big, or complex. Some JPA providers may allow the Id to be specified in the Embeddable, to resolve this issue. Note in this case the Id only needs to be unique for the collection, not the table, as the foreign key is included. Some may also allow the unique option on the CollectionTable to be used for this. Otherwise, if your Embeddable is complex, you may consider making it an Entity and use a OneToMany instead.
I think that your
IMAGE_INDEX requirement can be tackled with OrderColumns:
@ElementCollection(fetch=FetchType.EAGER) @OrderColumn(name = "IMAGE_INDEX") private List<FileAttachment> images;
This post may be useful.