How to solve Java EE EJB Glassfish error javax.naming.NamingException: Invocation exception: Got null ComponentInvocation? - jpa

I have a problem with creating a simple databse with EJB. I created a Web Project in Netbeans with Maven. I am using Glassfish 5 however the problem also occurs with glassfish 4.
Here are my classes.
Ui_model.java:
#Named("model")
#Stateless
public class Ui_model implements Serializable{
#Inject
PizzaRepository pizzas;
public Ui_model() {
}
#PostConstruct
public void init(){
Pizza one = new Pizza(1, "Pizza Margaritta", 4.5);
Pizza two = new Pizza(2, "Pizza Napoli", 5);
Pizza three = new Pizza(3, "Pizza Calzone", 6);
pizzas.createDB(one);
pizzas.createDB(two);
pizzas.createDB(three);
}
}
PizzaRepository.java:
#Named
#ApplicationScoped
public class PizzaRepository implements Serializable{
#PersistenceContext(unitName="Unit")
protected EntityManager em;
public void createDB(Pizza pizza){
try{
em.persist(pizza);
}catch(RollbackException e){
System.out.println(e.getMessage());
}
}
}
Pizza.java:
#Entity
public class Pizza implements Serializable{
#Id
int number;
String name;
double price;
public Pizza(int number, String name, double price) {
this.number = number;
this.name = name;
this.price = price;
}
public Pizza(){
}
}
This is my persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.1"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="Unit" transaction-type="JTA">
<jta-data-source>java:app/jdbc/testdb</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<!-- database connection -->
<property name="javax.persistence.schema-generation.database.action" value="drop-and-create" />
</properties>
</persistence-unit>
</persistence>
This is my glassfish-resources.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resources PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Resource Definitions//EN" "http://glassfish.org/dtds/glassfish-resources_1_5.dtd">
<resources>
<jdbc-connection-pool allow-non-component-callers="false"
associate-with-thread="false"
connection-creation-retry-attempts="0"
connection-creation-retry-interval-in-seconds="10"
connection-leak-reclaim="false"
connection-leak-timeout-in-seconds="0"
connection-validation-method="auto-commit"
datasource-classname="org.apache.derby.jdbc.ClientDataSource"
fail-all-connections="false" idle-timeout-in-seconds="300"
is-connection-validation-required="false"
is-isolation-level-guaranteed="true"
lazy-connection-association="false"
lazy-connection-enlistment="false"
match-connections="false"
max-connection-usage-count="0"
max-pool-size="32"
max-wait-time-in-millis="60000"
name="derby_net_testdb_usernamePool"
non-transactional-connections="false"
pool-resize-quantity="2"
res-type="javax.sql.DataSource"
statement-timeout-in-seconds="-1"
steady-pool-size="8"
validate-atmost-once-period-in-seconds="0"
wrap-jdbc-objects="false">
<property name="serverName" value="localhost"/>
<property name="portNumber" value="1527"/>
<property name="databaseName" value="testdb"/>
<property name="User" value="username"/>
<property name="Password" value="123456"/>
<property name="URL" value="jdbc:derby://localhost:1527/testdb"/>
<property name="driverClass" value="org.apache.derby.jdbc.ClientDriver"/>
</jdbc-connection-pool>
<jdbc-resource enabled="true"
jndi-name="java:app/jdbc/testdb"
object-type="user"
pool-name="java:app/derby_net_testdb_usernamePool"/>
</resources>
My project structure:
When I run this I get the following error:
The strange thing is that this still creates an empty table named Pizza in the testdb but with no entries. So it doesn't mean that the program is not finding the DB itself. I really don't know what to make of that error. The project was much bigger originally but I broke it down to get to the base problem and it doesn't get much easier than this. Still it doesn't work. I would appreciate any advice on how to fix it.
Edit:
asadmin list-jndi-entries prompts:
java:global: com.sun.enterprise.naming.impl.TransientContext
UserTransaction: com.sun.enterprise.transaction.startup.TransactionLifecycleService$2
__internal_java_app_for_app_client__testdb__java:app: com.sun.enterprise.naming.impl.TransientContext
concurrent: com.sun.enterprise.naming.impl.TransientContext
com.sun.enterprise.container.common.spi.util.InjectionManager: com.sun.enterprise.container.common.impl.util.InjectionManagerImpl
jms: com.sun.enterprise.naming.impl.TransientContext
ejb: com.sun.enterprise.naming.impl.TransientContext
jdbc: com.sun.enterprise.naming.impl.TransientContext
Command list-jndi-entries executed successfully.
asadmin list-jndi-entries --context jdbc prompts:
__default: org.glassfish.resourcebase.resources.api.ResourceProxy
__TimerPool: org.glassfish.resourcebase.resources.api.ResourceProxy
sample: org.glassfish.resourcebase.resources.api.ResourceProxy
Command list-jndi-entries executed successfully.

