-->
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: Need help using Hibernate in Eclipse/Websphere
PostPosted: Tue Sep 09, 2003 2:09 pm 
Newbie

Joined: Fri Sep 05, 2003 10:30 am
Posts: 17
Location: Texas
I'm having conceptual problems, am getting errors on my compile, and need help. :)

I've looked at some of the discussion on the board and I think those mostly revolve around using non-Eclipse/Websphere tools. My assumption is the Eclipse/Websphere are doing most of the grunt work for me, and I'm probably just having problems making sure all the pieces can find each other. (I second the suggestion there needs to be a Microsoft Studio type of GUI to bring mapping and code integration together! :)

So... I have my POJOs, I have my handcoded HBMs. I used the example on IBM's site to get started as shown here:
http://www7b.boulder.ibm.com/dmdd/libra ... l#download

So in other words I loaded up my POJOs and used the Hibernate plug-in to stub my HBMs, which I then (heavily) tweaked because I'm using nested relationships and I want to take advantage of lazy loads to drill down to the children.

(For the POJOs think of the Russian doll model, where every parent knows its child. But the DB2 tables work the other way around - every child knows its parent, but parents do not know their children.)

Then I simply wrapped the call to the high level object in a driver main class and compiled the project in Websphere Studio; the HBMs were moved to the right sub-folder and it appears they are found when Hibernate tries to register the classes to its Datastore.

When I run Studio fails with this error.

Code:
[INFO] DatastoreImpl - -Mapping resource: com/pier1/product/CompanyDto.hbm.xml
[INFO] XMLHelper - -Parsing XML: unknown system id
java.lang.NullPointerException
   at cirrus.hibernate.map.Collection.<init>(Collection.java:71)
   at cirrus.hibernate.map.Set.<init>(Set.java:26)
   at cirrus.hibernate.map.Root$2.create(Root.java:62)
   at cirrus.hibernate.map.PersistentClass.propertiesFromXML(PersistentClass.java:71)
   at cirrus.hibernate.map.RootClass.<init>(RootClass.java:227)
   at cirrus.hibernate.map.Root.<init>(Root.java:135)
   at cirrus.hibernate.impl.DatastoreImpl.store(DatastoreImpl.java:106)
   at cirrus.hibernate.impl.DatastoreImpl.storeInputStream(DatastoreImpl.java:116)
   at cirrus.hibernate.impl.DatastoreImpl.storeClass(DatastoreImpl.java:140)
   at com.pier1.product.persistence.hibernate.ProductPersistenceTest.<clinit>(ProductPersistenceTest.java:32)
   at TestHibernate.main(TestHibernate.java:28)
[ERROR] DatastoreImpl - -Could not configure datastore from input stream <java.lang.NullPointerException>
java.lang.ExceptionInInitializerError: java.lang.RuntimeException: couldn't get connection
   at com.pier1.product.persistence.hibernate.ProductPersistenceTest.<clinit>(ProductPersistenceTest.java:40)
   at TestHibernate.main(TestHibernate.java:28)
Exception in thread "main"



It may not be helpeful but here is an example of my high level POJO

Code:
<hibernate-mapping>
    <class name="com.product.CompanyDto" table="cubecompany">
        <id
           name="id"
           column="companyid"
           type="integer"
           unsaved-value="null"
        >
              <generator class="assigned"/>
          </id>
        <property
           name="description"
           column="deptdesc"
           type="string"
           length="40"
           update="false"
           insert="false"
           not-null="true"
        />
        <property
           name="totalSales"
           column="sales"
           type="float"
           update="false"
           insert="false"
           not-null="true"
        />
      <!-- FK to child Departments -->
      <set
         name="departmentList"
         cascade="all"
         inverse="true"
         lazy="true"
      >
         <key column="departmentid"/>
         <one-to-many class="com.product.DepartmentDto"/>
      </set>
    </class>
</hibernate-mapping>


