簡體   English   中英

為什么hbm2ddl不喜歡我在GregorianCalendar上的@Temporal注釋?

[英]Why does hbm2ddl not like my @Temporal annotation on a GregorianCalendar?

這是背景:我有一個帶注釋的@Embeddable Java類,該類具有GregorianCalendar字段。 我正在嘗試使用hibernate3:hbm2ddl通過hibernate3 Maven插件生成模式,以便我可以持久保存嵌入該對象的另一個對象,但是在使用@Temporal

這是可嵌入的類:

@Embeddable
public class OperationalStatus implements Serializable {
        .
        .
        .
    /**
     * Recorded date/time that the status value is valid
     */
    private GregorianCalendar time;

    /**
     * No-argument constructor.
     */
    public OperationalStatus() {}
        .
        .
        .
    /**
     * @return the time
     */
    @Temporal(TemporalType.TIMESTAMP) 
    public GregorianCalendar getTime() {
        return time;
    }

    /**
     * @param time the time to set
     */
    public void setTime(GregorianCalendar time) {
        this.time = time;
    }
}

這是錯誤讀數:

[錯誤]無法在項目STRIPES_V2上執行目標org.codehaus.mojo:hibernate3-maven-plugin:2.2:hbm 2ddl(default-cli):執行目標org.code haus.mojo:hibernate3-maven-plugin的default-cli :2.2:hbm2ddl失敗:@Temporal僅應在java.util.Date或java.util.Calendar屬性:stripes.datamodel上進行設置。 util.OperationalStatus.time

這是pom的一些摘錄:

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>hibernate3-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
    <components>
        <component>
            <name>hbm2ddl</name>
            <implementation>annotationconfiguration</implementation>
        </component>
    </components>
    <componentProperties>
        <drop>false</drop>
        <configurationfile>src/main/resources/hibernate.cfg.xml</configurationfile>
        <outputfilename>schema.sql</outputfilename>
    </componentProperties>
</configuration>
<dependencies>
    <dependency>
        <groupId>postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <version>9.2-1000.jdbc4</version>
    </dependency>
</dependencies>
</plugin>
.
.
.
<dependency>
    <groupId>org.hibernate</groupId>
    <version>4.1.7.Final</version>
    <artifactId>hibernate-core</artifactId>
</dependency>

我想念什么? GregorianCalendar是Calendar的具體擴展,那么怎么了?

規范中沒有任何內容限制提供商能夠出售所需的日歷的任何特定任意實現,因此如果他們允許您要求它提供特定的日歷,那么它將是一個兼容性問題。 (並不是說任何有主見的人都會創建Calendar的新子類,但是存在這種可能性。JPA實現只知道如何返回自己的Calendar的自定義子類,因此規范中的任何內容都不會錯,您不能要求它知道如何使用GregorianCalendar。)

或者,另一方面,如果我要創建org.affe.MyAwesomeCalendar,則期望JPA提供程序能夠為我創建它的實例是不合理的!

11.1.47時間注釋

必須為java.util.Date和java.util.Calendar類型的持久字段或屬性指定時間注釋。 只能為這些類型的字段或屬性指定。

Hibernate也不允許您直接選擇java.sql.Date等。 基本上,他們解釋是由持久性提供程序決定使用哪種Calendar實現。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM