5

I have this logic:

@GenericGenerator(
        /**
         * This one works as GenerationType.IDENTITY but works for table per subclass inheritance as well!
         */
        name     = "abc",
        strategy = "org.hibernate.id.enhanced.SequenceStyleGenerator",
        parameters = {
                @Parameter(name = SequenceStyleGenerator.INITIAL_PARAM,                     value = "" + MoJVEntity.Keys.INDEX_START),
                @Parameter(name = SequenceStyleGenerator.CONFIG_PREFER_SEQUENCE_PER_ENTITY, value = "true"  ),
                @Parameter(name = SequenceStyleGenerator.OPT_PARAM,                         value = "hilo"  )
        }
)

which I am either forced to use on a subclass, or copy and paste on each entity class that needs an id from this generator.

It would be a whole lot easier to just define this once, since you then have to use:

        @Id
        @GeneratedValue(generator = "abc")
        Long id;

on each id anyway.

Is it possible to use on a MappedSuperClass, or on any class level? ( Class level is not working in the same class as @Id is declared, although I am looking to define this only once )

Documentation says that class level and package level should work, but I couldn't get that to work.

mjs
  • 21,431
  • 31
  • 118
  • 200

0 Answers0