From: Phillip B. <phi...@cl...> - 2002-04-01 09:50:28
|
Gidday all, I'm having endless problems trying to do what I thought would be a no-brainer exercise with a Component property. Basically my classes are like the Person -> Name compoent example in the tutorial doc. I have a Listing class which contains a PhoneNumber property. PhoneNumber simply has four String properties which are mapped to the Listing class's table. So my mapping looks like this... <class name="phonebook.model.Listing" table="Listing" select="distinct"> <id name="UID" type="long" column="UID"> <generator class="hilo.long"/> </id> <property name="name" column="name" type="string"/> <component name="businessNumber" class="phonebook.model.PhoneNumber"> <property name="countryCode" column="countryCode" type="string"/> <property name="areaCode" column="areaCode" type="string"/> <property name="phoneNumber" column="phoneNumber" type="string"/> <property name="extension" column="extension" type="string"/> </component> If I try to save a Listing the following exception is thrown... java.lang.NullPointerException at java.lang.reflect.Method.invoke(Native Method) at cirrus.hibernate.type.ComponentType.getPropertyValue(ComponentType.java:152) at cirrus.hibernate.type.ComponentType.getValues(ComponentType.java:171) at cirrus.hibernate.impl.RelationalDatabaseSession.nullifyTransientReferences(RelationalDatabaseSession.java:527) at cirrus.hibernate.impl.RelationalDatabaseSession.nullifyTransientReferences(RelationalDatabaseSession.java:517) at cirrus.hibernate.impl.RelationalDatabaseSession.save(RelationalDatabaseSession.java:484) at cirrus.hibernate.impl.RelationalDatabaseSession.save(RelationalDatabaseSession.java:434) at phonebook.model.ListingFactory.save(ListingFactory.java:125) This exception is being caused because Listing.getBusinessNumber() is returning a null. Ok so I thought I'd work around the problem by initialising the property in the default constructor. That worked. Now the Listing could be saved. Tried deleting it next using session.delete("FROM listing IN CLASS phonebook.model.Listing") and got the following similar exception... java.lang.NullPointerException at java.lang.reflect.Method.invoke(Native Method) at cirrus.hibernate.type.ComponentType.getPropertyValue(ComponentType.java:152) at cirrus.hibernate.type.ComponentType.getValues(ComponentType.java:171) at cirrus.hibernate.impl.RelationalDatabaseSession.nullifyTransientReferences(RelationalDatabaseSession.java:527) at cirrus.hibernate.impl.RelationalDatabaseSession.nullifyTransientReferences(RelationalDatabaseSession.java:517) at cirrus.hibernate.impl.RelationalDatabaseSession.delete(RelationalDatabaseSession.java:590) at cirrus.hibernate.impl.IdentifierIterator.remove(IdentifierIterator.java:116) at cirrus.hibernate.impl.RelationalDatabaseSession.delete(RelationalDatabaseSession.java:669) at cirrus.hibernate.impl.RelationalDatabaseSession.delete(RelationalDatabaseSession.java:651) at phonebook.model.ListingFactory.deleteAll(ListingFactory.java:67) Running up the debugger I could see the Iterator was returning the Listing that had been saved. As documented in the tutorial doc, because all the PhoneNumber properties were blank, the businessNumber property ended up being set to null when loaded. This then resulted in same exception as when saving. So after all that my question is - is this a bug? How should null Component properties be handled? thanks PhillipB |