2016-11-27 70 views
0

我有一個TestEntity,並且此實體可​​以具有父TestEntity。 Spring數據JPA說無法確定類型:abc.entity.TestEntity,在表:test_entity,爲列:[org.hibernate.mapping.Column(parent)],我該如何解決這個問題?沒有在互聯網上找到任何東西,或者我搜索了錯誤的東西。Spring Data JPA無法確定屬於同一類對象的屬性的類型

package abc.entity; 

import javax.persistence.Entity; 
import javax.persistence.GeneratedValue; 
import javax.persistence.GenerationType; 
import javax.persistence.Id; 

@Entity 
public class TestEntity { 
    @Id 
    @GeneratedValue(strategy = GenerationType.AUTO) 
    private long id; 

    private String name; 

    private TestEntity parent; 

    public TestEntity(String name, TestEntity parent) { 
     this.name = name; 
     this.parent = parent; 
    } 

    public long getId() { 
     return id; 
    } 

    public String getName() { 
     return name; 
    } 

    public TestEntity getParent() { 
     return parent; 
    } 
} 

回答

0

好像你已經得到多個TestEntity類與一個包abc.entity.TestEntity和其他與tud.swt16w2.entity包。

所以import正確的實體類,即import tud.swt16w2.entity.TestEntity爲您的存儲庫類進口的一部分。

+0

答案不,我不是,我只是錯誤地編輯的計算器包名。我修好了,謝謝! – phip1611

0

在父母字段上使用@ManyToOne@JoinColumn(name = "parent_id")

0

這不是Spring Data JPA抱怨,而是Hibernate,底層OR映射器。如果您建模與實體的關係(無論它是相同類型還是不同實體),您需要確定關係的基數,即或者用@OneToOne@ManyToOne對其進行註釋,具體取決於您希望實現哪種語義。

1

您必須將@OneToOne@ManyToOne放在parent上。

此外,您應提供無參數構造函數。

順便說一下,它不是彈簧數據,但JPA提供商誰給你的錯誤。

這個問題已經在這裏JPA inheritance Could not determine type for

相關問題