2011-11-01 123 views
0

我试图将Hibernate(3.2.5)与PostgreSQL 8.2连接起来,但是当我尝试在hbm.xml文件中映射具有关系证书的类证书时,出现以下异常:无法连接Postgres与休眠

**

PSQLException: ERROR: relation "certificate" does not exist

**

创建的SQL证书:

CREATE TABLE "Certificate" ( id bigint NOT NULL,
name text,
CONSTRAINT certificate_pk1 PRIMARY KEY (id)
) WITHOUT OIDS;

的POJO CLAS '证书' 是:

public class Certificate implements Serializable { 
private static final long serialVersionUID = 1L; 
private Long id; 

private String name; 

public String getName() { 
    return name; 
} 

public void setName(String name) { 
    this.name = name; 
} 

public Long getId() { 
    return id; 
} 

public void setId(Long id) { 
    this.id = id; 
} 


public String toString() { 
    return "model.Certificate[id=" + id + "]"; 
} 

}

hibernate.cfg.xml文件:

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.url">jdbc:postgresql://localhost /Company</property>
<property name="hibernate.connection.username">postgres</property>
<property name="hibernate.connection.password">abc123</property>
<mapping resource="hibernate.hbm.xml"/>
</session-factory>
</hibernate-configuration>

回答

3

这是错误:

PSQLException: ERROR: relation "certificate" does not exist

这是你的表:

"Certificate"

数据库正在寻找小写的“证书”,创建了大写的“证书”。

围绕所有标识符使用相同的套管双引号,或者只是使用小写字母来简化事情。

+0

谢谢。它终于奏效了。我所做的是,在映射证书类的hbm.xml文件中,我使用了table =''Certificate''而不是table =“Certificate”。 – Supereme

+0

@Frank我有同样的问题。奇怪的是,它在我的iMac上工作,但是我的MacBook把这个错误抛给我。这怎么可能? – Varundroid