Reputation: 8184
I'm trying to generate a database created from entities. I'm using Hibernate, PostgreSQL, Tomcat6 and Eclipse for development.
Here's what one of the entities look like:
package pass.entities;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
@Entity
@Table(catalog = "pass2")
@SequenceGenerator(allocationSize=1,
initialValue=1,
sequenceName = "AL_seq",
name ="AL_gen")
public class AnoLectivo implements Serializable{
private static final long serialVersionUID = -2663573189740765100L;
@Id
@GeneratedValue(generator="AL_gen")
private int ent_id;
private String id;
/...
}
And this is the persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="AnoLectivoSrv" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>pass.entities.AnoLectivo</class>
<class>test.Test</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:postgresql:postgres"/>
<property name="javax.persistence.jdbc.user" value="postgres"/>
<property name="javax.persistence.jdbc.password" value="admin"/>
<property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver"/>
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
</properties>
</persistence-unit>
</persistence>
The problem is that in the entity class the "@Table" annotation is always underlined with an error stating the «Table "AnoLectivo" cannot be resolved» .
I've searched a lot so far but haven't solved this yet... any idea? cheers
Upvotes: 1
Views: 1962
Reputation: 8184
I had a problem on the platform selected: Going to project properties -> Java persistence , I saw that the selected platform was "Generic 2.0". Installed the Hibernate Tools plugins from this update site: download.jboss.org/jbosstools/updates/stable , restarted Eclipse, selected the platform as Hibernate 2.x and magic! It worked!
Upvotes: 2
Reputation: 76729
This has a lot to do with the Dali JPA Tools available in Eclipse. The error message (generated by the JPA validator) simply means that there was attempt made to verify if the table existed in the database specified in the currently configured database connection for the project.
Once you connect to the right database, or make the tables available in the database, the error should go away.
Turning off the JPA validator
When building a JPA application against a blank database schema, it is possible that these messages simply will not be resolved until the tables are created. If the JPA provider is responsible for creating the tables, then one would have a chicken and egg problem. This can be avoided by switching off the JPA validator, using the following steps.
Upvotes: 1