gpt4 book ai didi

java - JPA Hibernate 类型定义

转载 作者:行者123 更新时间:2023-12-02 00:22:55 24 4
gpt4 key购买 nike

在项目中,我使用 JPA 和 Hibernate 实现。所有实体都是基于注释的,并在 persistence.xml 中列出。

所有实体都打包到jar中。

我需要为几个属性(在所有实体中)定义一个 typedef,这些属性是枚举类型的字符串。在数据库中,列是varchar。我怎样才能实现这个目标?

我可以通过添加 hbm.xml 和 hibernate-cfg.xml 来实现此目的吗?

提前致谢。

最佳答案

直接来自the documentation :

@org.hibernate.annotations.TypeDef and @org.hibernate.annotations.TypeDefs allows you to declare type definitions. These annotations can be placed at the class or package level. Note that these definitions are global for the session factory (even when defined at the class level). If the type is used on a single entity, you can place the definition on the entity itself. Otherwise, it is recommended to place the definition at the package level.

关于java - JPA Hibernate 类型定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10598396/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com