-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Probleme beim Auslesen
PostPosted: Tue Nov 14, 2006 4:52 am 
Newbie

Joined: Tue Nov 14, 2006 4:39 am
Posts: 2
Hallo Alle
Ich bin noch ganz frisch was Hibernate betrifft und wollte mal eine kleine Testanwendung ausprobieren, die im Prinzip nichts anders macht als eine kleine Tabelle zu befüllen, was auch einwandfrei funktioniert, und die Daten dann wieder ausließt, was leider nicht funktioniert (siehe Exception).
Das Beispiel Programm hab ich aus der "Hibernate Reference Documentation 3.1.1".
Hat vielleicht jemand eine Idee, warum mein List nicht funktioniert, bin im Moment leider etwas ratlos.


Hibernate version:
3

Mapping documents:
Code:
<hibernate-mapping>
   <class name="events.Event" table="EVENTS">
      <id name="id" column="EVENT_ID">
         <generator class="native" />
      </id>
      <property name="date" type="timestamp" column="EVENT_DATE" />
      <property name="title" />
   </class>
</hibernate-mapping>


Code:
Code:
package events;

import java.util.Date;
import java.util.List;

import org.hibernate.Session;

import util.HibernateUtil;

public class EventManager {
  public static void main(String[] args) {
    EventManager mgr = new EventManager();
    if (args[0].equals("store")) {
      mgr.createAndStoreEvent("My Event", new Date());
    }
    else if (args[0].equals("list")) {
      List events = mgr.listEvents();
      for (int i = 0; i < events.size(); i++) {
        Event theEvent = (Event) events.get(i);
        System.out.println("Event: " + theEvent.getTitle() + " Time: "
            + theEvent.getDate());
      }
    }
    HibernateUtil.getSessionFactory().close();
  }

  private void createAndStoreEvent(String title, Date theDate) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();
    Event theEvent = new Event();
    theEvent.setTitle(title);
    theEvent.setDate(theDate);
    session.save(theEvent);
    session.getTransaction().commit();
  }

  private List listEvents() {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();
    List result = session.createQuery("from Event e").list();
    session.getTransaction().commit();
    return result;
  }
}


Full stack trace of any exception that occurs:
Code:
     [java] Exception in thread "main" java.lang.reflect.UndeclaredThrowableException
     [java] at $Proxy0.createQuery(Unknown Source)
     [java] at events.EventManager.listEvents(Unknown Source)
     [java] at events.EventManager.main(Unknown Source)
     [java] Caused by: java.lang.reflect.InvocationTargetException
     [java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     [java] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
     [java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
     [java] at java.lang.reflect.Method.invoke(Method.java:585)
     [java] at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:301)
     [java] ... 3 more
     [java] Caused by: java.lang.NoClassDefFoundError: antlr/ANTLRException
     [java] at org.hibernate.hql.ast.ASTQueryTranslatorFactory.createQueryTranslator(ASTQueryTranslatorFactory.java:35)
     [java] at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:74)
     [java] at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:56)
     [java] at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72)
     [java] at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
     [java] at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)
     [java] at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1623)
     [java] ... 8 more
     [java] Java Result: 1


Ant File:
Code:
<project name="hibernate-tutorial" default="compile">
   <property name="sourcedir" value="${basedir}/src" />
   <property name="targetdir" value="${basedir}/bin" />
   <property name="librarydir" value="${basedir}/lib" />
   <path id="libraries">
      <fileset dir="${librarydir}">
         <include name="*.jar" />
      </fileset>
   </path>
   <target name="clean">
      <delete dir="${targetdir}" />
      <mkdir dir="${targetdir}" />
   </target>
   <target name="compile" depends="clean, copy-resources">
      <javac srcdir="${sourcedir}" destdir="${targetdir}" classpathref="libraries" />
   </target>
   <target name="copy-resources">
      <copy todir="${targetdir}">
         <fileset dir="${sourcedir}">
            <exclude name="**/*.java" />
         </fileset>
      </copy>
   </target>
   <target name="run" depends="compile">
      <java fork="true" classname="events.EventManager" classpathref="libraries">
         <classpath path="${targetdir}" />
         <arg value="${action}" />
      </java>
   </target>
</project>


Name and version of the database you are using:
HSQLDB

mfG und vielen Dank
Corpse

_________________
Mind your Head!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 14, 2006 5:14 am 
Expert
Expert

Joined: Tue Dec 07, 2004 6:57 am
Posts: 285
Location: Nürnberg, Germany
Dir fehlen die antlr Jars im Classpath:

Quote:
Caused by: java.lang.NoClassDefFoundError: antlr/ANTLRException


Schau mal in die readme datei des lib Verzeichnisses. Dort ist genau dokumentiert welche jars du benötigst.

_________________
Please don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 14, 2006 5:37 am 
Newbie

Joined: Tue Nov 14, 2006 4:39 am
Posts: 2
Ah, super, funktioniert. Hatte die falsche jar eingebunden.
Vielen Dank!

_________________
Mind your Head!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.