postgresql + jpa + persistence.xml

时间:2014-01-27 16:34:01

标签: postgresql jpa glassfish persistence

我在使用PostgreSQL和JPA时遇到问题。

当我尝试在glassfish上执行我的应用程序时出现此错误:

Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: org.postgresql.util.PSQLException: ERROR: no schema has been selected to create in
Error Code: 0
Call: CREATE TABLE CABINET (ID INTEGER NOT NULL, PRIMARY KEY (ID))
Query: DataModifyQuery(sql="CREATE TABLE CABINET (ID INTEGER NOT NULL, PRIMARY KEY (ID))")
    at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:331)
    at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeDirectNoSelect(DatabaseAccessor.java:895)

那么如何为JPA指定架构,以便能够使用postgresql

注意:我已经添加了postgresql maven依赖:

        <dependency>
        <groupId>postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <version>9.1-901-1.jdbc4</version>
        </dependency>

请帮帮我;谢谢

1 个答案:

答案 0 :(得分:0)

使用postgres中的“search_path”变量指定模式。

要解决您的问题,您有两个解决方案:

将搜索永久添加到您的连接使用的用户:

ALTER user username set search_path=yourschema ;

临时添加jdbc连接中的search_path(我觉得很难看)

   set search_path=yourschema;
相关问题