Reputation: 46
I have been trying to figure out how to set up NetBeans (v8.1) and TomEE+ (v1.7.4) to Accessing Data with EJBs.
I have been following along The NetBeans E-commerce Tutorial (Affable Bean app) and I am stuck on Accessing Data with EJBs. Did all the edits as the tutorial states and get an error on run.
AffableBean log:
build-impl.xml:1045: The module has not been deployed.
See the server log for details.
Apache TomEE+ 1.7.4 Log:
Jun 15, 2016 8:26:14 AM org.apache.catalina.core.ApplicationContext log
INFO: Marking servlet ControllerServlet as unavailable
Jun 15, 2016 8:26:14 AM org.apache.catalina.core.StandardContext loadOnStartup
SEVERE: Servlet [ControllerServlet] in web application [/AffableBean] threw load() exception
javax.naming.NameNotFoundException: Name [controller.ControllerServlet/categoryFacade] is not bound in this Context. Unable to find [controller.ControllerServlet].
Apache TomEE+ 1.7.4:
INFO: Configuring PersistenceUnit(name=AffableBeanPU)
Jun 15, 2016 8:26:11 AM org.apache.openejb.config.AutoConfig deploy
WARNING: Found matching datasource: web/connpool but this one is not a JTA datasource
Jun 15, 2016 8:26:11 AM org.apache.openejb.config.AutoConfig deploy
WARNING: Found matching datasource: web/connpool but this one is not a JTA datasource
Jun 15, 2016 8:26:11 AM org.apache.tomee.catalina.TomcatWebAppBuilder startInternal
SEVERE: Unable to deploy collapsed ear in war StandardEngine[Catalina].StandardHost[localhost].StandardContext[/AffableBean]
org.apache.openejb.OpenEJBException: PeristenceUnit AffableBeanPU <jta-data-source> points to a non jta managed Resource. Update Resource "connpool" to "JtaManaged=true", use a different Resource, or delete the <jta-data-source> element and a default will be supplied if possible.
My codes for the persistence.xml is as per tutorial, which is:
<?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="AffableBeanPU" transaction-type="JTA">
<jta-data-source>connpool</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties/>
<property name="eclipselink.logging.level" value="FINEST"/>
</persistence-unit>
</persistence>
So my question is, how can I set up DataSource/EJB in my IDE so it can be run on my server? Irregardless of the Netbeans E-Commerce Tutorial.
EDITed: stuck on Accessing Data with EJBs.
Upvotes: 1
Views: 2031
Reputation: 751
You can define your datasource as a global datasource (for all webapps) defining in the $TOMEE/conf/tomee.xml file or specific to your webapp in the $WEBAPP/WEB-INF/resources.xml file just like this
persistence.xml at webapp's src/META-INF dir
<?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="xyz">
<jta-data-source>xyz</jta-data-source>
<properties>
<property
name="openjpa.jdbc.DBDictionary"
value="org.apache.openjpa.jdbc.sql.OracleDictionary" />
<property
name="openjpa.jdbc.DBDictionary"
value="oracle(maxEmbeddedBlobSize=-1,maxEmbeddedClobSize=-1)" />
<property
name="openjpa.jdbc.SynchronizeMappings"
value="buildSchema(ForeignKeys=true)" />
</properties>
</persistence-unit>
</persistence>
and data source defined at $WEBAPP/WEB-INF/resource.xml
<?xml version="1.0" encoding="UTF-8"?>
<tomee>
<Resource
id="xyz"
type="DataSource">
JdbcDriver oracle.jdbc.OracleDriver
JdbcUrl jdbc:oracle:thin:@localhost:1521:XE
UserName myuser
Password mypass
JtaManaged true
TestOnBorrow false
MaxActive 20
</Resource>
</tomee>
see http://tomee.apache.org/datasource-config.html and http://tomee.apache.org/common-datasource-configurations.html
Upvotes: 1