the error occured in method prefetchRelationship(Collection owners) line 149 when a cast for the 1:n references is done. The cast is
if (collectionClass != null)
{
newChildren = (Collection) broker.getCollectionByQuery(collectionClass, queries[i]); //Line 149
}
Thus I think OJB has problems with one of your collection class in class-descriptor of Employee
<collection-descriptor
name="contracts"
element-class-ref="com.hours28.domain.entity.EmployeeContract"
collection-class="com.hours28.domain.entity.EmployeeContractCollection"
auto-retreive="true"
auto-update="true">
<inverse-foreignkey field-ref="employeeId"/>
</collection-descriptor><collection-descriptor
name="employeeServiceDetails" element-class-ref="com.hours28.domain.entity.EmployeeServiceDetail" collection-class="com.hours28.domain.entity.EmployeeServiceDetailCollection"
auto-retreive="true"
auto-update="true">
<inverse-foreignkey field-ref="employeeId"/>
</collection-descriptor>
Are both classes EmployeeContractCollection, EmployeeServiceDetailCollection instance of Collection?
regards, Armin
Raymond Barlow wrote:
Hi Armin,
Since my my lsat post, I've found that this is something to do with polymorphic classes/extents. I've basically got a base "User" class, and descendingt from that are 2 classes "Supplier" and "Employee". "User" is an abstract class, and the only "Supplier" and "Employee" are concrete classes. Thus, there is no table for "User". "Employee" and "Supplier" map to their own tables. I will recompile the jars, but until then, here are the class-descriptors for the 3 classes:
<class-descriptor class="com.hours28.domain.entity.User"> <extent-class class-ref="com.hours28.domain.entity.Employee"/> <extent-class class-ref="com.hours28.domain.entity.Supplier"/> </class-descriptor>
<class-descriptor
class="com.hours28.domain.entity.Employee"
table="Employee">
<field-descriptor
name="oid"
column="employeeId"
jdbc-type="INTEGER"
primarykey="true"
autoincrement="true"/>
<field-descriptor
name="userName"
column="userName"
jdbc-type="VARCHAR"/>
<field-descriptor
name="password"
column="password"
jdbc-type="VARCHAR"/>
<field-descriptor
name="restricted"
column="restricted"
jdbc-type="BIT"/>
<field-descriptor
name="notes"
column="notes"
jdbc-type="VARCHAR"/>
<field-descriptor
name="imageStoredFileId"
column="imageStoredFileId"
jdbc-type="INTEGER"/>
<reference-descriptor
name="image"
class-ref="com.hours28.domain.entity.StoredFile">
<foreignkey field-ref="imageStoredFileId"/>
</reference-descriptor>
<field-descriptor
name="securityLevelId"
column="securityLevelId"
jdbc-type="INTEGER"/>
<reference-descriptor
name="securityLevel"
class-ref="com.hours28.domain.entity.SecurityLevel">
<foreignkey field-ref="securityLevelId"/>
</reference-descriptor>
<collection-descriptor
name="devices"
element-class-ref="com.hours28.domain.entity.ContactDevice"
auto-retrieve="true"
auto-update="true"
indirection-table="EmployeeContactDevice">
<fk-pointing-to-this-class column="employeeId"/>
<fk-pointing-to-element-class column="contactDeviceId"/>
</collection-descriptor>
<collection-descriptor
name="addresses"
element-class-ref="com.hours28.domain.entity.Address"
auto-retrieve="true"
auto-update="true"
indirection-table="EmployeeAddress">
<fk-pointing-to-this-class column="employeeId"/>
<fk-pointing-to-element-class column="addressId"/>
</collection-descriptor>
<field-descriptor
name="jobTitle"
column="jobTitle"
jdbc-type="VARCHAR"/>
<field-descriptor
name="startedWork"
column="startedWork"
jdbc-type="DATE"/>
<field-descriptor
name="title"
column="title"
jdbc-type="VARCHAR"/>
<field-descriptor
name="firstNames"
column="firstNames"
jdbc-type="VARCHAR"/>
<field-descriptor
name="lastName"
column="lastName"
jdbc-type="VARCHAR"/>
<field-descriptor
name="dateOfBirth"
column="dateOfBirth"
jdbc-type="DATE"/>
<field-descriptor
name="companyId"
column="companyId"
jdbc-type="INTEGER"
access="anonymous"/>
<reference-descriptor
name="company"
class-ref="com.hours28.domain.entity.Company">
<foreignkey field-ref="companyId"/>
</reference-descriptor>
<field-descriptor
name="interests"
column="interests"
jdbc-type="VARCHAR"/>
<collection-descriptor
name="contracts"
element-class-ref="com.hours28.domain.entity.EmployeeContract"
collection-class="com.hours28.domain.entity.EmployeeContractCollection"
auto-retreive="true"
auto-update="true">
<inverse-foreignkey field-ref="employeeId"/>
</collection-descriptor>
<collection-descriptor
name="employeeServiceDetails"
element-class-ref="com.hours28.domain.entity.EmployeeServiceDetail"
collection-class="com.hours28.domain.entity.EmployeeServiceDetailCollection"
auto-retreive="true" auto-update="true"> <inverse-foreignkey field-ref="employeeId"/> </collection-descriptor> </class-descriptor>
<class-descriptor class="com.hours28.domain.entity.Supplier" table="Supplier"> <field-descriptor name="oid" column="supplierId" jdbc-type="INTEGER" primarykey="true" autoincrement="true"/> <field-descriptor name="userName" column="userName" jdbc-type="VARCHAR"/> <field-descriptor name="password" column="password" jdbc-type="VARCHAR"/> <field-descriptor name="restricted" column="restricted" jdbc-type="BIT"/> <field-descriptor name="notes" column="notes" jdbc-type="VARCHAR"/> <field-descriptor name="imageStoredFileId" column="imageStoredFileId" jdbc-type="INTEGER"/> <reference-descriptor name="image" class-ref="com.hours28.domain.entity.StoredFile"> <foreignkey field-ref="imageStoredFileId"/> </reference-descriptor> <field-descriptor name="securityLevelId" column="securityLevelId" jdbc-type="INTEGER"/> <reference-descriptor name="securityLevel" class-ref="com.hours28.domain.entity.SecurityLevel"> <foreignkey field-ref="securityLevelId"/> </reference-descriptor> <collection-descriptor name="devices" element-class-ref="com.hours28.domain.entity.ContactDevice" auto-retrieve="true" auto-update="true" indirection-table="SupplierContactDevice"> <fk-pointing-to-this-class column="supplierId"/> <fk-pointing-to-element-class column="contactDeviceId"/> </collection-descriptor> <collection-descriptor name="addresses" element-class-ref="com.hours28.domain.entity.Address" auto-retrieve="true" auto-update="true" indirection-table="SupplierAddress"> <fk-pointing-to-this-class column="supplierId"/> <fk-pointing-to-element-class column="addressId"/> </collection-descriptor> <field-descriptor name="name" column="name" jdbc-type="VARCHAR"/> <field-descriptor name="forReal" column="forReal" jdbc-type="BIT"/> <field-descriptor name="preferredBookingDeviceId" column="preferredBookingDeviceId" jdbc-type="INTEGER" access="anonymous"/> <reference-descriptor name="preferredBookingDevice" class-ref="com.hours28.domain.entity.ContactDevice"> <foreignkey field-ref="preferredBookingDeviceId"/> </reference-descriptor> <field-descriptor name="abn" column="abn" jdbc-type="VARCHAR"/> <field-descriptor name="acn" column="acn" jdbc-type="VARCHAR"/> <field-descriptor name="beganBusiness" column="beganBusiness" jdbc-type="DATE"/> <field-descriptor name="description" column="description" jdbc-type="VARCHAR"/> </class-descriptor>
It has something to
Armin Waibel wrote:
Hi Raymond,
> I suspect it is something still hanging around from rc3 in my paths. > I've updated all the relevant jars (that I can think of), the > OJB.properties, the repository xml files etc.
ok, that's all you can do. hmm, your code works with rc3 and don't work with rc5 - right? If so, sounds like a bug in rc5.
Make OJB jars with target 'jar-debug' instead 'jar', then the line numbers will be included in stack trace.
Could you post the class-descriptor for Employee? I will try to write a test case for your problem.
regards, Armin
Raymond Barlow wrote:
Hi all,
I've been chasing this all day, and have gotten no further *sigh*.
Why does the following code give me a ClassCastException on the getCollectionByQuery??
PersistenceBroker broker = null; Criteria criteria = new Criteria(); criteria.addEqualTo("userName", "test"); Query query = new QueryByCriteria(Employee.class, criteria); try { broker = PersistenceBrokerFactory.defaultPersistenceBroker(); //dies on this line: Collection results = broker.getCollectionByQuery(query); Vector v = new Vector(); v.addAll(results); Employee u = (Employee)v.get(0); System.out.println(u.getUserName()); } catch (Throwable t) { t.printStackTrace(); } finally { if(broker != null) broker.close(); }
stack trace:
org.apache.ojb.broker.PersistenceBrokerException: java.lang.ClassCastException
at org.apache.ojb.broker.core.QueryReferenceBroker.getCollectionByQuery(Unknown Source)
at org.apache.ojb.broker.core.QueryReferenceBroker.getCollectionByQuery(Unknown Source)
at org.apache.ojb.broker.core.PersistenceBrokerImpl.getCollectionByQuery(Unknown Source)
at org.apache.ojb.broker.core.DelegatingPersistenceBroker.getCollectionByQuery(Unknown Source)
at org.apache.ojb.broker.core.DelegatingPersistenceBroker.getCollectionByQuery(Unknown Source)
at com.hours28.test.TempTest.test1(TempTest.java:40)
at com.hours28.test.TempTest.main(TempTest.java:28)
Caused by: java.lang.ClassCastException
at org.apache.ojb.broker.accesslayer.BasePrefetcher.prefetchRelationship(Unknown Source)
at org.apache.ojb.broker.core.QueryReferenceBroker.performRetrievalTasks(Unknown Source)
at org.apache.ojb.broker.core.QueryReferenceBroker.getCollectionByQuery(Unknown Source)
... 7 more
I suspect it is something still hanging around from rc3 in my paths. I've updated all the relevant jars (that I can think of), the OJB.properties, the repository xml files etc.
Another strange thing about this is that if I run this twice (ie, after the exception, try it again without restarting the session), it works. Strange. It seems like it just doesn't load classes correctly on the first search for them.
Any suggestions?
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
