2013-03-20 74 views
0

我有我想與JPA找不到實體

CREATE TABLE translations (
id SERIAL NOT NULL, 
KEY VARCHAR(255), 
LANGUAGE VARCHAR(255), 
TRANSLATION VARCHAR(255) 
) 

使用我創造了這個實體此數據表:

@Entity 
@Table(name = "translations") 
public class TranslationTestEntitie extends AbstractEntityWithId { 

    private static final long serialVersionUID = 2029240552230401080L; 

    @Column(name = "id", insertable=false, updatable=false) 
    private long id; 
    @Column(name = "key", insertable=false, updatable=false) 
    private String key; 
    @Column(name = "language", insertable=false, updatable=false) 

    private String language; 
    @Column(name = "translation", insertable=false, updatable=false) 
    private String translation; 

    public TranslationTestEntitie() { 
    } 

    // Getters and setters 
    public Long getId() { 
     return id; 
    } 

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

    public String getKey() { 
     return key; 
    } 

    public void setKey(String key) { 
     this.key = key; 
    } 

    public String getLanguage() { 
     return language; 
    } 

    public void setLanguage(String language) { 
     this.language = language; 
    } 

    public String getTranslation() { 
     return translation; 
    } 

    public void setTranslation(String translation) { 
     this.translation = translation; 
    } 

} 

當我試圖讓這個查詢SELECT c FROM Translations c WHERE c.Id = 70

我得到這個消息The abstract schema type 'Translations' is unknown.

這個權利根據t數據庫表。

P.S這是我用它來獲取數據的代碼:

public TData td; 

    public class TData { 

     private long id; 
     private String key; 
     private String language; 
     private String translation; 

     public TData() { 
     }; 

     public TData(long id, String key, String language, String translation) { 
      // super(); 
      this.id = id; 
      this.key = key; 
      this.language = language; 
      this.translation = translation; 
     } 

     public long getId() { 
      return id; 
     } 

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

     public String getKey() { 
      return key; 
     } 

     public void setKey(String key) { 
      this.key = key; 
     } 

     public String getLanguage() { 
      return language; 
     } 

     public void setLanguage(String language) { 
      this.language = language; 
     } 

     public String getTranslation() { 
      return translation; 
     } 

     public void setTranslation(String translation) { 
      this.translation = translation; 
     } 

    } 

    public TData getDataObj() { 
     return td; 
    } 

    @PostConstruct 
    public void loadData() { 

     td = new TData(); 

     String query = "SELECT c FROM Translations c WHERE c.id = 70"; 
     td = (TData) dao.jpqlQuerySingle(query);//(query);//jpqlQuery(query); 

    } 

但是我還是空的對象。

+0

您是否已經手動創建了該實體?爲什麼不使用netbeans/eclipse來使用數據庫表結構來生成這個? – pepuch 2013-03-20 10:28:51

+1

你如何嘗試查詢?如何註冊您的實體類型? – 2013-03-20 10:29:02

+0

你可以發佈請求數據庫的代碼嗎? – benzonico 2013-03-20 10:29:17

回答

1

也許是因爲你的表名不是Translations而是translations

SELECT c FROM translations c WHERE c.id = 70 

和小寫的id。

+0

但是這是JPQL,所以它應該是實體名稱而不是表名,按照JPA規範 – DataNucleus 2013-03-20 11:59:29

2

映射到您的translations數據庫表的實體被命名爲TranslationTestEntitie

from TranslationTestEntitie c應該適合您的需求。