users@glassfish.java.net

Inheritance problems

From: <glassfish_at_javadesktop.org>
Date: Fri, 18 Jan 2008 07:38:58 PST

I am trying to implement persistence on an existing database.

I am having problems fetching data from a table that has sub-types.

The supertype table is OBJ_ITEM and the subtype table is ORG.
The OBJ_ITEM table's primary key is obj_item_id and it's discriminator column is cat_code.
The ORG table's primary key is org_id (it is a rolenamed foreign key).

the obj_item annotations are:
@Entity
@Table(name="OBJ_ITEM", schema="dbo")
@Inheritance(strategy=InheritanceType.JOINED)
@DiscriminatorColumn(name="cat_code")
@DiscriminatorValue("NKN")
public class ObjectItem

and the org annotations are:
@Entity
@Table(name="ORG", schema="dbo")
@DiscriminatorColumn(name="cat_code")
@PrimaryKeyJoinColumn(name="org_id", referencedColumnName="obj_item_id")
@DiscriminatorValue("OR")

I have a test program that fetches an ObjectItem that is in the dbase but I get the following error

[TopLink Info]: 2008.01.18 08:44:54.125--ServerSession(23845098)--TopLink, version: Oracle TopLink Essentials - 2.0.1 (Build b09d-fcs (12/06/2007))
[TopLink Info]: 2008.01.18 08:44:54.593--ServerSession(23845098)--file:/C:/projects/Jc3iedmApi/build/classes/-Jc3iedmApi login successful
[TopLink Warning]: 2008.01.18 08:44:54.796--ServerSession(23845098)--Exception [TOPLINK-4002] (Oracle TopLink Essentials - 2.0.1 (Build b09d-fcs (12/06/2007))): oracle.toplink.essentials.exceptions.DatabaseException
Internal Exception: com.microsoft.sqlserver.jdbc.SQLServerException: Invalid column name 'obj_item_id'.
Error Code: 207
Call: SELECT DISTINCT t0.cat_code FROM dbo.OBJ_ITEM t0, dbo.ORG t1 WHERE (((t1.obj_item_id = ?) AND (t1.org_id = t0.obj_item_id)) AND t0.cat_code IN (?, ?, ?))
        bind => [34000000000000000000, OR, UN, CO]
Query: ReadObjectQuery(mil.simci.Jc3iedmApi.Organisation)
[TopLink Warning]: 2008.01.18 08:44:54.812--UnitOfWork(19171705)--Exception [TOPLINK-106] (Oracle TopLink Essentials - 2.0.1 (Build b09d-fcs (12/06/2007))): oracle.toplink.essentials.exceptions.DescriptorException
Exception Description: The method [setObjectItemLocationInObjectItem] on the object is throwing an exception.
Argument: [{IndirectList: not instantiated}]
Internal Exception: java.lang.reflect.InvocationTargetException
Target Invocation Exception: Exception [TOPLINK-4002] (Oracle TopLink Essentials - 2.0.1 (Build b09d-fcs (12/06/2007))): oracle.toplink.essentials.exceptions.DatabaseException
Internal Exception: com.microsoft.sqlserver.jdbc.SQLServerException: Invalid column name 'obj_item_id'.
Error Code: 207
Call: SELECT DISTINCT t0.cat_code FROM dbo.OBJ_ITEM t0, dbo.ORG t1 WHERE (((t1.obj_item_id = ?) AND (t1.org_id = t0.obj_item_id)) AND t0.cat_code IN (?, ?, ?))
        bind => [34000000000000000000, OR, UN, CO]
Query: ReadObjectQuery(mil.simci.Jc3iedmApi.Organisation)


The test program worked before I setup other tables with associations to org, so I suspect that the error is happening when toplink is trying to traverse from org to obj_item and not when it's going from obj_item to org...

The query should either be using "t1.org_id = ?" or "t0.obj_item_id = ?" in the where clause...

I tried to change the @Inheritance to use the table_per_class strategy but top-link said that wasn't a supported strategy...

Is this a bug in top-link or am I missing an annotation?
Has anyone ever tried to have sub-type tables with rolenamed foreign keys?
[Message sent by forum member 'tfriest' (tfriest)]

http://forums.java.net/jive/thread.jspa?messageID=254687