Ich habe ein Problem mit Hibernate Version 3 und Annotations.
Wenn ich meine Testklasse über die alten hbm-Files mappe, klappt alles wunderbar. Ich kann meine Querys absetzten und bekomme keine Fehler. Nun habe ich versucht meine Klasse (eine ID und ein Textfeld) über Annotations zu mappen.
Das ganze funktioniert solange, solange ich keine Query ausführe. Das connecten usw. haut alles hin. Nur bei der Query kommt er dann nicht weiter, da er meine annotierte Klasse nicht finden kann.
Klasse:
Code:
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;
}
}
Und hier ist meine Auslese-Logik
Code:
try
{
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" );
tx.commit();
s.close();
}catch(Exception e)
{
e.printStackTrace();
}
Hibernate-Config sieht so aus:
Code:
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.url">jdbc:mysql://192.168.2.1/diplomarbeit</property>
<property name="connection.username">thomas</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="connection.password">a9p8pabf</property>
<property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<property name="current_session_context_class">thread</property>
<property name="hibernate.show_sql">true</property>
<mapping package="hibernate"/>
</session-factory>
</hibernate-configuration>
Exception
org.hibernate.hql.ast.ASTQueryTranslatorFactory.createQueryTranslator
(ASTQueryTranslatorFactory.java:35)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:72)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:54)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCa
che.java:71)
at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessio
nImpl.java:133)
at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImp
l.java:112)
at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1583)
at hibernate.HibernateUtil.doTest(Unknown Source)
at org.apache.jsp.test_jsp._jspService(test_jsp.java:59)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper
.java:334)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:3
14)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:173)
at org.apache.shale.faces.ShaleApplicationFilter.doFilter(ShaleApplicati
onFilter.java:268)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
a:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
:869)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.p
rocessConnection(Http11BaseProtocol.java:664)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpo
int.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFol
lowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadP
ool.java:684)
at java.lang.Thread.run(Unknown Source)
Wäre echt super, wenn mir hier wer helfen würde. Bin schon mehr als verzweifelt, weil ich einfach keinen Fehler finde.
Danke!
Thomas