EJB3 @Column annotation problem

I am trying to annotate a class property using javax.persistence.Column annotation and trying to map the class property to a different database column name, but IntelliJ gives a syntax error. Here is the code:

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "USERID")
private int userId;

There is no syntax error in the code, i can compile it using javac, but IntelliJ underlines "USERID" and says "Cannot resolve symbol"

The same code works perfectly in Netbeans.

Thank you

3 comments
Comment actions Permalink

Hello Erdinc,

You might want to make sure that the datasource you assigned to the persistence
unit (place the cursor on the highlighted error and IDEA's going to offer
to assign a datasource to the persistence unit if you haven't done so, yet)
is up to date with the most current table definition. If everything else
works but just the column name is not recognized, you might have an old table
definition (IDEA loads the definitions when you define/reload the datasource
and stores them in the project file, for efficiency reasons).

HTH,
Andrei

EY> I am trying to annotate a class property using
EY> javax.persistence.Column annotation and trying to map the class
EY> property to a different database column name, but IntelliJ gives a
EY> syntax error. Here is the code:
EY>
EY> @Id
EY> @GeneratedValue(strategy = GenerationType.AUTO)
EY> @Column(name = "USERID")
EY> private int userId;
EY> There is no syntax error in the code, i can compile it using javac,
EY> but IntelliJ underlines "USERID" and says "Cannot resolve symbol"
EY>
EY> The same code works perfectly in Netbeans.
EY>
EY> Thank you
EY>


0
Comment actions Permalink

A slightly related problem...

@Column(name="\"YEAR\"")
public String getYear() { /* ... */ }

underlines \"YEAR\" even though the escaped quotes are required in order to ensure that the generated SQL does not throw exceptions from the use of the reserved word as a column name in the stupid legacy database that I have to map!

People also use quotes for case sensitive column names

0
Comment actions Permalink

You need to refresh the datasource from tools->datasources.
Select the datasource, click "properties", and "refresh tables".

It might be good idea to have a keyboard shortcut (and possibly a context menu item) that does that refresh action instantly. Saves a lot of frustration and a lot of mouseclicks/keystrokes when working with a rapidly evolving schema (rather than a mostly static one as would be encountered with mature systems).

0

Please sign in to leave a comment.