<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">
<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>
                                <td>
                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="https://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>
                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px; -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
Getting Up & Running with MySQL, DataNucleus & JDO
</h3>
<span style="margin-bottom: 10px;">
created by <a href="https://community.jboss.org/people/elnoobie">El Noobie</a> in <i>Beginner's Corner</i> - <a href="https://community.jboss.org/message/831210#831210">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">
<div class="jive-rendered-content"><p><strong>Warning</strong>:  I am a <span style="text-decoration: underline;">complete</span> newbie with JBoss AS7.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><strong>The Goal & Tools</strong></p><p>My primary goal is to get a complete service up and running locally (at first).  Later I will worry about moving things to OpenShift and playing around with that.  The key tool for all of this is just going to be use of Maven 3.x in order to get things built & deployed locally.  Therefore I'd like to stick with the standard Maven conventions for everything.<strong><br/></strong></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><strong>Where I Am Sucessful</strong></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><ol><li>Able to get the core of everything working with JSF, some REST & SOAP WS, XML/JSON setup, etc.</li><li>Able to get a bunch of OSGi stuff running</li><li>Figured out a bunch of logging issues so I can get Logback with SLF4J running</li><li>No issues deploying/undeploying anything via Maven</li><li>Using Liquibase for the basic database setup which was really easy</li><li>All is good with getting MySQL up, recognized and tested via the web console<ol><li>Added MySQL as a module</li><li>Added DataNucleus as a module</li><li>Defiend 2 data sources:  1 with JPA, 1 without</li></ol></li></ol><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>I was able to follow the basics with the help of a couple web articles:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><ul><li><a class="" href="https://community.jboss.org/docs/DOC-17094?_sscc=t">https://community.jboss.org/wiki/GettingStartedWithJDOOnJbossAS7InSevenSteps?_sscc=t</a></li><li><a class="jive-link-external-small" href="http://hwellmann.blogspot.com/2011/10/jboss-as-7-catching-up-with-java-ee-6.html" rel="nofollow">http://hwellmann.blogspot.com/2011/10/jboss-as-7-catching-up-with-java-ee-6.html</a></li></ul><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><strong>Where I Am Stuck</strong></p><p>So now I am starting to get to the recognition of the data source(s) within JBoss and hoping to move quickly onto the DataNucleus and JDO end of things.  However, I cannot get the data source reference via a context lookup without getting a "<em>Name Not Found</em>" exception.  I really want to get this piece-by-piece to understand the inner workings and therefore I don't want to skip this step before moving on to the setup of <em>persistence.xml</em> and whatnot.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>My data sources are setup like this in <em>standalone.xml</em>:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><pre class="jive-pre"><code class="jive-code jive-xml"><span class="jive-xml-tag"><datasource jta="false" jndi-name="java:/datasources/testMeDS" pool-name="testMeDS-pool" enabled="true" use-java-context="true" use-ccm="true"></span>
...
<span class="jive-xml-tag"></datasource></span>
<span class="jive-xml-tag"><datasource jta="true" jndi-name="java:/datasources/testMeDS-JTA" pool-name="testMeDS-JTA-pool" enabled="true" use-java-context="true" use-ccm="true"></span>
...
<span class="jive-xml-tag"></datasource></span>
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>In my simple, little JAX-RS setup I created a <em>DataSourceService</em> class that looks like this:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><pre class="jive-pre"><code class="jive-code jive-java">@Path (<font color="red">"/dstest"</font>)
<font color="navy"><b>public</b></font> <font color="navy"><b>class</b></font> DataSourceService <font color="navy">{</font>
 
  @Context
  HttpServletRequest request;
 
  @GET
  @Produces(<font color="navy">{</font>MediaType.APPLICATION_XML<font color="navy">}</font>)
  <font color="navy"><b>public</b></font> DSTestDocument getDataSourceTestResults() <font color="navy">{</font>
    <font color="navy"><b>try</b></font> <font color="navy">{</font>
      <font color="darkgreen">// Obtain our environment naming context</font>
      InitialContext initCtx = <font color="navy"><b>new</b></font> InitialContext();
      javax.naming.Context envCtx = (javax.naming.Context) initCtx.lookup(<font color="red">"java:comp/env"</font>);
 
 
      <font color="darkgreen">// Look up our data source</font>
      Object lol = envCtx.lookup(<font color="red">"java:/datasources/testMeDS"</font>);
    <font color="navy">}</font> <font color="navy"><b>catch</b></font> (Exception e) <font color="navy">{</font>
      e.printStackTrace(System.err);
    <font color="navy">}</font>
 
    <font color="darkgreen">// build the document</font>
    <font color="darkgreen">// ...</font>
    <font color="darkgreen">// do some logging</font>
    <font color="darkgreen">// ...</font>
    <font color="navy"><b>return</b></font> theResopnseDocumentObject;
  <font color="navy">}</font>
<font color="navy">}</font>
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>I get the following exception:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><blockquote class="jive-quote"><p>[stderr] (http--0.0.0.0-8080-1) javax.naming.NameNotFoundException: jboss/datasources/testMeDS -- service jboss.naming.context.java.module.ElTesting."webservices-1.0-SNAPSHOT".jboss.datasources.testMeDS</p><p>      at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:97)</p><p>      at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:178)</p><p>      at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:214)</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p></blockquote><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Can someone help me out so I can move on to the next steps?</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>I know that I won't follow <a class="" href="https://community.jboss.org/docs/DOC-17094?_sscc=t">steps 5 and 6</a> from the one article listed above exactly - and I will tackle that mountain when I get to it. I know I'll need to setup the <em>persistence.xml</em> and other things but I am not even going to bother to try until I get this part resolved.  I want to make sure I can connect to the data source and do some things manually before that.  That gives me an opportunity to play with more CDI and various other things utilizing JBoss to get a better understanding of the options opened and internal workings.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Thanks in advance!</p></div>
<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
<p style="margin: 0;">Reply to this message by <a href="https://community.jboss.org/message/831210#831210">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in Beginner's Corner at <a href="https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2075">Community</a></p>
</div></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>