0

I have this DB table which I want to use with JPA

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

I created this entity:

@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; } } 

When I try to make this query SELECT c FROM Translations c WHERE c.Id = 70

I get this message The abstract schema type 'Translations' is unknown.

Is this entitie correct according to the DB table.

P.S This is the code that I use to get the data:

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); } 

But I still get empty Object.

3
  • Have you created this entity manually? Why not to use netbeans/eclipse to generate this using database table structure? Commented Mar 20, 2013 at 10:28
  • 1
    How do you try to make that query? How to you register your entity type? Commented Mar 20, 2013 at 10:29
  • can you post the code that request the db ? Commented Mar 20, 2013 at 10:29

2 Answers 2

2

The entity mapped to your translations database table has been named TranslationTestEntitie.

from TranslationTestEntitie c should then suit your needs.

Sign up to request clarification or add additional context in comments.

Comments

1

Maybe because your table name is not Translations but translations.

SELECT c FROM translations c WHERE c.id = 70 

And id with lowercase.

1 Comment

but then this is JPQL so it should be the entity name not table name, as per the JPA spec

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.