当我尝试执行jpql查询时,我收到此异常。 我的EJB接口和实现它的DAO是:
// Bitmask of 'width' bits shifted 'shift' bits to the left
// For instance, mask<16,8> := 0x00FFFF00
template <uint8_t width, uint8_t shift=0>
struct mask {
static const uintmax_t value = (width >= (sizeof(uintmax_t)<<3)) ?
(~0 << shift) : (((uintmax_t(1)<<width)-1) << shift) ;
mask()=delete;
};
// A bitmask for a type, for instance, 0xFF for uint8_t
template <class T>
struct typeMask {
static const uintmax_t value = mask<sizeof(T)<<3>::value;
typeMask()=delete;
};
和
@Local
public interface DeckInter {
String findDeck(String name);
}
我正在进行&#34;测试&#34;返回,因为第一个抛出异常。 persistence.xml是:
@Stateless
public class DeckDAO implements DeckInter {
@PersistenceContext(unitName = "NewPersistenceUnit")
private EntityManager em;
private List<Deck> deckList;
public String findDeck(String name) {
try {
Query query = em.createQuery("select d from Deck d");
deckList = query.getResultList();
return deckList.get(0).getDname();
} catch (Exception e) {
e.printStackTrace();
}
return "test";
}
<?xml version="1.0" encoding="UTF-8"?>
和完整的堆栈跟踪:
<persistence-unit name="NewPersistenceUnit" transaction-type="JTA">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<jta-data-source>stonesqlserver</jta-data-source>
<class>hs.Deck</class>
<properties>
<property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.SunOneJtaPlatform" />
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect"/>
</properties>
</persistence-unit>
提前谢谢。
答案 0 :(得分:0)
找到解决方案:
@Resource
protected SessionContext context;
DAO中需要,就像持久化上下文注释一样。