Hibernation and inheritance display issues with @SecondaryTable
I have a fairly simple hierarchical class structure as shown below, with each subclass having an @DiscriminatorValue enum type that works really well.
Abstract class:
AbstractNode (abstract class mapped to Node table)
Class subclasses:
FieldNode (simple class mapped to Node table but with different @DiscriminatorValue)
SynonymNode (problem class, this class also maps to Node table with different @DiscriminatorValue)
but ALSO has a @SecondaryTable attribute and has additional columns like deletedDate, createdDate, etc ... each of which matches the cumum in the table defined in the @SecondaryTable attribute.
The problem I'm with comes when I make a simple hibernate query for this Node table
I am getting errors like:
org.hibernate.exception.GenericJDBCException: Failed to execute query ... stack trace ... Thrown by: java.sql.SQLException: Invalid column name
and in my logs I 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 and then indicates that it is the type of the SynonymNode class (by @DiscriminatorValue column), then tries to populate the class including the additional columns table mapped to @SecondaryTable.
How can I tell this to either, or join @SecondaryTable, or exclude it altogether for this particular request?
Thanks heaps! This problem is killing me!
I'm working with Hibernate 3.2.1 and Java 1.5
Cheers, Mark
a source to share
I believe the problem is that you have to specify which fields you map to your @SecondaryTable ...
In the @Column annotation, set the "table" attribute: @Column (name = "somecol", table = "secondaryTable")
Hibernate is complaining because it looks for your fields in the original table when it should look for them in the secondary table.
a source to share