0

I have an embeddable collection and i want to have a auto-generated UUID field in it. I am using hibernate ogm with mongoDB. I am trying the following code but it results in the following exception:

@Embeddable
public class Attachment {

    @Id
    @GeneratedValue(generator = "uuid")
    @GenericGenerator(name="uuid", strategy="uuid2")
    private String attachmentId;

Exception:

Caused by: org.hibernate.annotations.common.AssertionFailure: Declaring class is not found in the inheritance state hierarchy: com.xxx.yyy.zzz.model.Attachment

if I remove this id field, everything works fine except that my embedded document have no id in it. Any thoughts?

Obaid Maroof
  • 1,523
  • 2
  • 19
  • 40

1 Answers1

0

I don't think there is a way to do what you need at the moment.

The @GeneratedValue, @GenericGenerator and @Id are supposed to be used with entities, not with embeddables (as far as I know).

You probably need to generate a new UUID manually when you create a new embedded element.

Davide D'Alto
  • 7,421
  • 2
  • 16
  • 30