我有一个带有@Version
注释版本的属性的对象。从数据库中检索此对象并将其发送到前端时,缺少版本字段。是否需要从数据库中检索对象并将其发送到前端?我在后端使用java和spring。数据库中的字段正在更新,因此该部分可以正常工作,但由于某种原因,版本字段未发送到前端。
以下是我的域类的相关导入:
import javax.persistence.Version;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
以下是我的域名实体的相关代码:
@Entity
@NamedQueries({})
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
@Table(schema = "schema", name = "type")
public class Type {
@Column(name = "title", length = 128, nullable = false)
@Basic(fetch = FetchType.EAGER)
String title;
@Column(name = "description", length = 128, nullable = false)
@Basic(fetch = FetchType.EAGER)
String description;
@Version
@Column(name = "version", nullable = false)
@Basic(fetch = FetchType.EAGER)
int version = 0;
//getters and setters
public void setVersion(int version)
{
this.version = version;
}
public int getVersion()
{
return version;
}
}
以下是相关的休息控制器导入:
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
以下是将实体发送到客户端的Rest Controller方法:
@RequestMapping(value = "/type", method = RequestMethod.GET)
public List<Type> listTypes() {
ArrayList<Type> list = new java.util.ArrayList<Type>(TypeService.loadTypes());
Type type = list.get(0);
return list;
}
编辑:如果我删除@Version
注释