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!