将表从postgresql数据库绑定到Netbeans GUI表时出错

时间:2013-10-04 02:56:43

标签: java sql jpa netbeans jdbc

将一个表从postgresql绑定到Netbeans中设计表中的表后,我收到以下错误:

run:
[EL Info]: 2013-10-04 10:51:36.097--ServerSession(865393238)--EclipseLink, version: Eclipse Persistence Services - 2.5.0.v20130507-3faac2b
[EL Info]: connection: 2013-10-04 10:51:36.701--ServerSession(865393238)--file:/D:/Doodle Notes Database/Doodle Notes Projects/build/classes/_DoodleNotesPU login successful
[EL Warning]: 2013-10-04 10:51:37.119--UnitOfWork(1785038318)--Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: org.postgresql.util.PSQLException: ERROR: cross-database references are not implemented: "doodlenotes.public.projects"
  Position: 139
Error Code: 0
Exception in thread "main" javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: org.postgresql.util.PSQLException: ERROR: cross-database references are not implemented: "doodlenotes.public.projects"
Call: SELECT project_code, member_incharge, project_category, project_client, project_genre, project_name, project_package, project_status FROM DoodleNotes.public.projects
  Position: 139
Error Code: 0
Query: ReadAllQuery(referenceClass=Projects sql="SELECT project_code, member_incharge, project_category, project_client, project_genre, project_name, project_package, project_status FROM DoodleNotes.public.projects")
Call: SELECT project_code, member_incharge, project_category, project_client, project_genre, project_name, project_package, project_status FROM DoodleNotes.public.projects
Query: ReadAllQuery(referenceClass=Projects sql="SELECT project_code, member_incharge, project_category, project_client, project_genre, project_name, project_package, project_status FROM DoodleNotes.public.projects")
    at org.eclipse.persistence.internal.jpa.QueryImpl.getDetailedException(QueryImpl.java:377)
    at org.eclipse.persistence.internal.jpa.QueryImpl.executeReadQuery(QueryImpl.java:260)
    at org.eclipse.persistence.internal.jpa.QueryImpl.getResultList(QueryImpl.java:468)
    at Doodle.doodleNotes_Business.initComponents(doodleNotes_Business.java:26)
    at Doodle.doodleNotes_Business.<init>(doodleNotes_Business.java:11)
    at Doodle.doodleNotes_Business.main(doodleNotes_Business.java:311)
Caused by: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: org.postgresql.util.PSQLException: ERROR: cross-database references are not implemented: "doodlenotes.public.projects"
  Position: 139
Error Code: 0
Call: SELECT project_code, member_incharge, project_category, project_client, project_genre, project_name, project_package, project_status FROM DoodleNotes.public.projects
Query: ReadAllQuery(referenceClass=Projects sql="SELECT project_code, member_incharge, project_category, project_client, project_genre, project_name, project_package, project_status FROM DoodleNotes.public.projects")
    at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:340)
    at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:679)
    at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:558)
    at org.eclipse.persistence.internal.sessions.AbstractSession.basicExecuteCall(AbstractSession.java:1995)
    at org.eclipse.persistence.sessions.server.ServerSession.executeCall(ServerSession.java:570)
    at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:242)
    at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:228)
    at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeSelectCall(DatasourceCallQueryMechanism.java:299)
    at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.selectAllRows(DatasourceCallQueryMechanism.java:694)
    at org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.selectAllRowsFromTable(ExpressionQueryMechanism.java:2714)
    at org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.selectAllRows(ExpressionQueryMechanism.java:2667)
    at org.eclipse.persistence.queries.ReadAllQuery.executeObjectLevelReadQuery(ReadAllQuery.java:477)
    at org.eclipse.persistence.queries.ObjectLevelReadQuery.executeDatabaseQuery(ObjectLevelReadQuery.java:1155)
    at org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:899)
    at org.eclipse.persistence.queries.ObjectLevelReadQuery.execute(ObjectLevelReadQuery.java:1114)
    at org.eclipse.persistence.queries.ReadAllQuery.execute(ReadAllQuery.java:402)
    at org.eclipse.persistence.queries.ObjectLevelReadQuery.executeInUnitOfWork(ObjectLevelReadQuery.java:1202)
    at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2894)
    at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1797)
    at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1779)
    at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1744)
    at org.eclipse.persistence.internal.jpa.QueryImpl.executeReadQuery(QueryImpl.java:258)
    ... 4 more
Caused by: org.postgresql.util.PSQLException: ERROR: cross-database references are not implemented: "doodlenotes.public.projects"
  Position: 139
    at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2157)
    at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1886)
    at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
    at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:555)
    at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:417)
    at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:302)
    at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeSelect(DatabaseAccessor.java:1002)
    at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:641)
    ... 24 more
Java Result: 1
BUILD SUCCESSFUL (total time: 5 seconds)

我该怎么做才能解决错误?

1 个答案:

答案 0 :(得分:1)

我对IntelliJ IDEA和Hybernate也有同样的错误,

引起:org.postgresql.util.PSQLException:错误:未实现跨数据库引用:&#34; mydb.public.media_types&#34;

与你的相同,

引起:org.postgresql.util.PSQLException:错误:未实现跨数据库引用:&#34; doodlenotes.public.projects&#34;

我已经找到了解决方案,但是我想也是如此,我的解决方案就是从我的hbm.xml文件中删除名为catalog的属性。

之前:

`<class name="pkg.MediaTypesEntity" table="media_types" schema="public"` catalog="MyDB">

后:

<!-- catalog="MyDB" --removed -->
<class name="pkg.MediaTypesEntity" table="media_types" schema="public">
<!-- catalog="MyDB" --removed -->
    <id name="id">
        <column name="id" sql-type="serial" not-null="true"/>
    </id>
    <property name="txt">
        <column name="txt" sql-type="text" length="2147483647"/>
    </property>
</class>

我认为原因是数据库名称是在hibernate.cfg.xml中全局配置的。

<hibernate-configuration>
    <session-factory>

        <property name="connection.url">jdbc:postgresql://localhost:5432/MyDB</property>

        <property name="connection.driver_class">org.postgresql.Driver</property>
        <mapping resource="pkg/MediaTypesEntity.hbm.xml"/>
        <mapping class="pkg.MediaTypesEntity"/>
    </session-factory>
</hibernate-configuration>

而且,真正的原因,MyDB名称无法轻易从JDBC连接字符串中删除。只允许几个不同的hibernate-DBName.cfg.xml。 有关详细信息,请参阅这些链接:

hibernate-using-two-different-database-schemas-in-the-same-application

how-to-connect-to-multiple-databases-in-hibernate