Can';我无法让glassfish连接到mysql model.HelloWorld

Can';我无法让glassfish连接到mysql model.HelloWorld,mysql,jakarta-ee,glassfish,Mysql,Jakarta Ee,Glassfish,我已经在glassfish上安装了连接器,成功的ping使我无法使用servlet和entitymanager将查询发送到mysql服务器。任何帮助都会很好,还有教程。如果您使用的是Glassfish启动的JDBC连接(我想您是这样的,因为您说您成功地ping了数据源),那么您就不想在persistence.xml中定义属性。您只需要通过JNDI名称指定一个数据源 <?xml version="1.0" encoding="UTF-8"?> <persistence versi

我已经在glassfish上安装了连接器,成功的ping使我无法使用servlet和entitymanager将查询发送到mysql服务器。任何帮助都会很好,还有教程。

如果您使用的是Glassfish启动的JDBC连接(我想您是这样的,因为您说您成功地ping了数据源),那么您就不想在persistence.xml中定义属性。您只需要通过JNDI名称指定一个数据源

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
    <persistence-unit name="HelloWorld">
        <class>model.HelloWorld</class>
        <properties>
                <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
                <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/database" />
                <property name="javax.persistence.jdbc.user" value="root" />
                <property name="javax.persistence.jdbc.password" value="password" />
            </properties>
    </persistence-unit>
</persistence>

jdbc/myds
model.HelloWorld

如果您使用的是Glassfish启动的JDBC连接(我想您是这样的,因为您说您成功地ping了数据源),那么您就不想在persistence.xml中定义属性。您只需要通过JNDI名称指定一个数据源

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
    <persistence-unit name="HelloWorld">
        <class>model.HelloWorld</class>
        <properties>
                <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
                <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/database" />
                <property name="javax.persistence.jdbc.user" value="root" />
                <property name="javax.persistence.jdbc.password" value="password" />
            </properties>
    </persistence-unit>
</persistence>

jdbc/myds
model.HelloWorld

执行此操作时,调用类org.glassfish.persistence.jpa.JPADeployer prepare方法时会出现严重:异常准备应用程序时严重:名为[HelloWorld]的持久化单元配置为JTA,但在persistence.xml.java.lang.RuntimeException:persistence单元中只提供了非JTA数据源名称[HelloWorld]已配置为JTA,但persistence.xml中只提供了非JTA数据源名称。这意味着您已将JDBC连接配置为JTA,只需使用
而不是
就可以了。好的,我已经让mysql全部正常工作了,但这不是JPA?那么您知道关于JPA、eclipse和glassfish的好教程吗?Google并没有帮助过这个导师ial相当不错,请记住,因为您使用的是glassfish,所以您可以跳过步骤3.1,因为glassfish已经包含了eclipse链接的副本,如果您包含了glassfish运行库,那么您就已经包含了javax.persistence.*.jar。当我这样做时,调用org.glassfish.persistence.jp类时会出现严重异常a、 JPADeployer prepare method SEVERE:Exception在准备名为[HelloWorld]的应用程序SEVERE:Persistence单元时配置为JTA,但Persistence.xml.java.lang.RuntimeException:Persistence单元[HelloWorld]中只提供了非JTA数据源名称已配置为JTA,但persistence.xml中只提供了非JTA数据源名称。这意味着您已将JDBC连接配置为JTA,只需使用
而不是
就可以了。好的,我已经让mysql全部正常工作了,但这不是JPA?那么您知道关于JPA、eclipse和glassfish的好教程吗?Google并没有帮助过这个导师ial相当不错,请记住,因为您使用的是glassfish,所以可以跳过步骤3.1,因为glassfish已经包含了eclipse链接的副本,如果您已经包含glassfish运行库,那么您已经包含了javax.persistence.*.jar。
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">

  <persistence-unit name="HelloWorld">
    <non-jta-data-source>jdbc/myds</non-jta-data-source>
    <class>model.HelloWorld</class>
    <properties>
    </properties>
  </persistence-unit>

</persistence>