-->
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: Hibernate 3.0.5 & JBoss 4.0.2, NullPointerException
PostPosted: Tue May 31, 2005 10:40 am 
Newbie

Joined: Tue May 31, 2005 10:31 am
Posts: 5
Hi,

I'm searching for a persistence framework to use, and actually I try to test hibernate.
My problem at the moment is that i get a NullPointerException if I make a lookup.

In the JNDI VIEW page i found the entry: +- SessionFactory (class: org.hibernate.impl.SessionFactoryImpl)
But in the log file I found these entries, and i don't know what to do now.
Code:
[b]server.log:[/b]
...
[org.hibernate.impl.SessionFactoryObjectFactory] Not binding factory to JNDI, no JNDI name configured
...
[org.jboss.hibernate.jmx.Hibernate] SessionFactory successfully built and bound into JNDI [SessionFactory]
...


Code:
[b]hibernate-service.xml:[/b]
<server>
   <mbean code="org.jboss.hibernate.jmx.Hibernate" name="jboss.har:service=Hibernate">
      <attribute name="DatasourceName">java:/DefaultDS</attribute>
      <attribute name="Dialect">org.hibernate.dialect.Oracle9Dialect</attribute>
           <property name="hibernate.default_schema">LAGERDBA</property>
      <property name="connection.pool_size">1</property>
      <property name="show_sql">true</property>
      <attribute name="SessionFactoryName">SessionFactory</attribute>
      <attribute name="CacheProviderClass">org.hibernate.cache.HashtableCacheProvider</attribute>
      <attribute name="ShowSqlEnabled">true</attribute>
   </mbean>
</server>


Code:
[b]UserManager.java[/b]
...
InitialContext ctx = new InitialContext();
SessionFactory factory;
factory = (SessionFactory) ctx.lookup("SessionFactory");
Session hsession = factory.openSession();
Transaction tx = hsession.beginTransaction();
...


Sample Hibernate File

Code:
[b]AcUser.java[/b]
package de.psb_gmbh.main.business.persistence.hibernate;

import java.util.Set;

public class AcUser implements java.io.Serializable {

  // Fields
  private String UserId;
  private AcGroup AcGroup;
  private String LoginName;
  private String Name;
  private String Password;
  private Integer CheckCount;
  private Set<AcUserToGroup> SetOfAcUserToGroup;

  // Constructors
  public AcUser() {
  }

  // Property accessors
  public String getUserId() {
    return this.UserId;
  }

  public void setUserId(String UserId) {
    this.UserId = UserId;
  }

  public AcGroup getAcGroup() {
    return this.AcGroup;
  }

  public void setAcGroup(AcGroup AcGroup) {
    this.AcGroup = AcGroup;
  }

  public String getLoginName() {
    return this.LoginName;
  }

  public void setLoginName(String LoginName) {
    this.LoginName = LoginName;
  }

  public String getName() {
    return this.Name;
  }

  public void setName(String Name) {
    this.Name = Name;
  }

  public String getPassword() {
    return this.Password;
  }

  public void setPassword(String Password) {
    this.Password = Password;
  }

  public Integer getCheckCount() {
    return this.CheckCount;
  }

  public void setCheckCount(Integer CheckCount) {
    this.CheckCount = CheckCount;
  }

  public Set<AcUserToGroup> getSetOfAcUserToGroup() {
    return this.SetOfAcUserToGroup;
  }

  public void setSetOfAcUserToGroup(Set<AcUserToGroup> setOfAcUserToGroup) {
    this.SetOfAcUserToGroup = setOfAcUserToGroup;
  }
}

Code:
[b]AcUser.hbm.xml[/b]
<?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="de.psb_gmbh.main.business.persistence.hibernate.AcUser" table="AC_USER" schema="LAGERDBA">
    <id name="UserId">
      <column name="USER_ID"/>
      <generator class="assigned" />
    </id>
    <many-to-one name="AcGroup" class="de.psb_gmbh.main.business.persistence.hibernate.AcGroup">
      <column name="MASTER_GROUP_ID"/>
    </many-to-one>
    <property name="LoginName">
      <column name="LOGIN_NAME"/>
    </property>
    <property name="Name">
      <column name="NAME"/>
    </property>
    <property name="Password">
      <column name="PASSWORD"/>
    </property>
    <property name="CheckCount">
      <column name="CHECK_COUNT"/>
    </property>
    <set name="SetOfAcUserToGroup">
      <key>
        <column name="USER_ID" />
      </key>
      <one-to-many class="de.psb_gmbh.main.business.persistence.hibernate.AcUserToGroup" />
    </set>
  </class>
</hibernate-mapping>



I'm using
- JBoss 4.0.2
- Hibernate 3.0.5
- Java 5.0
- Oracle DB 9.2
- Windows XP SP1
- Eclipse 3.1M7 with MyEclipse 3.8.4, JBoss IDE1.5M1, XML Spy Pro 2005


THANKS!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 12, 2005 6:28 am 
Newbie

Joined: Thu Aug 11, 2005 6:56 am
Posts: 9
Hi

I have the exact same problem. My config-files look almost identical to yours.
and my log-output is the same. My java-code is also identical.

I don't know if this would help, but have you tried to add "java:/" in your hibernate-service.xml?
<attribute name="SessionFactoryName">java:/SessionFactory</attribute>
(I have seen it done like that in an example project that I have that woorks)

Of cource you then also have to reference it like this in your java code:
factory = (SessionFactory) ctx.lookup("java:/SessionFactory");

Mads


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 12, 2005 7:37 am 
Newbie

Joined: Thu Aug 11, 2005 6:56 am
Posts: 9
See if the answer on http://www.jboss.org/index.html?module= ... 15#3881015 helps.

That solved the problem for me. I Accidently had included "hibernate3.jar" in /WEB_INF/lib" in my .war-file.

When I removed it the lookup was successful.

Mads


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.