【发布时间】:2018-06-08 12:10:48
【问题描述】:
我正在尝试让 Java8EE 应用程序在 Wildfly10 和 Postgres 9.6.6 上运行。
我总是遇到找不到关系的错误。
我的 Postgres 在本地主机上运行,默认端口。我正在连接用户 postgres 和正确的密码。数据库 (hbnac) 有一个同名的架构。
Wildfly 配置为使用数据库,“测试连接”正在确认连接成功。 使用 pgAdmin 4,我还可以浏览数据库、查看架构以及表 group_member。
Jboss 中的配置如下:
<datasource jta="false" jndi-name="java:jboss/datasources/hbnac" pool-name="hbnac" enabled="true" use-ccm="false">
<connection-url>jdbc:postgresql://localhost:5432/hbnac</connection-url>
<driver-class>org.postgresql.Driver</driver-class>
<driver>postgres</driver>
<pool>
<min-pool-size>1</min-pool-size>
<initial-pool-size>1</initial-pool-size>
<max-pool-size>10</max-pool-size>
<flush-strategy>Gracefully</flush-strategy>
</pool>
<security>
<user-name>postgres</user-name>
<password>password</password>
</security>
<validation>
<valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLValidConnectionChecker"/>
<background-validation>true</background-validation>
<exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLExceptionSorter"/>
</validation>
</datasource>
但是,我的应用程序无法从同一个表中选择记录,导致以下错误:
Caused by: org.postgresql.util.PSQLException: ERROR: relation "group_member" does not exist
我的 persistence.xml 的配置正在对 Wildfly 中定义的连接进行 jndi 查找:
<persistence-unit name="hbnac">
<jta-data-source>java:jboss/datasources/hbnac</jta-data-source>
<class>hbnac.birthday.domain.groupmember.GroupMember</class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQL94Dialect" />
<!--property name="hibernate.hbm2ddl.auto" value="validate"/-->
<!--property name="hibernate.default_schema" value="hbnac"/-->
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="true" />
</properties>
</persistence-unit>
显然,jta-data-source 与 Wildfly 中的工作数据源相匹配。正如你所看到的,我已经对验证(在启动时由于相同的原因失败)和模式名称进行了一些试验,这也没有任何区别。
实体本身被注释:
@Entity
@Table(name = "group_member")
public class GroupMember extends AbstractEntity {
public final static String FACEBOOK_NAME_FIELD = "facebookName";
public final static String BIRTHDAY_FIELD = "birthday";
@Id
@GeneratedValue(strategy= GenerationType.IDENTITY)
private long id;
它为所有可用字段提供 getter、setter、hashcode 和 equals 方法。
如果我将 hibernate 生成的查询复制到 pgadmin 中,它也可以正常工作...
还有什么想法吗?
【问题讨论】:
标签: postgresql hibernate wildfly