Quote:
To make a long story short, you're trying to write standard SQL code where you should be using Hibernate's HQL or standard JPA-QL - both are shortened query languages for querying your entity classes, not database tables.
The idea is to abstract your database w/ entities...so you're working w/ objects, not tables, i.e. object graphs vs. relational data.
You'll find once you start building apps this way, it's much, much easier to manage and maintain them.
Read through the chapters in your book about Hibernate Query Language and JPA Query Language....this should help clear things up.
Well, that certainly helps to clear things up a bit. In the HelloWorld example the authors just provide a couple of test programs which have queries in them (which look just like SQL) but don't explain they they aren't really. That is they don't go into any great depth of explanation. I just assumed we continued to use SQL queries!
I tried changing the query to "select c from COMPANY c" but I'm still getting this silly exception:
[java] Exception in thread "main" java.lang.IllegalArgumentException: org.h
ibernate.hql.ast.QuerySyntaxException: COMPANY is not mapped [select c from COMPANY c]
[java] at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:616)
[java] at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:95)
[java] at scholastic.models.Test.main(Unknown Source)
What does it mean it's not mapped? Of course it is. I proved that is was earlier:
Code:
package scholastic.models;
//import org.hibernate.annotations.*;
import javax.persistence.*;
import java.io.Serializable;
import java.util.*;
@Entity
@Table(name = "COMPANIES")
public class Company implements Serializable
{
@Id @GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "COMPANY_ID")
private Long id = null;
...
}
What does it really want me to do?
Alan