7 Replies Latest reply on Nov 1, 2005 9:47 PM by David Navas

    Trying to get started

    Kazan Kazan Newbie

      I have been trying to get JBoss and Hibernate running, but I keep getting a "hibernate not bound" message when I try to create a sesseion:

      I am using JBoss 4.0.3 and Hibernate 3

      My .har file is located in my deploy directory:

      C:\jboss403\server\default\deploy\Test.har


      The .har file is composed as follows:

      C:\jboss403\server\default\deploy\META-INF
      C:\jboss403\server\default\deploy\META-INF\MANIFEST.MF
      C:\jboss403\server\default\deploy\META-INF\hibernate-service.xml
      C:\jboss403\server\default\deploy\com\xxxxx\persistence\Test.class
      C:\jboss403\server\default\deploy\com\xxxxx\persistence\Test.hbm.xml


      My hibernate-service.xml is as follows:
      -------------------------------------------------------------------------------
      <server>
       <mbean code="org.jboss.hibernate.jmx.Hibernate" name="jboss.har:service=Hibernate">
       <attribute name="SessionFactoryName">hibernate/HibernateFactory</attribute>
       <attribute name="DatasourceName">java:OracleDS</attribute>
       <attribute name="Dialect">net.sf.hibernate.dialect.OracleDialect</attribute>
       <attribute name="CacheProviderClass">net.sf.hibernate.cache.HashtableCacheProvider</attribute>
       </mbean>
      </server>


      This is my bean class (com.xxxxx.persistence.Test.java)
      ---------------------------------------------------------------------------------
      package com.xxxxx.persistence;
      
      import java.util.Set;
      
      public class Test implements java.io.Serializable {
       private String Id;
       private String CName;
       private String CNumber;
       private String CDate;
      
       // Constructors
       public Test() {
       }
      
       // Property accessors
       public String getId() {
       return this.Id;
       }
      
       public void setId(String Id) {
       this.Id = Id;
       }
      
       public String getCName() {
       return this.CName;
       }
      
       public void setCName(String CName) {
       this.CName = CName;
       }
      
       public String getCNumber() {
       return this.CNumber;
       }
      
       public void setCNumber(String CNumber) {
       this.CNumber = CNumber;
       }
      
       public String getCDate() {
       return this.CDate;
       }
      
       public void setCDate(String CDate) {
       this.CDate = CDate;
       }
      }



      This is the mapping file (Test.hbm.xml):
      ------------------------------------------------------------------------------
      <?xml version="1.0"?>
      <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
      "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
      <hibernate-mapping>
       <class name="com.xxxxx.persistence.Test" table="TEST">
       <id name="Id">
       <column name="ID"/>
       <generator class="native" />
       </id>
       <property name="CName">
       <column name="C_NAME"/>
       </property>
       <property name="CNumber">
       <column name="C_NUMBER"/>
       </property>
       <property name="CDate">
       <column name="C_DATE"/>
       </property>
       </class>
      </hibernate-mapping>


      This is my table in Oracle
      -----------------------------------------------------------------------
      create table TEST
      (
       ID INTEGER not null,
       C_NAME VARCHAR2(256),
       C_NUMBER NUMBER,
       C_DATE DATE
      )


      This is the JSP file I am using to test my Hibernate/JBoss config.
      -------------------------------------------------------------------------
      <%@ page import="java.io.*" %>
      <%@ page import="java.util.*" %>
      <%@ page import="org.hibernate.*" %>
      <%@ page import="org.hibernate.cfg.*" %>
      <%@ page import="javax.naming.*" %>
      <%@ page import="javax.transaction.*" %>
      <%@ page import="org.hibernate.*" %>
      <%@ page import="org.hibernate.cfg.*" %>
      <%@ page import="com.xxxxx.persistence.*" %>
      <%@ page import="org.jboss.hibernate.session.*" %>
      
      <HTML>
      <HEAD>
      <title>Greetings!</title>
      </HEAD>
      <BODY>
      <hr>xxxyyy
      <%
       try {
       System.out.println("test.1");
      
       Context ctx = new InitialContext();
       SessionFactory sf = (SessionFactory)ctx.lookup("hibernate/SessionFactory");
       Session s = sf.openSession();
      
      
      
       //Session s = HibernateContext.getSession("java:/hibernate/SessionFactory");
       System.out.println("test.2");
       org.hibernate.Transaction tx = s.beginTransaction();
       System.out.println("test.3");
       Test test = new Test();
       System.out.println("test.4");
       test.setCName("bubba");
       System.out.println("test.5");
       s.save(test);
       System.out.println("test.6");
       }
       catch(Exception exception){
       exception.printStackTrace();
       }
      %>
      <hr>

      This is the message I get when I load this page:
      ----------------------------------------------------------------------------
      javax.naming.NameNotFoundException: hibernate not bound


      I have been working on getting Hibernate running in JBoss for a while, and am not having any luck. Any help would by greatly appreciated.


        • 1. Re: Trying to get started
          Darran Lofthouse Master

          Did you get any errors on deployment?

          There is a known hibernate issue with JBoss 4.0.3, this could be related to your problem.

          http://jira.jboss.com/jira/browse/JBAS-2364

          • 2. Re: Trying to get started
            Kazan Kazan Newbie

            OK, I downloaded the latest JBoss 4.0.3 and I was able to sucessfully bind to the session object.

            However, I am getting this stacktrace:
            [BasicPropertyAccessor] IllegalArgumentException in class: com.xxxxx.persistence.Test, setter method of property: Id
            [BasicPropertyAccessor] expected type: java.lang.Integer, actual value: java.lang.Integer
            [STDOUT] org.hibernate.PropertyAccessException: IllegalArgumentException occurred while calling setter of com.xxx.persistence.Test.Id

            I have searched all over the internet for some explanation of this error, but I have not had any luck.

            I am using Oracle. My id column is using an Integer datatype. I have tried using a int and Integer data type in my .java file.

            Here is my JSP page:

            <%@ page import="java.io.*" %>
            <%@ page import="java.util.*" %>
            <%@ page import="org.hibernate.*" %>
            <%@ page import="org.hibernate.cfg.*" %>
            <%@ page import="javax.naming.*" %>
            <%@ page import="javax.transaction.*" %>
            <%@ page import="org.hibernate.*" %>
            <%@ page import="org.hibernate.cfg.*" %>
            <%@ page import="com.xxx.persistence.*" %>
            <%@ page import="org.jboss.hibernate.session.*" %>
            
            <HTML>
            <HEAD>
            </HEAD>
            <BODY>
            <hr>
            <%
             try {
             System.out.println("test.1");
            
             Context ctx = new InitialContext();
             SessionFactory sf = (SessionFactory)ctx.lookup("java:/hibernate/SessionFactory");
             Session s = sf.openSession();
            
            
            
             //Session s = HibernateContext.getSession("java:/hibernate/SessionFactory");
             System.out.println("test.2");
             org.hibernate.Transaction tx = s.beginTransaction();
             System.out.println("test.3");
             Test test = new Test();
             System.out.println("test.4");
             test.setCName("xxxx");
             System.out.println("test.5");
             s.save(test);
             System.out.println("test.6");
             }
             catch(Exception exception){
             exception.printStackTrace();
             }
            %>
            <hr>
            



            Here is my Test table: (Oracle)
            create table TEST
            (
             ID INTEGER primary key,
             C_NAME VARCHAR2(256),
             C_NUMBER NUMBER,
             C_DATE DATE
            )
            


            Here is my hbm file:
            <?xml version="1.0"?>
            <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
            "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
            <hibernate-mapping>
             <class name="com.xxx.persistence.Test" table="TEST">
             <id name="Id" type="int">
             <column name="ID"/>
             <generator class="sequence">
             <param name="sequence">TEST_ID_SEQ</param>
             </generator>
             </id>
             <property name="CName">
             <column name="C_NAME"/>
             </property>
             <property name="CNumber">
             <column name="C_NUMBER"/>
             </property>
             <property name="CDate">
             <column name="C_DATE"/>
             </property>
             </class>
            </hibernate-mapping>
            


            Here is my .java file:
            package com.xxx.persistence;
            
            import java.util.Set;
            
            public class Test implements java.io.Serializable {
             private Integer Id;
             private String CName;
             private String CNumber;
             private String CDate;
            
             // Constructors
             public Test(){
             }
            
             // Property accessors
             public Integer getId(){
             return this.Id;
             }
            
             public void setId(Integer Id) {
             this.Id = Id;
             }
            
             public String getCName() {
             return this.CName;
             }
            
             public void setCName(String CName) {
             this.CName = CName;
             }
            
             public String getCNumber() {
             return this.CNumber;
             }
            
             public void setCNumber(String CNumber) {
             this.CNumber = CNumber;
             }
            
             public String getCDate() {
             return this.CDate;
             }
            
             public void setCDate(String CDate) {
             this.CDate = CDate;
             }
            }
            


            • 3. Re: Trying to get started
              Brian Wallis Master

               

              "kazan77777" wrote:

              However, I am getting this stacktrace:
              [BasicPropertyAccessor] IllegalArgumentException in class: com.xxxxx.persistence.Test, setter method of property: Id
              [BasicPropertyAccessor] expected type: java.lang.Integer, actual value: java.lang.Integer
              [STDOUT] org.hibernate.PropertyAccessException: IllegalArgumentException occurred while calling setter of com.xxx.persistence.Test.Id


              That looks like a class path issue. Usually when you get an error like

              "expected type: java.lang.Integer, actual value: java.lang.Integer"

              it suggests that you have somehow managed to load two instances of the Integer.class with two different class loaders.

              You can easily see if this is the case via the Jmx console. Follow the link named "name=Default,service=LoaderRepository" near the top and invoke the "java.lang.String displayClassInfo()" operation with java.lang.Integer as the parameter. It should tell you if you have two copies of Integer loaded (if I remember correctly)


              • 4. Re: Trying to get started
                Kazan Kazan Newbie

                This is the output from JMX Console. It doesn't look like this is an issue:

                java.lang.Integer Information
                Repository cache version:
                java.lang.Integer(1a0d866).ClassLoader=null
                ++++Null CodeSource
                Implemented Interfaces:
                ++interface java.lang.Comparable(1747e0f)
                ++++ClassLoader: null
                ++++Null CodeSource

                • 5. Re: Trying to get started
                  Kazan Kazan Newbie

                  Can anyone please reply, (anyone from JBoss???) I need to get this running.

                  Is this a bug in JBoss, or am I not seeing something?

                  One thing I have discovered...the sequence is getting generated. Hibernate is getting stuck when it tries to call the setId method in my .java file. I have tried various combinations. I have tried using Integer and int, but no combination seams to work.

                  Are there any tips or techniques in tracing the hibernate code?

                  Help! I really want to get this running.

                  • 6. Re: Trying to get started
                    David Navas Newbie

                    You're doing better than I am -- the updated JBoss release didn't help me, I'm still
                    seeing a "hibernate not bound" message :( Undoubtedly some form of mis-
                    configuration. I'm using hibernate "under" ejb3 and I'm trying to retrieve statistics so
                    I can tune my one-to-many collection retrieval (which is horribly slow irrespective of
                    BatchSize -- in fact, batching appears to make things worse).

                    partial bean

                    @Stateless
                    public class DeviceService implements DeviceFacade {
                     @PersistenceContext (unitName="DA")
                     protected EntityManager em;
                    
                    
                     @TransactionAttribute(TransactionAttributeType.REQUIRED)
                     public String printDvcId(long dvcId) {
                     try {
                     SessionFactory sessionFactory = (SessionFactory)new InitialContext().lookup("hibernate/SessionFactory");
                    


                    So you see a HibernateMBeanService during startup? I get the feeling there ought to be one, and I don't see it....

                    Thanks,
                    -Dave


                    • 7. Re: Trying to get started
                      David Navas Newbie

                      I knew I'd figure it out as soon as I posted.
                      hibernate.session_factory_name needs to be set in the persistence.xml file.

                      BTW -- I agree with the original poster that your problem is very likely a ClassLoader
                      issue of some kind. I'm not sure how the persistence layer glues the two pieces
                      together, but, you can get a good indication of the ClassLoader loading the Integer
                      for your bean using

                      static {
                       System.out.println(Integer.class.getClassLoader());
                      }
                      

                      ...in your bean class. It ought to be the primordial class loader loading those classes....

                      [Of course, that won't help you know what the ClassLoader is for the other end....]

                      Hope that helps,
                      -Dave