• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate: Problem with @SecondaryTable annotation

 
Fernando Deutsch
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is my scenario.

Table: forum_topics
id : int (pk)
board_id : int
firstMessage_id : int

Table: forum_messages
id : int (pk)
subject : varchar(100)

I have a Topic Entity with forum_topics as base table, I want to include the topic "subject" from forum_messages table by a join on column forum_topics.firstMessage_id -> forum_messages.id



When I run the application (WebApp) I got the following message:


Invocation of init method failed; nested exception is org.hibernate.AnnotationException: SecondaryTable JoinColumn cannot reference a non primary key


If I swap the columns on the pkJoinColumns like:



I can run the application, but when I try to resolve Topic objects from a board_id I get the following error:


could not execute query; SQL [select topic0_.id as id1_, topic0_.board_id as board2_1_, topic0_.firstMessage_id as firstMes3_1_, topic0_1_.subject as subject2_ from forum_topics topic0_ left outer join forum_messages topic0_1_ on topic0_.id=topic0_1_.firstMessage_id where topic0_.board_id=?]; nested exception is org.hibernate.exception.SQLGrammarException: could not execute query


It looks to me like the validation of the columns involved on the Join is done in one direction, and the execution is done on reverse.

I am doing something wrong or missing something ? I am using hibernate3. The query I try to accomplish would be something like:


select A.id, A.board_id, A.firstMessage_id, B.subject from forum_topics A, forum_messages B where A.firstMessage_id = B.id and A.board_id = ? (of course with a left outer join)


Appreciate any help you could provide to me.

Thanks.
 
Fernando Deutsch
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No one has passed through this issue ?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic