我有两个项目,upstream
和downstream
。 upstream
是downstream
的编译时依赖项。
我在BaseEntity
中有一个班级upstream
:
@MappedSuperclass
public abstract class BaseEntity<T extends Serializable> {
public abstract T getId()
...
我在CustomUUIDGenerator
中也有一个upstream
类:
public class CustomUUIDGenerator extends UUIDGenerator {
@Override
public Serializable Generate(SharedSessionContractImplementor session, Object obj) throws HibernateException {
...
我在UserType
中也有JsonbType
,upstream
的派生类。
我已将这些批注添加到package-info.java
的根包中的upstream
文件中:
@GenericGenerator(name = "UUIDGenerator", strategy="<path>.CustomUUIDGenerator")
@TypeDef(name = "jsonb", typeClass = JsonbType.class)
在downstream
中,我有一个课程TestEntity
:
@Entity
@Table(name = "test")
public class TestEntity extends BaseEntity<UUID> {
@Id
@GeneratedValue(generator = "UUIDGenerator")
private UUID id;
@Type(type = "jsonb")
private TestPojo data;
public static class TestPojo {
String prop1;
String prop2;
<constructors for TestPojo omitted, but they are in my code>
}
<getters and setters omitted>
}
我在downstream
中进行了一个测试,试图保留TestEntity
,但是运行该测试时,我看到了org.hibernate.AnnotationException: Unknown Id.generator: UUIDGenerator
。如果我从generator
的{{1}}中删除了@GeneratedValue
参数并运行它,我会看到TestEntity
。
这些“定义”类型注释可用于类的条件是什么?如果我希望org.hibernate.boot.registry.classloading.spi.ClassLoadingException: Unable to load class [jsonb]
适用于具有@Type(type = "jsonb")
作为依赖项的项目中的所有实体,我将如何实现?