users@glassfish.java.net

Problems with DiscriminatorColumn

From: <glassfish_at_javadesktop.org>
Date: Fri, 27 Apr 2007 12:41:24 PDT

I have an abstract class which is declared as follows:

@Entity
@Table(name="SMementos")
@Inheritance(strategy=JOINED)
@DiscriminatorColumn(name="ModelKind", discriminatorType=INTEGER)
public abstract class SMemento {
...
@Column(name="ModelKind")
private int modelKindField;
...
public int getModelKind() { return modelKindField); }
public void setModelKind(int modelKind) { modelKindField = modelKind; }
...
}

And a concrete class with declarations as follows:

@Entity
@Table(name="SElements")
@PrimaryKeyJoinColumn(name="ElementId")
@DiscriminatorValue(value="10000")
public class SElement extends SMemento {
...
}

When I try to run the following code:

        public static void main( String[] args ) {
                // Create EntityManagerFactory for persistent unit named "pu1"
                // to be used in this test.
                EntityManagerFactory emf = Persistence.createEntityManagerFactory( "pu1" );
                EntityManager entityManager = emf.createEntityManager();

                SElement element = new SElement();

                entityManager.getTransaction().begin();

                entityManager.persist( element );

                entityManager.getTransaction().commit();
        }

I get this exception on the commit():

Call: INSERT INTO SMementos (MementoId, MODIFYDATE, ModelKind, CREATEDATE) VALUES (?, ?, ?, ?)
        bind => [ffa80f123488517d, 2007-04-27 12:33:08.093, 10000, 2007-04-27 12:33:08.093]
Query: InsertObjectQuery(SElement: GUID == ffa80f123488517d, tripletCount == 0)
        at oracle.toplink.essentials.exceptions.DatabaseException.sqlException(DatabaseException.java:296)
        at oracle.toplink.essentials.internal.databaseaccess.DatabaseAccessor.executeDirectNoSelect(DatabaseAccessor.java:639)
        at oracle.toplink.essentials.internal.databaseaccess.DatabaseAccessor.executeNoSelect(DatabaseAccessor.java:688)
        at oracle.toplink.essentials.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:477)
        at oracle.toplink.essentials.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:437)
        at oracle.toplink.essentials.internal.sessions.AbstractSession.executeCall(AbstractSession.java:675)
        at oracle.toplink.essentials.internal.queryframework.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:213)
        at oracle.toplink.essentials.internal.queryframework.DatasourceCallQueryMechanism.insertObject(DatasourceCallQueryMechanism.java:322)
        at oracle.toplink.essentials.internal.queryframework.StatementQueryMechanism.insertObject(StatementQueryMechanism.java:176)
        at oracle.toplink.essentials.internal.queryframework.StatementQueryMechanism.insertObject(StatementQueryMechanism.java:190)
        at oracle.toplink.essentials.internal.queryframework.DatabaseQueryMechanism.insertObjectForWrite(DatabaseQueryMechanism.java:457)
        at oracle.toplink.essentials.queryframework.InsertObjectQuery.executeCommit(InsertObjectQuery.java:74)
        at oracle.toplink.essentials.internal.queryframework.DatabaseQueryMechanism.performUserDefinedWrite(DatabaseQueryMechanism.java:635)
        at oracle.toplink.essentials.internal.queryframework.DatabaseQueryMechanism.performUserDefinedInsert(DatabaseQueryMechanism.java:599)
        at oracle.toplink.essentials.internal.queryframework.DatabaseQueryMechanism.insertObjectForWriteWithChangeSet(DatabaseQueryMechanism.java:495)
        at oracle.toplink.essentials.queryframework.WriteObjectQuery.executeCommitWithChangeSet(WriteObjectQuery.java:130)
        at oracle.toplink.essentials.internal.queryframework.DatabaseQueryMechanism.executeWriteWithChangeSet(DatabaseQueryMechanism.java:283)
        at oracle.toplink.essentials.queryframework.WriteObjectQuery.executeDatabaseQuery(WriteObjectQuery.java:67)
        at oracle.toplink.essentials.queryframework.DatabaseQuery.execute(DatabaseQuery.java:613)
        at oracle.toplink.essentials.queryframework.DatabaseQuery.executeInUnitOfWork(DatabaseQuery.java:540)
        at oracle.toplink.essentials.queryframework.ObjectLevelModifyQuery.executeInUnitOfWorkObjectLevelModifyQuery(ObjectLevelModifyQuery.java:123)
        at oracle.toplink.essentials.queryframework.ObjectLevelModifyQuery.executeInUnitOfWork(ObjectLevelModifyQuery.java:95)
        at oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2219)
        at oracle.toplink.essentials.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:937)
        at oracle.toplink.essentials.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:894)
        at oracle.toplink.essentials.internal.sessions.CommitManager.commitNewObjectsForClassWithChangeSet(CommitManager.java:254)
        at oracle.toplink.essentials.internal.sessions.CommitManager.commitAllObjectsWithChangeSet(CommitManager.java:175)
        at oracle.toplink.essentials.internal.sessions.AbstractSession.writeAllObjectsWithChangeSet(AbstractSession.java:2638)
        at oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl.commitToDatabase(UnitOfWorkImpl.java:1030)
        at oracle.toplink.essentials.internal.ejb.cmp3.base.RepeatableWriteUnitOfWork.commitToDatabase(RepeatableWriteUnitOfWork.java:387)
        at oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl.commitToDatabaseWithChangeSet(UnitOfWorkImpl.java:1112)
        at oracle.toplink.essentials.internal.ejb.cmp3.base.RepeatableWriteUnitOfWork.commitRootUnitOfWork(RepeatableWriteUnitOfWork.java:91)
        at oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl.commitAndResume(UnitOfWorkImpl.java:842)
        at oracle.toplink.essentials.internal.ejb.cmp3.transaction.base.EntityTransactionImpl.commit(EntityTransactionImpl.java:87)
        ... 7 more
Caused by: org.postgresql.util.PSQLException: ERROR: column "modelkind" is of type integer but expression is of type character varying
        at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1548)
        at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1316)
        at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:191)
        at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:452)
        at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:351)
        at org.postgresql.jdbc2.AbstractJdbc2Statement.executeUpdate(AbstractJdbc2Statement.java:305)
        at oracle.toplink.essentials.internal.databaseaccess.DatabaseAccessor.executeDirectNoSelect(DatabaseAccessor.java:632)
        ... 39 more

Stepping through the code it appears the that type of the discriminator value (which must be a string) overrides the type of the column (the docs say an attempt will be made to turn the string into the appropriate type). Am I missing something?

Brian
[Message sent by forum member 'bgladish' (bgladish)]

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