• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

many-to-one mapping issue EJB

 
Mark Calder
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is homework and I don't understand so help is appreciated. The system is an Olympic medal tally simulator.

We have an Events table and a Countries table:

These relate to entities:

The question says to add three Country instance variables to Event to represent the gold, silver and bronze winners and include the relationship type. To me it makes sense to be a many-to-one. But, when I try run this I get an error about join being wrong because it should allow only one write and the rest as read only.

So, I changed the JoinColumn to insertable=false and get an error: Column 'COUNTRYID' is either not in any table in the FROM list or appears within a join specification and is outside the scope of the join specification or appears in a HAVING clause and is not in the GROUP BY list.

Which is hit at this method in my QueriesBean:

Perhaps someone can give me some guidance?
 
James Sutherland
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The issue is that the default foreign key field (JoinColumn) is derived from the Country, so all three relationships end up trying to share the same COUNTRYID.

You need to specify a different JoinColumn, i.e. @JoinColumn(name="BRONZE_ID") for each relationship. (you must have three foreign keys).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic