没有为entity指定标识符:content.ContentType

时间:2015-12-06 07:44:30

标签: java hibernate jpa

我有两个表,ContentContentType

每个内容都有一种内容类型

每种内容类型可能包含许多内容。

这是我的模特:

@Entity
@Table(name = "content")
public class Content implements Serializable {

public Content() {}

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
private long id;

@ManyToOne
private ContentType contentType;

@NotNull
private String title;

//getter/setters }

ContentType上课:

@Entity
@Table(name = "contentType")
public class ContentType implements Serializable {

    public ContentType() {  }

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    private long id;

    @NotNull
    private String type;

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "content")
    private Set<Content> content;
//getter/setters }

但我得到了这个例外:

No identifier specified for entity: content.ContentType

2 个答案:

答案 0 :(得分:1)

尝试进行以下更改。

mappedBy应指向ContentType类中Content对象的名称。

@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "contentType")
private Set<Content> content;

希望这有帮助。

答案 1 :(得分:0)

setInterval(function(){ var date = new Date(); var dateFormat = date.getFullYear() + "-" + ("0" + date.getMonth()).slice(-2) + "-" + ("0" + date.getDate()).slice(-2) + " " + ("0" + date.getHours()).slice(-2) + ":" + ("0" + date.getMinutes()).slice(-2) + ":" + ("0" + date.getSeconds()).slice(-2); var claimObj = { first_author : $('#first_author').val(), authors : $('#authors').val(), publication_title : $('#publication_title').val(), source : $('#source').val(), publication_submitted : $('#publication_submitted :selected').val(), research_bank_number : $('#research_bank_number').val(), research_code_1 : $('#research_code_1 :selected').val(), research_code_2 : $('#research_code_2 :selected').val(), research_code_3 : $('#research_code_3 :selected').val(), issn : $('#issn').val(), type_of_publication : $('#type_of_publication :selected').val(), claim_type : $('input[name="claim_type"]').val(), claim_author : $('input[name="claim_author"]').val(), claim_date : dateFormat, user_id : $('input[name="user_id"]').val() }; var json_data = JSON.stringify(claimObj); var className; $.post("autoSavePublicationDetails", { '<?php echo $this->security->get_csrf_token_name(); ?>':'<?php echo $this->security->get_csrf_hash(); ?>', 'json' : json_data, 'claim_id' : $('#claim_id').val() }, function(data,status){ console.log("Status: " + status); var jsonReturn = $.parseJSON(data); alert(jsonReturn.message); if (jsonReturn.message == "Success") { className = 'label label-success'; $('#message').addClass(className); $('#message').text('Data saved.'); } else { className = 'label label-danger'; $('#message').addClass(className); $('#message').text('Form not saved.'); } $('#message').fadeIn(); setTimeout(function() { $('#message').fadeOut(); $('message').removeClass() }, 1000); }); }, 10000); 表格中添加@manyToOne注释(使用getter / setter)