New to Hibernate
by Thomas Walland
Hi,
I am new to hibernate and I wanted to try out this way of java
persistence.
I downloaded hibernate 3 and the hibernate annotation libraries.
I made a little project in which i want to select * from a database.
When I realize this in "the old-way" with hibernate mapping files, it
workes fine.
But when I applay the Version with Java-Annotations, I always get an
error message, which says, that my bean is not mapped or something in
this way. If I comment out the line with the query, everthing works
fine. So the set up seems to be ok. But the query doesn't work.
Here is my Annotated class:
----
package hibernate;
import javax.persistence.*;
import java.io.Serializable;
@Entity()
@Table (name="testtable")
public class ExampleDAO implements Serializable {
@Basic
@Id
public int id;
@Basic
public String name;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
---
and here is the query-code:
AnnotationConfiguration cfg = new AnnotationConfiguration();
cfg.configure( "../../etc/conf/hibernate.cfg.xml" );
SessionFactory sf = cfg.buildSessionFactory();
Session s = sf.openSession();
Transaction tx = s.beginTransaction();
Query q = s.createQuery( "from ExampleDAO" ); << Expection
tx.commit();
s.close();
--
I hope i expressed my problem clearly.
Thanks,
Thomas
18 years, 1 month