I think the problem is that the jdbc-resource pool-name and the jdbc-connection-pool name do not match. The first has java:app/ prefixed. Try to remove that.
See here for a minimal example: https://github.com/payara/Payara-Examples/blob/master/payara-micro/database-ping/src/main/webapp/WEB-INF/glassfish-resources.xml

I was able to solve the problem by putting the glassfish.xml into an setup file in src. I also got help from a friend who gave me his files.
glassfish.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resources PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Resource Definitions//EN" "http://glassfish.org/dtds/glassfish-resources_1_5.dtd">
<resources>
<jdbc-connection-pool allow-non-component-callers="false" associate-with-thread="false" connection-creation-retry-attempts="0" connection-creation-retry-interval-in-seconds="10" connection-leak-reclaim="false" connection-leak-timeout-in-seconds="0" connection-validation-method="auto-commit" datasource-classname="org.apache.derby.jdbc.ClientDataSource" fail-all-connections="false" idle-timeout-in-seconds="300" is-connection-validation-required="false" is-isolation-level-guaranteed="true" lazy-connection-association="false" lazy-connection-enlistment="false" match-connections="false" max-connection-usage-count="0" max-pool-size="32" max-wait-time-in-millis="60000" name="derby_net_testdb_pizzaPool" non-transactional-connections="false" pool-resize-quantity="2" res-type="javax.sql.DataSource" statement-timeout-in-seconds="-1" steady-pool-size="8" validate-atmost-once-period-in-seconds="0" wrap-jdbc-objects="false">
<property name="serverName" value="localhost"/>
<property name="portNumber" value="1527"/>
<property name="databaseName" value="testdb"/>
<property name="User" value="username"/>
<property name="Password" value="123456"/>
<property name="connectionAttributes" value=";create=true" />
<property name="URL" value="jdbc:derby://localhost:1527/testdb;create=true"/>
<property name="driverClass" value="org.apache.derby.jdbc.ClientDriver"/>
</jdbc-connection-pool>
<jdbc-resource enabled="true" jndi-name="jdbc/testdb" object-type="user" pool-name="derby_net_testdb_pizzaPool"/>
</resources>
persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="Unit" transaction-type="JTA">
<jta-data-source>jdbc/testdb</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<!--<property name="javax.persistence.jdbc.url" value="jdbc:derby://localhost:1527/ModulDB"/>
<property name="javax.persistence.jdbc.user" value="pizza"/>
<property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.ClientDriver"/>
<property name="javax.persistence.jdbc.password" value="123456"/>-->
<property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/>
</properties>
</persistence-unit>
</persistence>
However I then got an error Could not create stateless EJB because of the persist call. That I could resolve by not calling createDB() in the PostConstruct init(). I don't know why but it just didn't work with post construct. Now everything works properly so far. Thank you all very much.

Related

openJPA configured not persisting

