-->
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.  [ 5 posts ] 
Author Message
 Post subject: Problems with example Hello world messages
PostPosted: Wed Feb 27, 2008 7:10 pm 
Newbie

Joined: Wed Feb 27, 2008 6:13 pm
Posts: 3
Hibernate version: hibernate-3.2.6.ga

Hello everyone, new to Hibernet and a little stuck.

Im following the example in the book "java persistence with hibernate" and the reference manual example
but i get an Exception when i try to get the List (with "from Messages" query)
of Messages from the table.

here is the code where the list is called

Code where the exception occours
Code:
      Session session = HibernateUtil.getSessionFactory().getCurrentSession();
        session.beginTransaction().begin();
        List messages = null;
        try {
            messages = session.createQuery("from hello.Message").list(); //this throws Exception
            //messages = session.createCriteria(Message.class).list(); //this works
            System.out.println(messages.size() + " messages(s) found");
        } catch (Exception ex){
            ex.printStackTrace();
        }
        session.getTransaction().commit();


Exception that occurs:
Code:
16:07:59,007 DEBUG ThreadLocalSessionContext:300 - allowing proxied method [createQuery] to proceed to real session
      16:07:59,222 DEBUG QueryPlanCache:70 - unable to locate HQL query plan in cache; generating (from Message)
      08/02/27 16:08:01 java.lang.NullPointerException
      08/02/27 16:08:01    at java.lang.Class.forName0(Native Method)
      08/02/27 16:08:01    at java.lang.Class.forName(Class.java:164)
      08/02/27 16:08:01    at antlr.CharScanner.setTokenObjectClass(CharScanner.java:337)
      08/02/27 16:08:01    at org.hibernate.hql.ast.HqlLexer.setTokenObjectClass(HqlLexer.java:31)
      08/02/27 16:08:01    at antlr.CharScanner.<init>(CharScanner.java:51)
      08/02/27 16:08:01    at antlr.CharScanner.<init>(CharScanner.java:60)
      08/02/27 16:08:01    at org.hibernate.hql.antlr.HqlBaseLexer.<init>(HqlBaseLexer.java:56)
      08/02/27 16:08:01    at org.hibernate.hql.antlr.HqlBaseLexer.<init>(HqlBaseLexer.java:53)
      08/02/27 16:08:01    at org.hibernate.hql.antlr.HqlBaseLexer.<init>(HqlBaseLexer.java:50)
      08/02/27 16:08:01    at org.hibernate.hql.ast.HqlLexer.<init>(HqlLexer.java:26)
      08/02/27 16:08:01    at org.hibernate.hql.ast.HqlParser.getInstance(HqlParser.java:44)
      08/02/27 16:08:01    at org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:242)
      08/02/27 16:08:01    at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:157)
      08/02/27 16:08:01    at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:111)
      08/02/27 16:08:01    at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:77)
      08/02/27 16:08:01    at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:56)
      08/02/27 16:08:01    at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72)
      08/02/27 16:08:01    at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
      08/02/27 16:08:01    at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)
      08/02/27 16:08:01    at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1623)
      08/02/27 16:08:01    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      08/02/27 16:08:01    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      08/02/27 16:08:01    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      08/02/27 16:08:01    at java.lang.reflect.Method.invoke(Method.java:585)
      08/02/27 16:08:01    at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:301)
      08/02/27 16:08:01    at $Proxy0.createQuery(Unknown Source)
      08/02/27 16:08:01    at backing.Backing_main.main(Backing_main.java:24)
      08/02/27 16:08:01    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      08/02/27 16:08:01    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      08/02/27 16:08:01    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      08/02/27 16:08:01    at java.lang.reflect.Method.invoke(Method.java:585)
      08/02/27 16:08:01    at com.sun.faces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:126)
      08/02/27 16:08:01    at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:72)
      08/02/27 16:08:01    at oracle.adf.view.faces.component.UIXCommand.broadcast(UIXCommand.java:211)
      08/02/27 16:08:01    at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:267)
      08/02/27 16:08:01    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:381)
      08/02/27 16:08:01    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:75)
      08/02/27 16:08:01    at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
      08/02/27 16:08:01    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:90)
      08/02/27 16:08:01    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)
      08/02/27 16:08:01    at com.evermind.server.http.ResourceFilterChain.doFilter(ResourceFilterChain.java:64)
      08/02/27 16:08:01    at oracle.adfinternal.view.faces.webapp.AdfFacesFilterImpl._invokeDoFilter(AdfFacesFilterImpl.java:367)
      08/02/27 16:08:01    at oracle.adfinternal.view.faces.webapp.AdfFacesFilterImpl._doFilterImpl(AdfFacesFilterImpl.java:336)
      08/02/27 16:08:01    at oracle.adfinternal.view.faces.webapp.AdfFacesFilterImpl.doFilter(AdfFacesFilterImpl.java:196)
      08/02/27 16:08:01    at oracle.adf.view.faces.webapp.AdfFacesFilter.doFilter(AdfFacesFilter.java:87)
      08/02/27 16:08:01    at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:629)
      08/02/27 16:08:01    at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:376)
      08/02/27 16:08:01    at com.evermind.server.http.HttpRequestHandler.doProcessRequest(HttpRequestHandler.java:870)
      08/02/27 16:08:01    at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:451)
      08/02/27 16:08:01    at com.evermind.server.http.HttpRequestHandler.serveOneRequest(HttpRequestHandler.java:218)
      08/02/27 16:08:01    at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:119)
      08/02/27 16:08:01    at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:112)
      08/02/27 16:08:01    at oracle.oc4j.network.ServerSocketReadHandler$SafeRunnable.run(ServerSocketReadHandler.java:260)
      08/02/27 16:08:01    at oracle.oc4j.network.ServerSocketAcceptHandler.procClientSocket(ServerSocketAcceptHandler.java:230)
      08/02/27 16:08:01    at oracle.oc4j.network.ServerSocketAcceptHandler.access$800(ServerSocketAcceptHandler.java:33)
      08/02/27 16:08:01    at oracle.oc4j.network.ServerSocketAcceptHandler$AcceptHandlerHorse.run(ServerSocketAcceptHandler.java:831)
      08/02/27 16:08:01    at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:303)
      08/02/27 16:08:01    at java.lang.Thread.run(Thread.java:595)


