休眠状态下,映射到数据库表的Bean的默认继承策略是什么? [英] What is the default Inheritance strategy in hibernate for a bean mapped to a database table?

查看:61
本文介绍了休眠状态下,映射到数据库表的Bean的默认继承策略是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

This is my first query in stackoverflow and I think I am providing all my necessary inputs:

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

I have provided my Java bean and the database table details below:

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

******Java Bean Class:***

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:

Below is the DDL for my Database Table (Oracle):

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

我试图了解休眠状态下对于映射到上述数据库表的bean的默认继承策略是什么?

I am trying to understand what is the default Inheritance strategy in hibernate for a bean mapped to a database table like above ?

推荐答案

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

If you just have one entity without any subclass, inheritance is irrelevant.

否则, javadoc 有答案:

注释类型Inheritance

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

定义用于实体类层次结构的继承策略.它是在实体类上指定的,该实体类是实体类层次结构的根. 如果未指定继承注释,或者未为实体类层次结构指定继承类型,则使用SINGLE_TABLE映射策略..

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.

(重点是我的).

这篇关于休眠状态下,映射到数据库表的Bean的默认继承策略是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