And here is the test case that registers the class to Hibernate and attempts to create a session factory.

Code:
public class ProductPersistenceTest
   extends TestCase
{
   private Session session;
   private static SessionFactory sessionFactory;

   static {
      try
      {
         Datastore ds = Hibernate.createDatastore();
         ds.storeClass(CompanyDto.class);
         ds.storeClass(DepartmentDto.class);
         ds.storeClass(ClassDto.class);
         ds.storeClass(SkuDto.class);
         sessionFactory = ds.buildSessionFactory();
      }
      catch (Exception e)
      {
         throw new RuntimeException("couldn't get connection");
      }
   }

   public ProductPersistenceTest(String testName)
   {
      super(testName);
   }

   public void testCreateAndReadCompany() throws Exception
   {
      session = sessionFactory.openSession();

      CompanyDto company =
         (CompanyDto) session.load(CompanyDto.class, new Integer(1));

      session.flush();
      session.close();
   }
}


Apologies if this is information overload. :( Your help is very much appreciated!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 09, 2003 2:14 pm 
Newbie

Joined: Fri Sep 05, 2003 10:30 am
Posts: 17
Location: Texas
Additionally, I am using a strongly-typed collection in each higher level objects to contain its respective children. I do not know if this sort of extension can cause a problem. This is a pretty standard use of strong-typing, with the following code extended for each respective type of child class:

Code:
public class BaseProductList
   implements Serializable
{
   public Vector m_List = new Vector();
   
   public BaseProductList(){}
   
   public Vector getList() {
      return m_List;
   }
   
   public void addProduct(BaseProductDto item)
   {
      if (indexOfProduct(item) == -1) {
         m_List.add(item);
      }
   }

   public void removeProduct(BaseProductDto item)
   {
      int index = indexOfProduct(item);
      if (index > -1) {
         m_List.removeElementAt(index);
      }
   }

   public boolean containsProduct(BaseProductDto item)
   {
      if (indexOfProduct(item) > -1) {
         return true;
      } else {
         return false;
      }
   }
   
   public int indexOfProduct(BaseProductDto item)
   {
      int index = -1;

      int size = m_List.size();
      for(int j=0;j<size;j++) {
         BaseProductDto item2 = (BaseProductDto)m_List.elementAt(j);
         if (item2.getBaseId().equals(item.getBaseId())) {
            index = j++;
            break;
         }
      }
      
      return index;
   }

   public BaseProductDto baseProductAt(int index)
      throws Exception
   {

      validateIndex(index);

      return
         (BaseProductDto)m_List.elementAt(index);
   }


   public void validateIndex(int index)
      throws Exception
   {
      if (
         (index > m_List.size())
         ||
         (index < 0)
         ) {
         throw new Exception(
            "Index ["
            + index
            + "] out of range"
            );
      }
   }

}


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 09, 2003 4:09 pm 
Newbie

Joined: Fri Sep 05, 2003 10:30 am
Posts: 17
Location: Texas
Hmm ok it looks like the root of my problem is when it parses the XML. After commenting out the collection I get the error down to this:

Code:
[INFO] DatastoreImpl - -Mapping resource: com/pier1/product/CompanyDto.hbm.xml
[INFO] XMLHelper - -Parsing XML: unknown system id


It looks like it may be the collection causing the original problem, probably because I'm using the older Vector class.

Changing the base collection type isn't a problem, but this current error has really confused me. My ID field in the object is called 'id' - could this problem be cause by the fact that ID extends from a base class?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 09, 2003 10:13 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
(1) ignore the INFO, this is a FAQ
(2) the exception occurs because you are using Hibernate 1.x, and you don't specify a role attribute in the collection mapping
(3) i suspect that you intend to be using Hibernate2 (download it)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 11, 2003 11:46 am 
Newbie

Joined: Fri Sep 05, 2003 10:30 am
Posts: 17
Location: Texas
Moving to 2.x fixed it all - thx Gavin!


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.