java - 对于映射到数据库表的 bean,hibernate 中的默认继承策略是什么?

标签 java hibernate jpa

这是我在 stackoverflow 中的第一个查询,我想我提供了所有必要的输入:

我在下面提供了我的 Java bean 和数据库表的详细信息:

******Java Bean 类:***

import java.sql.Timestamp;

import javax.persistence.Column;

import javax.persistence.Entity;

import javax.persistence.Id;

import javax.persistence.Table;

@Entity

@Table(name = "BANK_MESSAGES")

public class messagesBean implements Serializable

{

    @Id
    @Column(name="msg_id")
    private String msg_id;

    @Column(name="msg_date")
    Timestamp msgDateTime;

    @Column(name="message")
    private byte[] message;

    @Column(name="msg_type")
    private String msg_type;

    //Getters and Setters for the above fields
}

下面是我的数据库表 (Oracle) 的 DDL:

create table BANK_MESSAGES
(msg_id varchar2(10),
msg_date timestamp,
message blob,
msg_type varchar2(5)) ;

我想了解像上面这样映射到数据库表的 bean 在 hibernate 中的默认继承策略是什么?

最佳答案

如果您只有一个实体而没有任何子类,那么继承是无关紧要的。

否则,the javadoc有答案:

Annotation Type Inheritance

@Target(value=TYPE)
@Retention(value=RUNTIME)
public @interface Inheritance

Defines the inheritance strategy to be used for an entity class hierarchy. It is specified on the entity class that is the root of the entity class hierarchy. If the Inheritance annotation is not specified or if no inheritance type is specified for an entity class hierarchy, the SINGLE_TABLE mapping strategy is used.

(强调我的)。

关于java - 对于映射到数据库表的 bean,hibernate 中的默认继承策略是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31746666/

相关文章:

java - 部署war包后tomcat的webapps目录下多了很多.aut文件

java - 为什么这种类型的通配符不起作用?

java - Hibernate Session 方法 saveOrUpdate() 和 merge() 之间有什么区别?

java - 如何在 postgres 中没有时区的情况下节省时间。我正在使用 hibernate Spring MVC

hibernate - 如何在tomcat上使用maven在spring MVC中集成apache solr

java - 将 JPA 注释添加到字段与 getter 之间有什么区别?

java - 使用 Spring 批处理处理大文件的最佳方法

java - 不将字符串列表作为单个参数传递给 preparedStatement.setObject()

java - Guice 合成方法警告

jpa - 具有应用程序管理的持久性上下文的Spring Boot