I have a very minimal test that properly configures openJPA, JTA, database connectivity, enhancement and emits no exceptions however it does not persist with the simple code below. What more do I need to show or what is necessary beyond the simple statements to actually write records to the db?
public class Manipulation00 {
public Manipulation00(){}
public void startUp(ServletContext sc){
EntityManagerFactory emf =
(EntityManagerFactory)sc.getAttribute("emf");
EntityManager em = emf.createEntityManager();
Exemptions00 exempt00 = new Exemptions00();
exempt00.setUpc("722430001166");
exempt00.setDesc("KOMBUCHA,OG2,SEASONAL");
em.persist(exempt00);
}
}
the persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="ediExemptions" transaction-type="JTA">
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<jta-data-source>java:app/ediExemptions</jta-data-source>
<class>tng.db02.Exemptions00</class>
<properties>
<property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/>
<property name="openjpa.Log" value="DefaultLevel=WARN, Tool=INFO"/>
<property name="openjpa.jdbc.SynchronizeMappings"
value="buildSchema"/>
<property name="openjpa.ConnectionURL"
value="jdbc:derby://localhost:1527/ediExemptions"/>
<property name="openjpa.ConnectionDriverName"
value="org.apache.derby.jdbc.ClientDriver"/>
<property name="openjpa.ConnectionUserName"
value="root"/>
<property name="openjpa.ConnectionPassword"
value="admin"/>
</properties>
</persistence-unit>
</persistence>
I'd guess that your transaction isn't being committed.

JBPM6 project connect to mysql failed

i installed jbpm6 and mysql,i used PoolingDataSource to start BD,but always unable to find'squenses' tables,i kown it's hibernate'dialect problem,and i want to use persistence.xml to start .
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<persistence
version="2.0"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_2_0.xsd"
xmlns:orm="http://java.sun.com/xml/ns/persistence/orm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="com.test.test" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>jdbc/jbpm-ds</jta-data-source>
<mapping-file>META-INF/JBPMorm.xml</mapping-file>
<mapping-file>META-INF/Taskorm.xml</mapping-file>
<class>org.jbpm.persistence.processinstance.ProcessInstanceInfo</class>
<class>org.drools.persistence.info.SessionInfo</class>
<class>org.drools.persistence.info.WorkItemInfo</class>
<class>org.jbpm.process.audit.ProcessInstanceLog</class>
<class>org.jbpm.process.audit.NodeInstanceLog</class>
<class>org.jbpm.process.audit.VariableInstanceLog</class>
<class>org.jbpm.persistence.correlation.CorrelationKeyInfo</class>
<class>org.jbpm.persistence.correlation.CorrelationPropertyInfo</class>
<!-- manager -->
<class>org.jbpm.runtime.manager.impl.jpa.ContextMappingInfo</class>
<class>org.jbpm.services.task.impl.model.AttachmentImpl</class>
<class>org.jbpm.services.task.impl.model.ContentImpl</class>
<class>org.jbpm.services.task.impl.model.BooleanExpressionImpl</class>
<class>org.jbpm.services.task.impl.model.CommentImpl</class>
<class>org.jbpm.services.task.impl.model.DeadlineImpl</class>
<class>org.jbpm.services.task.impl.model.CommentImpl</class>
<class>org.jbpm.services.task.impl.model.DeadlineImpl</class>
<class>org.jbpm.services.task.impl.model.DelegationImpl</class>
<class>org.jbpm.services.task.impl.model.EscalationImpl</class>
<class>org.jbpm.services.task.impl.model.GroupImpl</class>
<class>org.jbpm.services.task.impl.model.I18NTextImpl</class>
<class>org.jbpm.services.task.impl.model.NotificationImpl</class>
<class>org.jbpm.services.task.impl.model.EmailNotificationImpl</class>
<class>org.jbpm.services.task.impl.model.EmailNotificationHeaderImpl</class>
<class>org.jbpm.services.task.impl.model.PeopleAssignmentsImpl</class>
<class>org.jbpm.services.task.impl.model.ReassignmentImpl</class>
<class>org.jbpm.services.task.impl.model.TaskImpl</class>
<class>org.jbpm.services.task.impl.model.TaskDataImpl</class>
<class>org.jbpm.services.task.impl.model.UserImpl</class>
<!--BAM for task service -->
<class>org.jbpm.services.task.impl.model.BAMTaskSummaryImpl</class>
<properties>
<property name="hibernate.max_fetch_depth" value="3"/>
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
<!-- BZ 841786: AS7/EAP 6/Hib 4 uses new (sequence) generators which seem to cause problems -->
<property name="hibernate.id.new_generator_mappings" value="false" />
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
<property name="hibernate.connection.username" value="jbpm"/>
<property name="hibernate.connection.password" value="jbpm"/>
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/jbpm"/>
<property name="hibernate.cglib.use_reflection_optimizer" value="true"/>
<property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.BitronixJtaPlatform" />
</properties>
</persistence-unit>
</persistence>
but the error is that:
​Exception in thread "main" javax.persistence.PersistenceException: [PersistenceUnit: org.jbpm.persistence.jpa] Unable to build EntityManagerFactory
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:925)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:900)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:59)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:63)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47)
at test.test.createRuntimeManager(test.java:71)
at test.test.main(test.java:37)
Caused by: org.hibernate.service.jndi.JndiException: Unable to lookup JNDI name [jdbc/jbpm-ds]
at org.hibernate.service.jndi.internal.JndiServiceImpl.locate(JndiServiceImpl.java:68)
at org.hibernate.service.jdbc.connections.internal.DatasourceConnectionProviderImpl.configure(DatasourceConnectionProviderImpl.java:116)
at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:85)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:184)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:156)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.buildJdbcConnectionAccess(JdbcServicesImpl.java:223)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:89)
at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:85)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:184)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:156)
at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1827)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1785)
at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:96)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:915)
... 6 more
Caused by: javax.naming.NameNotFoundException: unable to find a bound object at name 'jdbc/jbpm-ds'
at bitronix.tm.jndi.BitronixContext.lookup(BitronixContext.java:83)
at bitronix.tm.jndi.BitronixContext.lookup(BitronixContext.java:67)
at javax.naming.InitialContext.lookup(Unknown Source)
at org.hibernate.service.jndi.internal.JndiServiceImpl.locate(JndiServiceImpl.java:65)
... 19 more
i don't kown what i lose

