Hibernate-在实体字段上应用操作的注释?

发布于 2025-01-26 20:17:40 字数 823 浏览 2 评论 0原文

我有以下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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文