Hibernate-在实体字段上应用操作的注释?
我有以下Java实体
@Table(name = "some_table", schema = "some_schema")
public class SomeEntity{
@Id
@Generated(value = GenerationTime.INSERT)
@Column(name = "id", unique = true)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Size(min = 0, max = 255)
@Column(name = "node", nullable = false, length = 20)
private String node;
}
node
属性是hierarchicalId
类型。 当我创建一个新的某种范围
实例时,使用node
value'/1/1/'创建一个时,它可以正常工作。 但是,我想注释node
字段,以便每次选择
查询,它将选择node.tostring()
> (要获取node
属性的可读字符串表示),而不是选择节点
。
选择节点
返回X而不是'/1/',我想获得'/1/'而不是x。 我该怎么做? 可以在不使用本机查询的情况下实现这一目标吗? 感谢您的帮助。
I have the following JAVA entity
@Table(name = "some_table", schema = "some_schema")
public class SomeEntity{
@Id
@Generated(value = GenerationTime.INSERT)
@Column(name = "id", unique = true)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Size(min = 0, max = 255)
@Column(name = "node", nullable = false, length = 20)
private String node;
}
the node
property is a HierarchicalId
type.
When I create a new SomeEntity
instance, with a node
value '/1/1/', it works fine.
However, I'd like to annotate the node
field so that everytime a SELECT
query is made, it will select the node.ToString()
(to get the readable string representation of the node
property) instead of SELECT node
.
The SELECT node
returns X instead of '/1/' and I would like to get '/1/' instead of X.
How can I do that ?
Is that possible to achieve that without using native query ?
Thanks for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论