RESTful web-service not found when I deploy app in eclipse

So, I have a Spring Maven web-app with a handful of RESTful web-services. For testing, this project is in Spring (4.1.4.RELEASE). I am using the latest STS (Spring-Eclipse) tool, and I am using Tomcat 8 for the server.
My UserController is designed as follows:
#Controller
#RequestMapping("/users")
public class UserController {
private final static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
#Autowired
private IUserService service;
#RequestMapping(value = "", method = RequestMethod.GET, headers = "Accept=application/json")
public #ResponseBody
ArrayList<UserEntity> getUserList()
{
System.out.println("UserController: getUserList: START");
ArrayList<UserEntity> userEntityList = (ArrayList) service.getAllUsers();
return userEntityList;
}
#RequestMapping(value = "/", method = RequestMethod.GET, headers = "Accept=application/json")
public #ResponseBody
ArrayList<UserEntity> getAllUsers()
{
System.out.println("UserController: getAllUsers: START");
ArrayList<UserEntity> userEntityList = (ArrayList) service.getAllUsers();
return userEntityList;
}
I have a test which runs when I build the app with maven, and this works great:
#RunWith(SpringJUnit4ClassRunner.class)
#WebAppConfiguration
#ContextConfiguration(locations =
{ "classpath:/spring/angular-context.xml", "file:src/main/webapp/WEB-INF/springmvc-servlet.xml" })
#Transactional
public class BaseControllerTests extends TestCase {
#Test
public void testMockGetUserList1() throws Exception
{
MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.get("/users/");
this.mockMvc.perform(requestBuilder).andDo(print()).andExpect(status().isOk());
}
#Test
public void testMockGetUserList2() throws Exception
{
MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.get("/users");
this.mockMvc.perform(requestBuilder).andDo(print()).andExpect(status().isOk());
}
}
The web-xml file looks like:
<web-app>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:/spring/angular-context.xml</param-value>
</context-param>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath:/logging/log4j-config.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Servlets -->
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>jUnitHostImpl</servlet-name>
<servlet-class>com.google.gwt.junit.server.JUnitHostImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>jUnitHostImpl</servlet-name>
<url-pattern>/SoccerApp/junithost/*</url-pattern>
</servlet-mapping>
<!-- Default page to serve -->
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
And the angular-context.xml file looks like:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:lang="http://www.springframework.org/schema/lang"
xmlns:util="http://www.springframework.org/schema/util" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-3.2.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.2.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">
<context:annotation-config />
<context:component-scan base-package="com.tomholmes.angularjs.phonebook" />
<bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://localhost:3306/phonebook</value>
</property>
<property name="username">
<value>myusername</value>
</property>
<property name="password">
<value>mypassword</value>
</property>
</bean>
<!-- JNDI DataSource for Java EE environments -->
<!-- <jee:jndi-lookup id="dataSource" jndi-name="java:comp/env/jdbc/MyDatabase"/> -->
<!-- Hibernate SessionFactory -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="packagesToScan" value="com.tomholmes.angularjs.phonebook.domain" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.cglib.use_reflection_optimizer">true</prop>
</props>
</property>
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host" value="mail.tomholmes.net" />
<property name="port" value="587" />
<property name="username" value="myusername" />
<property name="password" value="mypassword" />
<property name="javaMailProperties">
<props>
<prop key="mail.smtp.auth">true</prop>
<prop key="mail.smtp.starttls.enable">true</prop>
</props>
</property>
</bean>
<!--
<bean id="sendMailService" class="com.tomholmes.angularjs.phonebook.shared.util.SendEmailService">
<property name="mailSender" ref="mailSender" />
</bean>
-->
<bean id = "transactionManager" class = "org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name = "sessionFactory" ref = "sessionFactory" />
</bean>
<!-- enable the configuration of transactional behavior based on annotations -->
<tx:annotation-driven transaction-manager="transactionManager"/>
</beans>
So, this project compiles under maven just fine. Under eclipse (STS) with the Tomcat 8 engine, it runs fine, and I can go to my app:
http://localhost:8080/angularjs-phone-book/
and I can see the index.html just fine, so I know the app is out there.
If I go to:
http://localhost:8080/angularjs-phone-book/users
http://localhost:8080/angularjs-phone-book/users/
http://localhost:8080/angularjs-phone-book/rest/users
http://localhost:8080/angularjs-phone-book/rest/users/
Nothing works, and I get a 404 error that this web-service is not found.
But like I said, I know the test works, but I can't see what the exact URL has to be to get there.
I tried deploying the WAR on Tomcat 8 directly, but this web-app won't even start there, supposedly because of logging problems.
If I can provide any more information, please let me know. Any help in finding this would be great. Ultimately I want to have an AngularJS UI on the front-end tied to web-services, and I have to get the web-services working first.
Thanks!
You probably miss the Spring config reference from your web.xml. The unit test runs because you give the reference to the XML directly there, but not in web.xml, so Spring will not scan your controller for annotations.
Use an <init-param> inside <servlet>!
And the correct URL will be the last one, that is, with .../rest/users/, and .../rest/users is also allowed by the help of the browser, I guess.

Tomcat + Eclipse Link + Vaadin, NoClassDefFoundError javax/persistence/Persistence

I'm using Vaadin and Eclipse Link for my web application based on MySQL database.
I have a following class to manage db operations:
public class DatabaseManager {
private static final String PERSISTENCE_UNIT_NAME = "students";
private static EntityManagerFactory factory;
private static EntityManager em;
public DatabaseManager() {
factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
em = factory.createEntityManager();
}
public void addEntry(Student student) {
em.getTransaction().begin();
em.persist(student);
em.getTransaction().commit();
}
}
and the following persistence.xml file:
<?xml version="1.0" encoding="UTF-8" ?>
<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" version="2.0" xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="students" transaction-type="RESOURCE_LOCAL">
<class>com.example.simplegradebook.Student</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver" />
<property name="javax.persistence.jdbc.url" value="jdbc:derby:C:\\Users\\Ja\\workspace\\SimpleDB;create=true" />
<property name="javax.persistence.jdbc.user" value="test" />
<property name="javax.persistence.jdbc.password" value="test" />
<!-- EclipseLink should create the database schema automatically -->
<!-- <property name="eclipselink.ddl-generation" value="drop-and-create-tables" /> -->
<property name="eclipselink.ddl-generation.output-mode" value="both" />
</properties>
I also have a DBTest class in which I test DatabaseManager in console and everything seems to be okay. But when I put for example:
DatabaseManager dbm = new DatabaseManager();
dbm.addEntry(new Student(/*some stuff here*/));
in my VaadinUI class, I get errors like that:
com.vaadin.server.ServiceException: java.lang.NoClassDefFoundError: javax/persistence/Persistence
com.vaadin.server.VaadinService.handleExceptionDuringRequest(VaadinService.java:1463)
com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1417)
com.vaadin.server.VaadinServlet.service(VaadinServlet.java:237)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
java.lang.NoClassDefFoundError: javax/persistence/Persistence
com.example.simplegradebook.DatabaseManager.<init>(DatabaseManager.java:19)
com.example.simplegradebook.SimplegradebookUI.init(SimplegradebookUI.java:44)
com.vaadin.ui.UI.doInit(UI.java:641)
com.vaadin.server.communication.UIInitHandler.getBrowserDetailsUI(UIInitHandler.java:222)
com.vaadin.server.communication.UIInitHandler.synchronizedHandleRequest(UIInitHandler.java:74)
com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:41)
com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1405)
com.vaadin.server.VaadinServlet.service(VaadinServlet.java:237)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
I have these libraries included in my project:
javax.persistence_2.1.0.v201304241213.jar
javax.persistence.source_2.1.0.v201304241213.jar
Any ideas what may cause the problem?

