views:

511

answers:

1

I have a pretty simple class hierarchy structure that is listed below, each sub class having a @DiscriminatorValue enumeration type, which works very well.

Abstract class:

AbstractNode (abstract class mapped to the Node table)

Subclassed classes:

FieldNode (simple class mapped to Node table as well, but with different @DiscriminatorValue value)

SynonymNode (problem class, this class also maps to the Node table with a different @DiscriminatorValue value)

but ALSO has a @SecondaryTable attribute and has extra columns, such as deletedDate, createdDate, etc... each which map to coumns in the table defined in the @SecondaryTable attribute.

Im issue comes when I do a simple hibernate query for that Node table

I get errors like:

org.hibernate.exception.GenericJDBCException: could not execute query ... stack trace ... Caused by: java.sql.SQLException: Invalid column name

and in my logs I can see:

Hibernate: Select * from vocab_node where lower(name) like '%' || ? || '%'

INFO [NullableType.java:132] : could not read column value from result set: DELETED_DATE; Invalid column name

My guess is that it finds a row in the DB table, then identifies that is is a SynonymNode class type (by the @DiscriminatorValue column) then tries to populate the class including the extra columns table mapped with the @SecondaryTable.

How can I tell it to either, left join the @SecondaryTable, or exclude it altogether for this particular query?

Thanks heaps! This issue is killing me!

Im running Hibernate 3.2.1, and Java 1.5

Cheers, Mark

+1  A: 

I believe the problem is that you have to specify which fields you are mapping to your @SecondaryTable...

In the @Column annotation set the "table" attribute: @Column(name="somecol", table="secondaryTable")

Hibernate is complaining because it is looking for your fields in the original table when it should be looking for them in the secondary table.

jonnysamps