classes
Code:
public class Message{
          private Long id;
          private String text;
          private Message nextMessage;
         ..
         //setters & getters...
      }


Mapping documents:
Message
Code:
<hibernate-mapping>
        <class name="hello.Message" table="MESSAGES">
          <id name="id" column="MESSAGE_ID">
            <generator class="increment"/>
          </id>
          <property name="text" column="MESSAGE_TEXT"/>
          <many-to-one name="nextMessage" cascade="all" column="NEXT_MESSAGE_ID"
                       foreign-key="FK_NEXT_MESSAGE"/>
        </class>
      </hibernate-mapping>

Hibernate Configuration
Code:
<!-- Database connection settings -->
        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="connection.url">jdbc:mysql://localhost/eventos_schema</property>
        <property name="connection.username">XYZ</property>
        <property name="connection.password">XYZ</property>

        <!-- JDBC connection pool (use the built-in) -->
        <property name="connection.pool_size">1</property>
        <!-- SQL dialect -->
        <property name="dialect">org.hibernate.dialect.MySQL5Dialect</property>
        <!-- Enable Hibernate's automatic session context management -->
        <property name="current_session_context_class">thread</property>
        <!-- Disable the second-level cache  -->
        <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
        <!-- Echo all executed SQL to stdout -->
        <property name="show_sql">true</property>
        <property name="format_sql">true</property>
        <!-- Drop and re-create the database schema on startup -->
        <!-- <property name="hbm2ddl.auto">create</property> -->   

        <mapping resource="hello/Message.hbm.xml"/>      



so what im missing ? i added all the jars in the lib directory in hibernate-3.2.6.ga.zip

also tryed the code tutorial y the hibernate /doc/tutorial

Code:
//List result = session.createCriteria(Event.class).list();  // this works
        List result = session.createQuery("from Event").list();  // this throws the exception
      
      Caused by: java.lang.NullPointerException   
      at java.lang.Class.forName0(Native Method)   
      at java.lang.Class.forName(Class.java:164)   
      at antlr.CharScanner.setTokenObjectClass(CharScanner.java:337)   
      at org.hibernate.hql.ast.HqlLexer.setTokenObjectClass(HqlLexer.java:31)   
      at antlr.CharScanner.<init>(CharScanner.java:51)   
      at antlr.CharScanner.<init>(CharScanner.java:60)   
      at org.hibernate.hql.antlr.HqlBaseLexer.<init>(HqlBaseLexer.java:56)   
      at org.hibernate.hql.antlr.HqlBaseLexer.<init>(HqlBaseLexer.java:53)   
      at org.hibernate.hql.antlr.HqlBaseLexer.<init>(HqlBaseLexer.java:50)   
      at org.hibernate.hql.ast.HqlLexer.<init>(HqlLexer.java:26)   
      at org.hibernate.hql.ast.HqlParser.getInstance(HqlParser.java:44)   
      at org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:242)   
      at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:157)   
      at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:111)   
      at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:77)   
      at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:56)
      at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72)   
      at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
      at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)   
      at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1623)   
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)   
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)   
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)   
      at java.lang.reflect.Method.invoke(Method.java:585)   
      at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:301)   
      at $Proxy0.createQuery(Unknown Source)   at TheBean.getList(TheBean.java:39)   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)   
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)   
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:585)   at com.sun.faces.el.PropertyResolverImpl.getValue(PropertyResolverImpl.java:79)


