OSGi中的UserType

时间:2017-07-18 09:52:28

标签: java hibernate osgi

我有一个非常简单的用例不起作用,我认为它可能是OSGi上下文我正在运行Hibernate,但我不确定:

@Entity(name = "Profile")
@Table(name = "profile")
@TypeDefs({ @TypeDef(name = "RawDataUserType", typeClass = RawDataUserType.class) })
public class ProfileEntity {

    @Column(name = "raw_data")
    @Type(type = "RawDataUserType")
    private RawData rawData;
}

public class RawDataUserType implements UserType {

    public RawDataUserType() {
        System.out.println("RawDataUserType.RawDataUserType()");
    }
    // actual implementation
 }

我可以看到抛出异常时没有调用RawDataUserType的构造函数:

Caused by: org.hibernate.MappingException: Could not determine type for: org.acme.module.RawDataUserType, at table: profile, for columns: [org.hibernate.mapping.Column(raw_data)]
at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:411)
at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:384)
at org.hibernate.mapping.Property.isValid(Property.java:226)
at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:529)
at org.hibernate.mapping.RootClass.validate(RootClass.java:265)
at org.hibernate.boot.internal.MetadataImpl.validate(MetadataImpl.java:329)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:464)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:881) 

OSGi类加载器通常在查找类时遇到问题,并且至少this person似乎有同样的问题(但没有解决方案)。但是,org.hibernate.osgi应该用在OSGi中工作的东西替换类加载器。

要修复它,我尝试将以下行添加到 Manifest.MF (不,它不是OSGi标准,但我不在乎它是否有效):

Eclipse-RegisterBuddy: org.hibernate.core
Eclipse-BuddyPolicy: global

是否可以在OSGi中使用UserType?怎么样?

0 个答案:

没有答案