java - Connecting to database with Jetty and JNDI/JPA -


i trying migrate glassfish jetty. trying setup connection pools within jetty access oracle database jpa. when have connection information in persistence.xml, connection works , can access database know database drivers working. apps use jndi lookup data source example below.

when run entitymanager null @ em.createnativequery(querystring, config.class).getresultlist();.

persistence.xml:

<?xml version="1.0" encoding="utf-8"?> <persistence version="1.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_1_0.xsd"> <persistence-unit name="data_source" transaction-type="jta">     <jta-data-source>testdata</jta-data-source>     <exclude-unlisted-classes>false</exclude-unlisted-classes>     <properties>         <property name="eclipselink.cache.shared.default" value="false"/>     </properties> </persistence-unit> 

java:

@managedbean(name = "configdao") @applicationscoped public class configdao implements serializable {      @persistencecontext()     private entitymanager em;     @resource     private usertransaction utx;      public string getgroupemaillist() {         return getconfigbyname(fileutils.email_list).getconfigvalue();     }      public config getconfigbyname(string configname) {         string querystring = "select * config config_name = '" + configname + "'";         list<config> configlist = em.createnativequery(querystring, config.class).getresultlist();          if (configlist != null && !configlist.isempty()) {             return configlist.get(0);         }          return null;     }  } 

in jetty.xml in $jetty_home/etc

<new id="testdata" class="org.eclipse.jetty.plus.jndi.resource">     <arg/>     <arg>testdata</arg>     <arg>         <new class="oracle.jdbc.pool.oracledatasource">             <set name="url">jdbc:oracle:thin:@server:1521:data</set>             <set name="user">user</set>             <set name="password">password</set>             <set name="connectioncachingenabled">true</set>             <set name="connectioncacheproperties">                 <new class="java.util.properties">                     <call name="setproperty">                         <arg type="java.lang.string">inactivitytimeout</arg>                         <arg type="java.lang.string">300</arg>                     </call>                     <call name="setproperty">                         <arg type="java.lang.string">abandonedconnectiontimeout</arg>                         <arg type="java.lang.string">600</arg>                     </call>                     <call name="setproperty">                         <arg type="java.lang.string">timetolivetimeout</arg>                         <arg type="java.lang.string">600</arg>                     </call>                     <call name="setproperty">                         <arg type="java.lang.string">initiallimit</arg>                         <arg type="java.lang.string">10</arg>                     </call>                     <call name="setproperty">                         <arg type="java.lang.string">maxstatementslimit</arg>                         <arg type="java.lang.string">50</arg>                     </call>                     <call name="setproperty">                         <arg type="java.lang.string">minlimit</arg>                         <arg type="java.lang.string">20</arg>                     </call>                 </new>             </set>         </new>     </arg> </new> 


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

Nuget pack csproj using nuspec -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -