下面是背景:我有一个带注释的@Embeddable类,它有一个GregorianCalendar字段。我试图使用hibernate3 3: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;
}
}下面是错误读数:
错误未能在项目org.codehaus.mojo:hibernate3-maven-plugin:2.2:hbm上执行STRIPES_V2 2ddl (默认-cli):执行默认-目标的cli,org.code haus.mojo:hibernate3-maven-plugin:2.2:hbm2ddl失败:@ java.util.Date或java.util.Calendar属性: stripes.datamodel上只有s et。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是日历的一个具体扩展,那么有什么问题吗?
发布于 2012-11-06 16:41:39
规范中没有任何东西限制提供者能够自动出售您想要的日历的任意实现,所以如果它们允许您要求它提供特定的实现,那么它将是一个兼容性问题。(并不是说任何头脑正常的人都会创建一个新的日历子类,但这是有可能的。一个只知道如何返回它自己的自定义Calendar子类的JPA实现并不是规范中的任何错误,您不能要求它知道如何使用GregorianCalendar )。
或者说另一方面,如果我要创建org.affe.MyAwesomeCalendar,那么期望JPA提供程序能够为我制作它的实例是不合理的!
11.1.47时间说明 必须为java.util.Date和java.util.Calendar类型的持久字段或属性指定时态注释。它只能为这些类型的字段或属性指定。
Hibernate也不允许您直接选择java.sql.Date等。基本上,他们解释它是留给持久化提供者来决定使用什么Calendar实现。
https://stackoverflow.com/questions/13255108
复制相似问题