-
1. Re: Can't find a deployment unit in .war file. Persistence.xml issue.
aarnold Dec 19, 2011 6:41 PM (in response to aarnold)continued....
Here is my interface:
package com.missionse.de.coda.data;
import java.util.List;
public interface DataManager {
public String addData(Data data) throws Exception;
public Data findData(String username) throws Exception;
}
Here is my implementation:
package com.missionse.de.coda.data;
import java.util.List;
import java.util.logging.Logger;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.inject.Named;
import javax.persistence.EntityManager;
import javax.transaction.UserTransaction;
@Named("dataManager")
@RequestScoped
public class ManagedBeanDataManager implements DataManager {
@Inject
private transient Logger logger;
@Inject
private EntityManager userDatabase;
@Inject
private UserTransaction utx;
public String addData(Data data) throws Exception {
try {
try {
utx.begin();
userDatabase.persist(data);
logger.info("Added " + data);
} finally {
utx.commit();
}
} catch (Exception e) {
utx.rollback();
throw e;
}
return "userAdded";
}
public Data findData(String name) throws Exception {
try {
try {
utx.begin();
@SuppressWarnings("unchecked")
List<Data> results = userDatabase
.createQuery("select u from User u where u.username=:username and u.password=:password")
.setParameter("name",name).getResultList();
if (results.isEmpty()) {
return null;
} else if (results.size() > 1) {
throw new IllegalStateException("Cannot have more than one user with the same username!");
} else {
return results.get(0);
}
} finally {
utx.commit();
}
} catch (Exception e) {
utx.rollback();
throw e;
}
}
}
When I try to use it like this I get the error....
...
@Inject
DataManager dm;
...
dm.addData(new Data());
-
2. Re: Can't find a deployment unit in .war file. Persistence.xml issue.
rnott Dec 29, 2011 10:26 PM (in response to aarnold)Based on your error message, I'd guess the container is not finding your persistence.xml file. Here are the rules on where the container will search: https://docs.jboss.org/author/display/AS7/JPA+Reference+Guide
Beware that the rule which states WEB-INF/classes will be searched appears to be false, at least in the version I'm using (7.1.0.Beta1b). In my case, I simply add a new JAR to WEB-INF/lib whose only contents are META-INF/persistence.xml and it's suddenly found.