我正在尝试生成从实体创建的数据库。我正在使用 Hibernate、PostgreSQL、Tomcat6 和 Eclipse 进行开发。
以下是其中一个实体的样子:
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;
/...
}
这是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>
问题在于,在实体类中,“@Table”注释始终带有下划线,并带有错误说明 «Table "AnoLectivo" cannot be resolve»。
到目前为止,我已经搜索了很多,但还没有解决这个问题......任何想法?干杯