package-info.java + Hibernate注释@TypeDefs + Maven

时间:2015-02-04 05:58:28

标签: java hibernate maven orm package-info

如何在单独的package-info.java类中声明@TypeDefs,并将其与@Type一起使用。目前我已按照以下方式宣布。但是当我用Maven编译应用程序时,它会给出以下错误。谢谢。

package-info.java类

@TypeDefs
        ({
                @TypeDef(
                        name="encryptedString",
                        typeClass=EncryptedStringType.class,
                        parameters={
                                @Parameter(name="encryptorRegisteredName",
                                        value="rcmHibernateStringEncryptor")
                        }
                )
        })

package com.core.model;
import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.TypeDefs;
import org.hibernate.annotations.Parameter;
import org.jasypt.hibernate4.type.EncryptedStringType;

Maven错误

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project MyApp: Compilation failure
[ERROR] com\core\model\package-infor.java:[2,0] error: package annotations should be in file package-info.java

1 个答案:

答案 0 :(得分:4)

您需要将package-infor.java重命名为package-info.java

其中应包含以下内容:

@TypeDefs({
    @TypeDef(
        name="encryptedString",
        typeClass=EncryptedStringType.class,
        parameters={
            @Parameter(name="encryptorRegisteredName",
                value="rcmHibernateStringEncryptor")
        }
    )
})    
package com.core.model;
import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.TypeDefs;
import org.hibernate.annotations.Parameter;
import org.jasypt.hibernate4.type.EncryptedStringType;