EntityTransaction rollback

I use EJB to insert/update data to the database and I have this problem. My commit only works with updating(merge), but doesn't rollback inserts(persist). Even more, my inserts(persist) happen before transaction commit.
my persistence unit:
<persistence-unit name="bpmBeans_RESOURCE_LOCAL" transaction-type="RESOURCE_LOCAL">
<jta-data-source>java:jboss/datasources/java_orgstruct</jta-data-source>
<properties>
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.connection.useUnicode" value="true"/>
<property name="hibernate.connection.characterEncoding" value="UTF-8"/>
<property name="hibernate.connection.CharSet" value="utf8"/>
<property name="hibernate.cache.use_second_level_cache" value="true" />
<property name="hibernate.cache.use_query_cache" value="true" />
<property name="hibernate.transaction.factory_class" value="org.hibernate.transaction.JTATransactionFactory" />
<property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
<property name="hibernate.connection.autocommit" value="false"/>
</properties>
</persistence-unit>
how i inject entity manager factory
#PersistenceUnit(unitName="bpmBeans_RESOURCE_LOCAL")
public EntityManagerFactory emf;
what happens with the code
EntityManager em = emf.createEntityManager();
EntityTransaction ets = em.getTransaction();
ets.begin();
Process newObj = new Process();
em.persist(newObj); //data gets inserted at this moment, not at commit
...
...
if(allgood){
ets.commit();// now update(merge, setters on managed entities) would happend.
} else {
ets.rollback(); // this would rollback the updates, but not the insert
}
Any ideas what to try? I guess I'm just understanding some JPA concepts badly.
EDIT:
Datasource code. Datasource is described in WEB-INF/mysql-ds.xml file . Driver .jar is in JBoss deployments.
<?xml version="1.0" encoding="UTF-8"?>
<datasources xmlns="http://www.jboss.org/ironjacamar/schema">
<datasource jndi-name="java:jboss/datasources/java_orgstruct" pool-name="MySQLPool">
<connection-url>jdbc:mysql://192.168.150.141/organisation_model</connection-url>
<connection-property name="zeroDateTimeBehavior">convertToNull</connection-property>
<connection-property name="characterEncoding">utf8</connection-property>
<driver>mysql-connector-java-5.1.28-bin.jar</driver>
<security>
<user-name></user-name>
<password></password>
</security>
</datasource>
</datasources>