Name and version of the database you are using:
MySql Server 5.0



also another thing that gets me confused is some diferences between the book and the
reference manual examples

in the book (java persistence with hibernate) the session is called

Session session = HibernateUtil
.getSessionFactory()
.openSession();

and in the reference manual

Session session = HibernateUtil
.getSessionFactory()
.getCurrentSession();

what is the diference?

i appreciate help, thank you all..

_________________
--------------------------------------
Para todos la luz, para todos todo


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 28, 2008 3:42 am 
Beginner
Beginner

Joined: Tue Aug 16, 2005 3:44 pm
Posts: 33
Hi!

Have you added antlr-x.x.x.jar to your project?

See http://saloon.javaranch.com/cgi-bin/ubb ... 8&t=002092


-Kaj :)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 28, 2008 11:22 am 
Senior
Senior

Joined: Fri Jun 01, 2007 12:41 pm
Posts: 121
openSession --> Create database connection and open a Session on it.

getCurrentSession --> Obtains the current session. The definition of what exactly "current" means controlled by the CurrentSessionContext impl configured for use.


Top
 Profile  
 
 Post subject: jars
PostPosted: Thu Feb 28, 2008 11:43 am 
Newbie

Joined: Wed Feb 27, 2008 6:13 pm
Posts: 3
Hi kajh, thanks for reply

I was thinking that, that i missed a jar or something, but i added all the jars in the hibernate zip (also antlr-2.7.6.jar)

I use jDeveloper and when i run the project, the output in the log messages is:


Code:
C:\jdev_dir\jdk\jre\bin\java.exe -jar C:\jdev_dir\jdev\lib\ojc.jar -noquiet -warn -nowarn:320 -nowarn:486 -nowarn:487 -deprecation:self -nowarn:560 -nowarn:704 -nowarn:489 -nowarn:415 -nowarn:909 -nowarn:412 -nowarn:414 -nowarn:561 -nowarn:376 -nowarn:371 -nowarn:558 -nowarn:375 -nowarn:413 -nowarn:377 -nowarn:372 -nowarn:557 -nowarn:556 -nowarn:559 -source 1.5 -target 1.5 -encoding Cp1252 -g -d C:\project_dir\classes -make C:\project_dir\classes\HibernateExample.cdi -classpath 
C:\jdev_dir\jdk\jre\lib\rt.jar;
C:\jdev_dir\jdk\jre\lib\i18n.jar;
C:\jdev_dir\jdk\jre\lib\sunrsasign.jar;
C:\jdev_dir\jdk\jre\lib\jsse.jar;
C:\jdev_dir\jdk\jre\lib\jce.jar;
C:\jdev_dir\jdk\jre\lib\charsets.jar;
C:\jdev_dir\jdk\jre\classes;C:\project_dir\classes;C:\jdev_dir\jsf-ri\jsf-api.jar;
C:\jdev_dir\jsf-ri\jsf-impl.jar;
C:\jdev_dir\jakarta-taglibs\commons-beanutils-1.6.1\commons-beanutils.jar;
C:\jdev_dir\jakarta-taglibs\commons-digester-1.5\commons-digester.jar;
C:\jdev_dir\jakarta-taglibs\commons-logging-1.0.3\commons-logging-api.jar;
C:\jdev_dir\jakarta-taglibs\commons-logging-1.0.3\commons-logging.jar;
C:\jdev_dir\jakarta-taglibs\commons-collections-2.1\commons-collections.jar;
C:\jdev_dir\jakarta-taglibs\jstl-1.1\lib\jstl.jar;
C:\jdev_dir\j2ee\home\lib\ojsp.jar;
C:\jdev_dir\j2ee\home\jsp\lib\taglib\ojsputil.jar;
C:\jdev_dir\j2ee\home\oc4j.jar;
C:\jdev_dir\j2ee\home\lib\oc4j-internal.jar;
C:\jdev_dir\j2ee\home\lib\servlet.jar;
C:\jdev_dir\jdev\lib\ojc.jar;
C:\jdev_dir\jlib\adf-faces-impl.jar;
C:\jdev_dir\jlib\adf-faces-api.jar;
C:\jdev_dir\BC4J\lib\adfshare.jar;
C:\project_dir\lib\hibernate\ant-1.6.5.jar;
C:\project_dir\lib\hibernate\ant-antlr-1.6.5.jar;
C:\project_dir\lib\hibernate\ant-junit-1.6.5.jar;
C:\project_dir\lib\hibernate\ant-launcher-1.6.5.jar;
C:\project_dir\lib\hibernate\ant-swing-1.6.5.jar;

