how to fetch a value from persistence.xml to build.properties?

How do I fix this datasource problem for JBoss AS 7?

  • I think my bottom-line issue here is JNDI. It automatically adds references to my other resources there for me, and then when it gets to the LoginDS, it dies and seems to say it doesn't have any reference to it. I inserted data source information into my standalone.xml like so: <datasources>     <datasource jta="true" jndi-name="java:jboss/datasources/LoginDS" pool-name="LoginDS" enabled="true" use-java-context="true">         <connection-url>jdbc:mysql://localhost:3306/loginUsers</connection-url>         <driver name="mysql" module="com.mysql">mysql</driver>         <pool>                 <min-pool-size>10</min-pool-size>                 <max-pool-size>100</max-pool-size>         </pool>         <security>                 <user-name>root</user-name>                 <password>bondstone</password>         </security> </datasource> <drivers> <driver name="h2" module="com.h2database.h2"> <xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class> </driver> </drivers> </datasources> My persistence.xml file inside of my EJB3 project looks like this: <?xml version="1.0" encoding="UTF-8"?> <persistence 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_1_0.xsd" version="1.0"> <persistence-unit name="LoginPersistenceUnit">     <provider>org.hibernate.ejb.HibernatePersistence</provider>     <jta-data-source>java:jboss/datasources/LoginDS</jta-data-source>         <properties>             <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>             <property name="hibernate.hbm2ddl.auto" value="update"/>         </properties>     </persistence-unit> </persistence> So then I put a module.xml along with the mysql-connector-java-5.1.29-5.1.29.jar inside of ${jboss_home}/modules/com/mysql/main. <?xml version="1.0" encoding="UTF-8"?> <module xmlns="urn:jboss:module:1.0" name="com.mysql">     <resources>         <resource-root path="mysql-connector-java-5.1.29-bin.jar"/>     </resources>     <dependencies>         <module name="javax.api"/>     </dependencies> </module> All of this, and I still get the following error message. I'm sure it has something to do with getting my datasource called "LoginDS" onto JNDI. 21:42:00,051 INFO [http://org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-5) JBAS010404: Deploying non-JDBC-compliant driver class com.mysql.jdbc.Driver(version 5.1) 21:42:00,140 INFO [http://org.jboss.as] (MSC service thread 1-5)JBAS015951: Admin console listening on http://127.0.0.1:9990 21:42:00,140 ERROR [http://org.jboss.as] (MSC service thread 1-5) JBAS015875: JBoss AS 7.1.1.Final "Brontes" started (with errors) in 2534ms - Started 194 of 287 services (16 services failed or missing dependencies, 76 services are passive or on-demand) 21:42:00,340 INFO [http://org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS015870: Deploy of deployment "stalker.war" was rolled back with failure message {"JBAS014771: Services with missing/unavailable dependencies" => ["jboss.persistenceunit.\"stalker.war#LoginPersistenceUnit\"jboss.naming.context.java.LoginDSMissing[jboss.persistenceunit.\"stalker.war#LoginPersistenceUnit\"jboss.naming.context.java.LoginDS]"]} 21:42:00,359 INFO [http://org.jboss.as.server.deployment] (MSC service thread 1-2) JBAS015877: Stopped deployment stalker.war in 18ms 21:42:00,361 INFO [http://org.jboss.as.controller] (DeploymentScanner-threads - 2) JBAS014774: Service status report JBAS014775: New missing/unsatisfied dependencies: service jboss.naming.context.java.LoginDS (missing) dependents: [service jboss.persistenceunit."stalker.war#LoginPersistenceUnit"] 21:42:00,362 ERROR [http://org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 1) {"JBAS014653: Composite operation failed and was rolled back. Steps that failed:" => {"Operation step-2" => {"JBAS014771: Services with missing/unavailable dependencies" => ["jboss.persistenceunit.\"stalker.war#LoginPersistenceU nit\"jboss.naming.context.java.LoginDSMissing[jboss.persistenceunit.\"stalker.wa r#LoginPersistenceUnit\"jboss.naming.context.java.LoginDS]"]}}}

  • Answer:

    Not an expert but I think that the jndi name of the datasource should be "jboss/datasources/LoginDS" in standalone.xml and in persistence.xml:     <jta-data-source>java:/jboss/datasources/LoginDS</jta-data-source> (add the / before "jboss") My answer is based on: https://docs.jboss.org/ejb3/docs/reference/build/reference/en/html/entityconfig.html jta-data-source, non-jta-data-source This is the JNDI name of where the javax.sql.DataSource is located. [...] If you're running inside JBoss, put the jndi name of the datasource you defined in the earlier section. Remember to put the "java:/" in front of the jndi name you selected for your datasource.

George Popescu at Quora Visit the source

Was this solution helpful to you?

Other answers

Your JNDI name looks fine to me : jndi-name="java:jboss/datasources/LoginDS" But your datasource has reference to mysql driver : <driver name="mysql" module="com.mysql">mysql</driver> But the drivers section does not contain mysql driver <drivers> <driver name="h2" module="com.h2database.h2"> : <xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class> </driver> </drivers> Also So then I put a module.xml along with the mysql-connector-java-5.1.29-5.1.29.jar inside of ${jboss_home}/modules/com/mysql/main. <?xml version="1.0" encoding="UTF-8"?> <module xmlns="urn:jboss:module:1.0" name="com.mysql">     <resources>         <resource-root path="mysql-connector-java-5.1.29-bin.jar"/> Is there a typo in the JAR file name?

Murat Kilic

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.