facebook

Hibernate not working in 5.1

  1. MyEclipse Archived
  2.  > 
  3. Database Tools (DB Explorer, Hibernate, etc.)
Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #261847 Reply

    bsavardnok
    Member

    Hi.
    I’m new to Hibernate; I went through the Hibernate example in the Eclipse Help system and have a console app that works against my MySQL table.
    Now I want to take that knowledge and use it in my Web application, so I put the code in a JSP:

    <%@ page language=”java” import=”java.util.*,com.x.datastore.*” pageEncoding=”UTF-8″%>
    <!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”>
    <html>
    <head></head>
    <body>
    <%
    SitetagsDAO dao = null;
    try{
    dao = new SitetagsDAO();
    List l = dao.findByOwnerId(new Integer(“2”));
    System.out.println(((Sitetags)l.get(0)).getTagText());
    }
    catch(Exception e){
    e.printStackTrace();
    }
    finally {
    try{dao.getSession().close();}
    catch(Exception ex){}
    }
    %>
    </body>
    </html>

    When I use the code in a JSP page, I get the following error on Tomcat’s console:

    <snip>
    INFO : cfg.Environment: Hibernate 3.1.3
    INFO : cfg.Environment: hibernate.properties not found
    INFO : cfg.Environment: using CGLIB reflection optimizer
    INFO : cfg.Environment: using JDK 1.4 java.sql.Timestamp handling
    INFO : cfg.Configuration: configuring from resource: /hibernate.cfg.xml
    INFO : cfg.Configuration: Configuration resource: /hibernate.cfg.xml
    INFO : cfg.Configuration: Reading mappings from resource: com/x/datastore/Simple.hbm.xml
    INFO : cfg.HbmBinder: Mapping class: com.x.datastore.Simple -> simple
    INFO : cfg.Configuration: Reading mappings from resource: com/x/datastore/Sitetags.hbm.xml
    INFO : cfg.HbmBinder: Mapping class: com.x.datastore.Sitetags -> sitetags
    INFO : cfg.Configuration: Configured SessionFactory: null
    %%%% Error Creating SessionFactory %%%%
    java.lang.ClassCastException: java.util.HashMap
    at org.hibernate.util.PropertiesHelper.resolvePlaceHolders(PropertiesHelper.java:88)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1173)
    at com.x.datasource.HibernateSessionFactory.rebuildSessionFactory(HibernateSessionFactory.java:61)
    at com.x.datasource.HibernateSessionFactory.getSession(HibernateSessionFactory.java:44)
    at com.x.datastore.BaseHibernateDAO.getSession(BaseHibernateDAO.java:14)
    at com.x.datastore.SitetagsDAO.findByProperty(SitetagsDAO.java:80)
    at com.x.datastore.SitetagsDAO.findByOwnerId(SitetagsDAO.java:90)
    at org.apache.jsp.GetTags_jsp._jspService(GetTags_jsp.java:50)
    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:332)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
    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(ApplicationFilterChain.java:252)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:541)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
    at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java
    :664)
    at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
    at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
    at java.lang.Thread.run(Thread.java:595)
    ERROR: datastore.SitetagsDAO: find by property name failed
    java.lang.NullPointerException
    at com.x.datastore.SitetagsDAO.findByProperty(SitetagsDAO.java:80)
    at com.x.datastore.SitetagsDAO.findByOwnerId(SitetagsDAO.java:90)
    at org.apache.jsp.GetTags_jsp._jspService(GetTags_jsp.java:50)
    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:332)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
    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(ApplicationFilterChain.java:252)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:541)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
    at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java
    :664)
    at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
    at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
    at java.lang.Thread.run(Thread.java:595)
    java.lang.NullPointerException
    at com.x.datastore.SitetagsDAO.findByProperty(SitetagsDAO.java:80)
    at com.x.datastore.SitetagsDAO.findByOwnerId(SitetagsDAO.java:90)
    at org.apache.jsp.GetTags_jsp._jspService(GetTags_jsp.java:50)
    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:332)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
    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(ApplicationFilterChain.java:252)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:541)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
    at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java
    :664)
    at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
    at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
    at java.lang.Thread.run(Thread.java:595)
    INFO : cfg.Configuration: configuring from resource: /hibernate.cfg.xml
    INFO : cfg.Configuration: Configuration resource: /hibernate.cfg.xml
    INFO : cfg.Configuration: Reading mappings from resource: com/x/datastore/Simple.hbm.xml
    INFO : cfg.Mappings: duplicate import: com.x.datastore.Simple->com.x.datastore.Simple
    INFO : cfg.Mappings: duplicate import: com.x.datastore.Simple->Simple
    INFO : cfg.HbmBinder: Mapping class: com.x.datastore.Simple -> simple
    %%%% Error Creating SessionFactory %%%%
    org.hibernate.MappingException: Could not read mappings from resource: com/x/datastore/Simple.hbm.xml
    at org.hibernate.cfg.Configuration.addResource(Configuration.java:485)
    at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1465)
    at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1433)
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1414)
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1390)
    at org.hibernate.cfg.Configuration.configure(Configuration.java:1310)
    at com.x.datasource.HibernateSessionFactory.rebuildSessionFactory(HibernateSessionFactory.java:60)
    at com.x.datasource.HibernateSessionFactory.getSession(HibernateSessionFactory.java:44)
    at com.x.datastore.BaseHibernateDAO.getSession(BaseHibernateDAO.java:14)
    at org.apache.jsp.GetTags_jsp._jspService(GetTags_jsp.java:57)
    </snip>

    Here’s my hibernate.cfg.xml which lives in the root of my src dir:

    <?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”&gt;

    <!– Generated by MyEclipse Hibernate Tools. –>
    <hibernate-configuration>

    <session-factory>
    <property name=”connection.username”>me</property>
    <property name=”connection.password”>mypass</property>
    <property name=”connection.url”>jdbc:mysql://192.168.1.44:3306/x</property>
    <property name=”dialect”>org.hibernate.dialect.MySQLDialect</property>
    <property name=”myeclipse.connection.profile”>Laptop MySQL</property>
    <property name=”connection.driver_class”>com.mysql.jdbc.Driver</property>
    <property name=”show_sql”>true</property>
    <mapping resource=”com/x/datastore/Simple.hbm.xml” />
    <mapping resource=”com/x/datastore/Sitetags.hbm.xml” />
    </session-factory>

    </hibernate-configuration>

    and here’s Sitetags.hbm.xml, which lives in the com/x/datastore package:

    <?xml version=”1.0″ encoding=”utf-8″?>
    <!DOCTYPE hibernate-mapping PUBLIC “-//Hibernate/Hibernate Mapping DTD 3.0//EN”
    http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd”&gt;
    <!–
    Mapping file autogenerated by MyEclipse – Hibernate Tools
    –>
    <hibernate-mapping>
    <class name=”com.x.datastore.Sitetags” table=”sitetags” catalog=”x”>
    <id name=”siteUrl” type=”java.lang.String”>
    <column name=”SiteUrl” length=”65535″ />
    <generator class=”native” />
    </id>
    <property name=”ownerId” type=”java.lang.Integer”>
    <column name=”OwnerId” not-null=”true” />
    </property>
    <property name=”tagText” type=”java.lang.String”>
    <column name=”TagText” length=”65535″ not-null=”true” />
    </property>
    </class>
    </hibernate-mapping>

    I’m really not sure why the Hibernate code works in a stand-alone class, but not when embedded in a JSP.
    I’ve Googled and didn’t find much for this. I’ve spent all day on it, so now I’m asking for help 🙂
    Any help is much appreciated!!!
    -B

    #261848 Reply

    bsavardnok
    Member

    This is using ME 5.1 via a fresh install of the plug-in, and I chose Hibernate 3.1 libraries.

    Thanks.

    #261919 Reply

    Haris Peco
    Member

    bsavard ,

    It looks that application server can’t find your Simple.hbm.xml file.
    You probably haven’t set output directory (Build path in Project properties) to web application’s classes directory

    Regards,

    #261927 Reply

    bsavardnok
    Member

    @support-snpe wrote:

    bsavard ,

    It looks that application server can’t find your Simple.hbm.xml file.
    You probably haven’t set output directory (Build path in Project properties) to web application’s classes directory

    Regards,

    Hi.

    Yes, my project’s output dir is set to “x/WebRoot/WEB-INF/classes”. That is Tomcat’s classes dir.

    Thanks for the suggestion – have any others???

    #261933 Reply

    Haris Peco
    Member

    bsavard,

    Please, heck if your hbm.xml is really in tomcat’s classes directory and in correct directory/package ?
    You can send your proecjt on [email protected] with subject ATTN: snpe (if it is possible)
    and I will try check what is your problem

    Regards,

    #262020 Reply

    bsavardnok
    Member

    I took me a couples of days to figure this out, so I’m posting my methodology so it may benefit someone else someday.

    Quick overview: my Hibernate code works in a console app, but fails when I use it with Tomcat.

    steps to resolve:
    1) verify that my hibernate.cfg.xml is located in the root of my source folder
    2) verify the the *.hbm.xml file is located in the correct source package folder
    3) verified that the mapping in hibernate.cfg.xml for the .hbm file included the full package and didn’t start with “/”
    4) added log4j.properties from the Hibernate distro to the root of my source folder and changed log4j.logger.org.hibernate to debug (was info)
    5) this was showing where it was bombing on Tomcat’s console:
    java.lang.ClassCastException: java.util.HashMap
    at org.hibernate.util.PropertiesHelper.resolvePlaceHolders(PropertiesHelper.java:88)
    6) downloaded sources for Hibernate; PropertiesHelper.java:88 is expecting a String value from properties, but was getting a HashMap
    7) looked over the Tomcat console and realized that Properties did in fact contain a HashMap, but it was loaded there FROM ANOTHER WEB APPLICATION!
    8) removed that web app and restarted Tomcat, and my Hibernate code now works 🙂

    So, the morals of the story are:
    1) Thank God for open-source software!
    2) Maybe Hibernate’s PropertiesHelper.java:88 should do an instanceof and make sure the value is a String before assigning it.
    3) Re-examine my use of the Properties to store config info for web apps.

    I’m thinking I’ll definately do #3, but I also think Hibernate should take a look at #2.
    Does anyone agree or am I 100% at fault here?

    Thanks,
    -B

    #262057 Reply

    bsavardnok
    Member

    Just downloaded Hibernate 3.2.0 GA and checked the sources for PropertiesHelper, and it looks like they’ve implmented the test I talked about above. So, when will MyEclipse ship with Hibernate 3.2? Can I patch my ME 5.1 install with the Hibernate 3.2 files without my install blowing up?

    Thanks.

    #262099 Reply

    Haris Peco
    Member

    You have to add your user libraries (Window>Preference>Java>Build Path>User libraries) and use it in 1th page of ‘Add Hibernate Capabilites’ wizard instead of myEclipse libraries, but it is not supported and tested and you can have different problems.
    If you add and use user libraries you will not break installation, but maybe some MyEclipse features will not work.

    Regards,

    #264634 Reply

    SeeControl
    Member

    – System Setup ——————————-
    Operating System and version:
    Eclipse version:
    Eclipse build id:
    Fresh Eclipse install (y/n):
    If not, was it upgraded to its current version using the update manager?
    Other installed external plugins:
    Number of plugins in the <eclipse>/plugins directory that begin with org.eclipse.pde.*:
    MyEclipse version:
    Eclipse JDK version:
    Application Server JDK version:
    Are there any exceptions in the Eclipse log file?

    If this is a DB related question please answer the following:

    RDBMS vendor and version:
    JDBC driver vendor and version, and access type (thin, type-2, etc):
    Connection URL:
    Eclipse error logs related to com.genuitec.eclipse.sqlexplorer packages:

    – Message Body ——————————-

    Hi,

    When can we expect Hibernate 3.2 support to be available in MyEclipse?

    Thanks

    #264921 Reply

    Brian Fernandes
    Moderator

    Hibernate 3.2 support will most likely be present in 5.5GA.

Viewing 10 posts - 1 through 10 (of 10 total)
Reply To: Hibernate not working in 5.1

You must be logged in to post in the forum log in