I have a class that im is trying to implement (similar to the example in Java Persistence with Hibernate 6.3.3)
public class Property { ... @ElementCollection(fetch=FetchType.EAGER) @CollectionId( columns=@Column (name="Property_image_id"), type=@Type (type="long"), generator="native" ) private Collection<FileAttachment> images = new ArrayList<FileAttachment>(); ... }
unit test throws the following exception:
java.lang.ClassCastException: org.hibernate.id.IdentifierGeneratorHelper$2 cannot be cast to java.lang.Long
I am not too sure of the best value for the βgeneratorβ, and I assume that this will affect the result.
Also, when I get this working, can a FileAttachment object access Property_image_id? And how do you assign it to a property since it is defined in the property class?
I want the Property_images table to have a compound key [Property_id-Image_index], where Image_index starts with 1 for each new Property_id, but I have no idea how to implement this using @ElementCollection and @CollectionId using a generator. Maybe I should have FileAttachment as @Entity instead of @Embeddable, but id is probably not the way it is used only inside the Property class.
Hooray! Nfv
source share