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
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!