Eclipse reports error on my JPA project

前端 未结 10 1950
-上瘾入骨i
-上瘾入骨i 2021-02-04 07:39

Each time I make a JPA project Eclipse reports that there are errors in my project but I do not understand why it does so. I added image and errors below:

相关标签:
10条回答
  • 2021-02-04 08:10

    Read This if you want to solve your problem easily

    There is no problem in your Database. You just have to create a new connection from Eclipse to the same database which we do during Adding JPA capabilities to the Project.

    Steps:-
    Create a new database from your mysql prompt.
    Right click on your Project in Eclipse/MyEclipse, then go to Properties.
    Click on Eclipse/MyEclipse tab on the left and then click on JPA sub menu.
    Then Click on Create new Connection. Put a new Connection name. And add the same Database. (You can opt to change your database too, but same database will also do).
    Test Connection, and click on Finish.
    First Time it wont show that newly created Connection name. Just Click Ok to close that Window.

    Then, Right Click again on Project and then Click on Propeties. Now you can see your newly created Connection on that Connection drop down list. Selct that and Click OK.

    Your Error will vanish.

    Possible Reason for this error:-
    Eclipse creates connection with you database everytime you connect using any project using persistence.xml, but only for the first time.
    So, any changes after that, especially from the database side(table name etc.) will throw an error from Eclipse.

    Thank You.

    0 讨论(0)
  • 2021-02-04 08:10

    The annotations look correct, are you sure your project classpath is good? try and build the entity without the id and title fields first of all.

    0 讨论(0)
  • 2021-02-04 08:17

    Do you have the JPA/JPA2 interfaces included in your project? If you are using maven, you need to include a dependency for the classes. I assume that they are since there are no red lines appearing in the import declarations, but just to be safe, you should validate that they exist.

    For a JPA2 dependency, you can use:

    <dependency>
        <groupId>org.hibernate.javax.persistence</groupId>
        <artifactId>hibernate-jpa-2.0-api</artifactId>
        <version>1.0.0.Final</version>
    </dependency>
    
    0 讨论(0)
  • 2021-02-04 08:18

    Try doing code assist inside the quotes of @Column(name=""). Or open the JPA Details view and view the column name combo to see the column options. There is no validation error on the @Table(name="page") annotation, so it looks like Eclipse is finding the page table.

    0 讨论(0)
  • 2021-02-04 08:20

    I've had the same problem, the solution for me was to refresh the database connection.

    Open the JPA view, find the data source explorer. There you open Database Connection, connect with your database, hit refresh. Then make some changes in your file and save it, i added an @Column(name = "") annotation to my id field. After that the error message was gone, and i ereased the Column annotation.

    The Problem seems to be that eclipse reads the database tables after establishing the first connection, after that the connection is closed. So if you, like i did, made some changes after this first connection in your database, like changing the field name from foo_id to just id, eclipse didn't know that and comes with this error.

    0 讨论(0)
  • 2021-02-04 08:28

    Go to Data Source Explorer, disconnect the database connection, after connect the database connection, right click in your project and click in validate.

    I hope it helps you.

    0 讨论(0)
提交回复
热议问题