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

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

  • Purpose: Existing Glassfish Server
  • Configuration: EJB module + Files for deploying GlassFish Descriptor + Java + JPA In the JPA Facet window, I announce the connection to postgres db (successful ping)

I have a problem when I try to define an object: The Employee table cannot be resolved. I added an @Table annotation with the specified name parameter, but that didn't work. My persistence.xml file:

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

In a glass fish, I defined a JDBC resource with the name: "jdbc / baza1Postgres"
How does eclipse know if my table exists? What else do I need to configure?

+6
source share
7 answers

Found this solution so that the error "Table xxx was not resolved":

In Eclipse, go to Window -> Preferences -> Validation, JPA Validator, turn it off to build.

Sometimes you develop an application along with a new database schema to go with it, but you get the following:

The null schema cannot be allowed for table XXXX.

This should probably not be enabled by default; "people are more likely to create new applications from scratch than to create new applications to match old databases, and even if they build from old ones, Eclipses JPA Tools has objects built from tables."

+30
source

In Eclipse, to make him happy, I had to create a table through JPA Tools.

Right click on the project> JPA Tools> Generate Tables from Objects

I think you can disable validation too, but creating a table seems more reasonable.

+4
source

You need to specify in the persistence.xml file where to look for objects, see the Java EE 6 tutorial , here is an example taken from there:

Conservation Units

A persistence unit defines a set of entire entity classes that are managed by EntityManager instances in the application. This set of feature classes represents data contained in a single data warehouse.

Save units are saved in the configuration of the persistence.xml file. The following is an example persistence.xml file:

  <persistence> <persistence-unit name="OrderManagement"> <description>This unit manages orders and customers. It does not rely on any vendor-specific features and can therefore be deployed to any persistence provider. </description> <jta-data-source>jdbc/MyOrderDB</jta-data-source> <jar-file>MyOrderApp.jar</jar-file> <class>com.widgets.Order</class> <class>com.widgets.Customer</class> </persistence-unit> </persistence> 

This file defines a persistence unit called OrderManagement, which uses a data source that supports JTA: JDBC / MyOrderDB. File and class jar elements define managed persistence classes: entity classes, nested classes, and associated superclasses. The jar-file element indicates JAR files that are visible for a packaged persistence unit that contain managed stability classes, while the class element explicitly calls managed persistence classes.

Also consider this fooobar.com/questions/59572 / ... using sleep mode, which you can scan for your classes that have an Entity annotation

+3
source

I am using Eclipse. I noticed that eclipse recognizes tables when I use the Data Source Explorer window in JPA eviroment (itโ€™s probably not necessary to compile, but it is useful to check the database in the same Eclipse IDE). Then, when I created the database connection in this window, I received data about the change in the problem in the connection properties:

NOt Working (table cannot be resolved):

 Database: my_database URL: jdbc:mysql://localhost:3306 User Name: jpa_user Password: jpa_pass 

Bugfix (I add the database in the URL field):

 Database: my_database URL: jdbc:mysql://localhost:3306/my_database User Name: jpa_user Password: jpa_pass 

Remember to use @Table (name = "") in your entities if the tables do not have upper case in the database.

+3
source

I had this error, and I managed to get it to work with very tortuous efforts. I am using PostgreSQL.

First of all, I did this, as suggested above, and turned off validation for the build. Then I checked the check manually by tying things together. My steps were essentially this:

1: connect through the data source explorer to my database. Make sure the connection is in the correct state and I go to TABLES and update the message. Connection update error did not update tables.

2: Probably optional, but I used JPA Tools to export the schema to the database. Again, I click update as in step 1.

3: annotate an object with both an entity and a table. Add a name to the entity and NAME, CATALOG, and SCHEMA in the table annotation.

 @Entity(name="DBAssembly") @Table(name="DBAssembly",catalog="lag",schema="public") 

4: perform manual check. Adding a directory was important. This is very picky.

+1
source

Another option using maxmcbyte answer is to install it only for certain projects. Right-click the project and select Validation. Turn on special project settings and disable Validator for build.

0
source

It works, but in addition to the maxmcbyte (thanks !!) answer, itโ€™s better to apply this solution only for some projects several times, do it individually by referring to: project properties> Validation> Turn to "Project settings included" and then override off . JPA Validation in Build Column . See Image ...

Config

0
source

Source: https://habr.com/ru/post/897630/


All Articles