首页 文章

使用Hibernate映射组合键会在Oracle中生成原始字段

提问于
浏览
0
  • The Facts ....
    在我的项目中,每个类/表都应该有一对(站点,结构),以便提供多站点部署 .

我提供了一个安装类

@Entity
@Table(name="COM_INSTALLATION")
@IdClass(InstallationPK.class)
public class Installation implements Serializable{

private static final long serialVersionUID = 3601006283578715263L;

@Id
@Column(name = "site") 
private String site;
@Id
@Column(name = "structure")
private String structure;

/* ... constructor, getters, setters ... */
}

和它的PK,如

public class InstallationPK implements Serializable {

private static final long serialVersionUID = 1L;
private String site;
private String structure;
/* .. constructor, getters, setters ... */
}

然后我有一个名为BaseEntity的MappedSuperclass

@MappedSuperclass
public class BaseEntity
{
private Installation installation;

@OneToOne
@JoinColumns({    
    @JoinColumn(name = "site", referencedColumnName = "site"),
    @JoinColumn(name = "structure", referencedColumnName = "structure")
})
public Installation getInstallation() {
    return installation;
}
public void setInstallation(Installation installation) {
    this.installation = installation;
}
}

到目前为止很容易...每个@Entity和@Table注释类扩展BaseEntity包含一个列SITE,一个列STRUCTURE和一个相关的外键 .
enter image description here

  • The Problem ....
    实际上,通过实现org.springframework.security.core.userdetails.UserDetails并扩展BaseEntity的类,Hibernate不会创建两列,而是创建具有RAW类型的INSTALLATION列 . 那是 class
@Entity
@Table(name="USR_USER", uniqueConstraints =    
@UniqueConstraint(columnNames = { "username" }))
@SequenceGenerator(name = "userId_seq_generator", sequenceName = "S_USER")
public class User  extends BaseEntity implements UserDetails{

private static final long serialVersionUID = 8698408700004341649L;

@Id
@GeneratedValue(strategy = GenerationType.AUTO, generator = "userId_seq_generator")
private Long userId;
/* ... getter, setters, ... */
}

这就是结果
enter image description here

有任何想法吗?提前致谢

1 回答

  • 0

    我没有评论点的声誉,所以我会在这里发表评论:

    为什么instalationPK字段不在instalation.class中?您应该将 @EmbeddedId 放在Installation.class中的字段instalationPK中 .

    如果有差异,我不会,但是在 BaseEntity 中的字段上放入joinCollums:

    @OneToOne
    @JoinColumns({    
        @JoinColumn(name = "site", referencedColumnName = "site"),
        @JoinColumn(name = "structure", referencedColumnName = "structure")
    })
    private Installation installation;
    

相关问题