Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem with JPA Project in Eclipse - error in class annotated @Entity: Table "xxx" cannot be resolved

I'm trying to create simple EJB + JPA project in Eclipse (Indigo). I created new EJB project where:

  • Target: existing Glassfish Server
  • Configuration: EJB Module + GlassFish Deployment Descriptor Files + Java + JPA In window JPA Facet I declare connection to postgres db (ping successful)

I have problem when I'm trying to define entity: Table "Employee" cannot be resolved. I added @Table annotation with specified name parameter but this didn't work. My persistence.xml file:

    <persistence-unit name="pu_name">
    <jta-data-source>jdbc/baza1Postgres</jta-data-source>
</persistence-unit>

In glassfish I have defined JDBC Resource with name: "jdbc/baza1Postgres"
How "eclipse know" if my table exist? What else I should configure?

like image 432
Adam Szecowka Avatar asked Sep 19 '11 18:09

Adam Szecowka


2 Answers

Found this solution to "Table xxx cannot be resolved" error:

In Eclipse, go to Window -> Preferences -> Validation, JPA Validator, turn off for Build.

Sometimes you’re developing an app along with a new database schema to go with it, but you get this:

Schema "null" cannot be resolved for table "XXXX".

This probably shouldn’t be on by default anyway; people are most likely going to build new apps from scratch than build new apps to fit old databases, and even if they do build from old, Eclipse’s JPA Tools has a build entities from tables function."

like image 92
maxmcbyte Avatar answered Oct 10 '22 15:10

maxmcbyte


In Eclipse to make it happy I had to create the table via JPA Tools.

Right Click Project > JPA Tools > Generate Tables from Entities

I guess you could turn off validation too, but creating the table seems to make more sense.

like image 29
bobtheowl2 Avatar answered Oct 10 '22 16:10

bobtheowl2