-
Hello! Totally stuck here: public class Customer extends PanacheEntityBase {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seq_customer")
@SequenceGenerator(name = "seq_customer", sequenceName = "seq_customer_oid", allocationSize = 1)
@Column(name = "OID", nullable = false, unique = true)
public Long oid;
@GeneratorType(type = CustomerIdGenerator.class, when = GenerationTime.INSERT)
@Column(name = "CUSTOMER_ID")
public BigInteger customerId; public class CustomerIdGenerator extends MutinyValueGenerator<BigInteger> {
@Override
public Uni<BigInteger> generateValue(Mutiny.Session session, Object o) {
return session
.createNativeQuery("select SEQ_CUSTOMER_ID.nextval FROM dual")
.getSingleResult()
// Of course Oracle returns a BigDecimal instead...
.map(x -> ((BigDecimal) x).toBigInteger());
}
} MutinyValueGenerator doesn't exist in hibernate-reactive anymore, @GeneratorType is deprecated and marked for removal... Colleague made it like this: @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seq_customer_id")
@SequenceGenerator(name = "seq_customer_id", sequenceName = "SEQ_CUSTOMER_ID", allocationSize = 1)
@Column(name = "CUSTOMER_ID")
public BigInteger customerId; which compiles and runs, but does not generate a customerId but leaves it empty. So tried different approaches. Last one is: public class CustomerIdGenerator extends MutinyGenerator {
@Override
public Uni<Object> generate(Mutiny.Session session, Object owner, Object currentValue, EventType eventType) {
return session
.createNativeQuery("select SEQ_CUSTOMER_ID.nextval FROM dual")
.getSingleResult()
;
}
@Override
public EnumSet<EventType> getEventTypes() {
return EventTypeSets.INSERT_ONLY;
}
} @ValueGenerationType(generatedBy = ArchiveIdGenerator.class)
@Column(name = "CUSTOMER_ID", nullable = false)
public BigInteger customerId; But this leads to: @ValueGenerationType' not applicable to field Any help appreciated! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
/cc @DavideD (hibernate-reactive), @Sanne (hibernate-reactive), @gavinking (hibernate-reactive) |
Beta Was this translation helpful? Give feedback.
-
My solution: public class CustomerIdGenerator extends MutinyGenerator {
@Override
public Uni<Object> generate(Mutiny.Session session, Object owner, Object currentValue, EventType eventType) {
return session
.createNativeQuery("select SEQ_CUSTOMER_ID.nextval FROM dual")
.getSingleResult()
.map(x -> BigInteger.valueOf((Integer) x))
;
}
} public class Customer extends PanacheEntityBase {
@ValueGenerationType(generatedBy = CustomerIdGenerator.class)
@Retention(RetentionPolicy.RUNTIME)
public @interface CustomerId {}
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seq_customer")
@SequenceGenerator(name = "seq_customer", sequenceName = "seq_customer_oid", allocationSize = 1)
@Column(name = "OID", nullable = false, unique = true)
public Long oid;
@CustomerId
@Column(name = "CUSTOMER_ID")
public BigInteger customerId; |
Beta Was this translation helpful? Give feedback.
My solution: