Connected to the project persistence.xml , gives an error:

 org.hibernate.hql.internal.ast.QuerySyntaxException: table is not mapped 

Here is the persistence:

 <persistence> <persistence-unit name="jsfProject"> <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider> <class>entity.models.UserProfile</class> <properties> <property name="hibernate.connection.url" value="jdbc:mysql://sfmnew.amadeus.kz:54001/temp_autoparser"/> <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/> <property name="hibernate.connection.username" value="autoparser_user"/> <property name="hibernate.connection.password" value="autoparser_user03022016"/> <property name="hibernate.archive.autodetection" value="class"/> <property name="hibernate.show_sql" value="true"/> <property name="hibernate.format_sql" value="true"/> <property name="hbm2ddl.auto" value="update"/> </properties> </persistence-unit> </persistence> 

here is the class that describes the table

 import javax.persistence.*; import java.io.Serializable; @Entity @Table(name="post") public class UserProfile implements Serializable{ @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "id", updatable = false, nullable = false) private Long id = null; @Column(name="body") private String body; public Long getId() { return this.id; } public void setId(final Long id) { this.id = id; } public String getBody() { return body; } public void setBody(String body) { this.body = body; } } EntityManagerFactory emf=Persistence.createEntityManagerFactory("jsfProject"); Query q=emf.createEntityManager().createQuery("select body from post"); 
  • It would be nice to see the HQL request. - enzo
  • @enzo, EntityManagerFactory emf = Persistence.createEntityManagerFactory ("jsfProject"); Query q = emf.createEntityManager (). CreateQuery ("select body from post"); - andy

1 answer 1

When you write HQL, you are not referring to a table (this is not SQL), but to an entity. By default, the entity name matches the class name.

createQuery("select p.body from UserProfile p")