I have a class which im 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>();
...
}
The unit test fails throwing the following exception:
java.lang.ClassCastException: org.hibernate.id.IdentifierGeneratorHelper$2
cannot be cast to java.lang.Long
Im not too sure about the best value for 'generator', and I assume this will affect the outcome.
Also when i get this working, can the FileAttachment object access the Property_image_id? And how do you assign it to a property, since its defined in the Property class?
What I'd like is for the Property_images table to have a composite key [Property_id-Image_index], where Image_index starts at 1 for each new Property_id but I have no idea how to implement this using @ElementCollection and @CollectionId with a generator. Maybe i have to have FileAttachment as an @Entity instead of @Embeddable, but id rather not as its only used inside the Property class.
Cheers! NFV