Как я могу внедрить некоторые bean-компоненты (или свойства конфигурации) ) в мою реализацию генератора?
Вот код:
Код: Выделить всё
@Entity
@Table(name = "my_entity")
public class MyEntity {
@Id
@MyIdGeneratorValue
@Column(name = "id")
private Long id;
//other fields
}
@IdGeneratorType(MyIdGenerator.class)
@Retention(RUNTIME)
@Target({METHOD, FIELD})
public @interface MyIdGeneratorValue {
}
public class MyIdGenerator implements BeforeExecutionGenerator {
//doesn't work
@Inject
OtherService service;
@Override
public Object generate(SharedSessionContractImplementor session, Object owner, Object currentValue,
EventType eventType) {
return service.nextId();
}
@Override
public EnumSet getEventTypes() {
return INSERT_ONLY;
}
}
Я' Я использую Quarkus в качестве реализации CDI.
Подробнее здесь: https://stackoverflow.com/questions/790 ... ngenerator
Мобильная версия