如何连接 SQL 服务器数据库与 JPA 项目 - Wildfly 服务器 - Java EE
How to connect SQL server database with JPA project - Wildfly server - Java EE
好吧,这个问题可能是重复的。但我很绝望。我正在学习 Java EE,但我什至无法正确设置所有配置。
我的情况:
我有一台 Wildfly 8.1- Jboss 服务器,已准备就绪。
我已经部署了数据源(SQL 服务器)它正在工作。
它有这个 JNDI:
java:/TimeTrackerDS
还有这个driver:sql服务器
Driver Class: com.microsoft.sqlserver.jdbc.SQLServerDriver
这一切似乎都还好。现在我正在部署我的新应用程序。
而且我只是不知道如何使用此人员连接到数据库。
该应用程序也已部署。如何连接这两个东西(数据库和应用程序)
我找到了很多解决方案。将属性写入 persistance.xml 但我无法正常工作。因为我不明白。也许如果你们有人,请在我的特定示例中向我展示。我会明白我做错了什么。
(服务器、应用程序和 sql 服务器都在同一台机器上)(localhost)
我找到了解决方案。
我的实体 java class 有误。所以它没有正确编译。
Propper persistence.xml 给可能需要它的人 :
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="TimeTracker">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:/TimeTrackerDS</jta-data-source>
<class>model.Task</class>
<properties>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.jdbc.batch_size" value="20" />
<property name="hibernate.format_sql" value="true"/>
</properties>
</persistence-unit>
好吧,这个问题可能是重复的。但我很绝望。我正在学习 Java EE,但我什至无法正确设置所有配置。
我的情况: 我有一台 Wildfly 8.1- Jboss 服务器,已准备就绪。 我已经部署了数据源(SQL 服务器)它正在工作。
它有这个 JNDI:
java:/TimeTrackerDS
还有这个driver:sql服务器 Driver Class: com.microsoft.sqlserver.jdbc.SQLServerDriver
这一切似乎都还好。现在我正在部署我的新应用程序。 而且我只是不知道如何使用此人员连接到数据库。 该应用程序也已部署。如何连接这两个东西(数据库和应用程序)
我找到了很多解决方案。将属性写入 persistance.xml 但我无法正常工作。因为我不明白。也许如果你们有人,请在我的特定示例中向我展示。我会明白我做错了什么。
(服务器、应用程序和 sql 服务器都在同一台机器上)(localhost)
我找到了解决方案。 我的实体 java class 有误。所以它没有正确编译。 Propper persistence.xml 给可能需要它的人 :
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="TimeTracker">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:/TimeTrackerDS</jta-data-source>
<class>model.Task</class>
<properties>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.jdbc.batch_size" value="20" />
<property name="hibernate.format_sql" value="true"/>
</properties>
</persistence-unit>