休眠设置Foreign_key字段,但返回null

时间:2019-02-06 11:17:05

标签: eclipse hibernate null

我正在使用hibernate通过@ManyToOne将一个对象映射到另一个对象。 我可以完美地在休眠状态下查询引用的表,并使用它来填充下拉列表。 Hibernate在我的MySQL数据库中正确设置了外键,但是当我再次查询相同的项目时,即使它仍填充在数据库中,它也会返回null。

我尝试过的事情:

  • 创建静态元模型类
  • 重命名getter和setter
  • 还已经将该类添加到了我的hibernate.cfg.xml文件中

参考课程:

@Entity
@Table(name = "\"sequence_themes\"")
@BeanConfig(name = "theme", article = "de")
public class Theme {

    private static final Logger logger = LoggerFactory.getLogger(Theme.class);

    @Id
    private String id;

    private String name;

    private String description;

    private String primary_color_1;

    @Column(name = "\"id\"")
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    @Column(name = "\"name\"")
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Column(name = "\"description\"")
    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    @Column(name = "\"primary_color_1\"")
    public String getPrimary_color_1() {
        return primary_color_1;
    }

    public void setPrimary_color_1(String primary_color_1) {
        this.primary_color_1 = primary_color_1;
    }

基类:

@Entity
@Table(name = "\"x_sequences_and_contents\"", uniqueConstraints = {
        @UniqueConstraint(columnNames = { "\"sequence_id\"", "\"order\"" })
})
@BeanConfig(article = "de", name = "inhoud")
public class SequenceItem implements Serializable, Comparable<SequenceItem> {

    // omitted

    private Theme thema;

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "\"theme_id\"")
    public Theme getThema() {
        return thema;
    }

    public void setThema(Theme thema) {
        this.thema = thema;
    }

    // omitted

0 个答案:

没有答案