C:\project_dir\lib\hibernate\antlr-2.7.6.jar;
Code:
C:\project_dir\lib\hibernate\asm-attrs.jar;
C:\project_dir\lib\hibernate\asm.jar;
C:\project_dir\lib\hibernate\c3p0-0.9.1.jar;
C:\project_dir\lib\hibernate\cglib-2.1.3.jar;
C:\project_dir\lib\hibernate\checkstyle-all.jar;
C:\project_dir\lib\hibernate\cleanimports.jar;
C:\project_dir\lib\hibernate\commons-collections-2.1.1.jar;
C:\project_dir\lib\hibernate\commons-logging-1.0.4.jar;
C:\project_dir\lib\hibernate\concurrent-1.3.2.jar;
C:\project_dir\lib\hibernate\dom4j-1.6.1.jar;
C:\project_dir\lib\hibernate\ehcache-1.2.3.jar;
C:\project_dir\lib\hibernate\hibernate3.jar;
C:\project_dir\lib\hibernate\jaas.jar;
C:\project_dir\lib\hibernate\jacc-1_0-fr.jar;
C:\project_dir\lib\hibernate\javassist.jar;
C:\project_dir\lib\hibernate\jaxen-1.1-beta-7.jar;
C:\project_dir\lib\hibernate\jboss-cache.jar;
C:\project_dir\lib\hibernate\jboss-common.jar;
C:\project_dir\lib\hibernate\jboss-jmx.jar;
C:\project_dir\lib\hibernate\jboss-system.jar;
C:\project_dir\lib\hibernate\jgroups-2.2.8.jar;
C:\project_dir\lib\hibernate\jta.jar;
C:\project_dir\lib\hibernate\junit-3.8.1.jar;
C:\project_dir\lib\hibernate\log4j-1.2.11.jar;
C:\project_dir\lib\hibernate\oscache-2.1.jar;
C:\project_dir\lib\hibernate\proxool-0.8.3.jar;
C:\project_dir\lib\hibernate\swarmcache-1.0rc2.jar;
C:\project_dir\lib\hibernate\syndiag2.jar;
C:\project_dir\lib\hibernate\versioncheck.jar;
C:\project_dir\lib\hibernate\xerces-2.6.2.jar;
C:\project_dir\lib\hibernate\xml-apis.jar;
C:\project_dir\lib\mysql\mysql-connector-java-5.1.5-bin.jar
-sourcepath
C:\project_dir\src;
C:\jdev_dir\jdk\src.zip;C:\jdev_dir\jakarta-taglibs\commons-logging-1.0.3\src;
C:\jdev_dir\BC4J\src\adfmsrc.zip;C:\jdev_dir\BC4J\src\adfsharesrc.zip C:\project_dir\src\backing\Backing_main.java C:\project_dir\src\hello\Persona.java C:\project_dir\src\persistence\HibernateUtil.java
  compiling C:\project_dir\src\backing\Backing_main.java


so as you can see the jar is included,
kind of lost here :(

_________________
--------------------------------------
Para todos la luz, para todos todo


Top
 Profile  
 
 Post subject: antlr jar
PostPosted: Thu Feb 28, 2008 12:26 pm 
Newbie

Joined: Wed Feb 27, 2008 6:13 pm
Posts: 3
so the problem: antlr.jar

jdeveloper seems to have an old version that cause the crash, replacing the old one with the one that came with hibermate fixed the problem,
hope not affect other things

http://www.it-eye.nl/weblog/2006/02/02/jdeveloper-and-hibernate-3/

is there a better solution than replacing the jar from the jdeveloper dir?

_________________
--------------------------------------
Para todos la luz, para todos todo


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.