由数据库控制的Hibernate时间戳版本. [英] Hibernate timestamp version controlled by database.
问题描述
我同时使用了Hibernate注释和Sybase.我正在寻找设置版本列以防止锁定.数据库需要管理时间戳而不是应用程序.我想使用注释而不是hbm.xml来完成此操作.
I'm using both Hibernate annotations and Sybase. I'm looking to setup a version column to prevent locking. The database needs to administrate the timestamp rather than the application. I would like to accomplish this using annotations rather than hbm.xml.
我尝试以下操作均未成功
I've tried the following without success,
我在jboss.org上阅读以使用
I read on jboss.org to use
@org.hibernate.annotations.SourceType.DB
@org.hibernate.annotations.Generated(GenerationTime.ALWAYS)
但是我遇到数据库的IDE编译错误,找不到标志符号:DB类位置:类SourceType"
however I'm getting an IDE compiling error for DB, "cannot find symbol symbol: class DB location: class SourceType"
以及rowVersion的编译错误
and a compiling error for rowVersion,
版本"字段或属性不是受支持的类型之一.确保它是以下类型之一:int,Integer,short,Short,long,Long,java.sql.Timestamp.
The Version field or property is not one of the supported types. Make sure that it is one of the following types: int, Integer, short, Short, long, Long, java.sql.Timestamp.
时间属性必须使用@Temporal注释进行标记.
A temporal attribute must be marked with the @Temporal annotation.
http://docs.jboss.org/hibernate/core/3.6/reference/zh-CN/html/mapping.html#d0e5785
5.1.3.2.时间戳
5.1.3.2. Timestamp
示例代码
@Version
@org.hibernate.annotations.SourceType.DB
@org.hibernate.annotations.Generated(GenerationTime.ALWAYS)
@Column(name = "row_version")
private Date rowVersion;
public Date getRowVersion() {
return rowVersion;
}
public void setRowVersion(Date rowVersion) {
this.rowVersion = rowVersion;
}
有人可以告诉我我想念什么吗?
Could someone tell me what I'm missing?
推荐答案
这不是批注,而是枚举的字段:
This is not an annotation, but a field of an enum:
@org.hibernate.annotations.SourceType.DB
您需要在字段中使用此
@Version
@org.hibernate.annotations.Source(SourceType.DB)
@org.hibernate.annotations.Generated(GenerationTime.ALWAYS)
@Column(name = "row_version") //maybe unnecessary, because this annotation
//is only needed, if the column name does not
//match hibernate's default naming strategy
//(or custom strategy).
@Temporal(TemporalType.TIMESTAMP)
private Date rowVersion;
这篇关于由数据库控制的Hibernate时间戳版本.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!