我正在使用gwt,hibernate和PostgreSql构建Web应用程序。当我尝试从数据库中获取数据时,我收到来自异常的错误。
特别地: RPC失败,无法构建EntityManagerFactory。 在调试期间,我可以看到消息:无法将org.hibernate.Dialect强制转换为org.hibernate.dialect.PostgreSQLDialect 或删除jar后:使用方言:org.hibernate.dialect.PostgreSQLDialect
相关的源代码是:
public class DomainTransaction {
...
static {
try {
emfInstance = Persistence.createEntityManagerFactory("zonk");
}
catch (Exception e) {
System.out.println("Create entity manager factory failed" + e.getMessage());
}
}
public DomainTransaction() {
em = emfInstance.createEntityManager();
tx = em.getTransaction();
tx.begin();
}
我调用createEntityManager()的方法:
public List<String> getEmployees(){
DomainTransaction dmTran = new DomainTransaction();
List<Employee> employees = dmTran.getEM().createQuery("select e from Employee e", Employee.class).getResultList();
List<String> names = new ArrayList<String>();
for(Employee emp : employees){
names.add(emp.getLastname()+", "+emp.getLastname());
}
return names;
}
可能是什么问题?与罐子有什么关系?
问题显然在于使用org.hibernate.dialect.PostgreSQLDialect。然而为什么它不能使用方言?
编辑:例外显示为: 信息:HHH000400:使用方言:org.hibernate.dialect.PostgreSQLDialect 创建实体管理器工厂失败[PersistenceUnit:zonk]无法构建EntityManagerFactory 在端口8888上启动Jetty [WARN]调度传入的RPC调用时发生异常 com.google.gwt.user.server.rpc.UnexpectedException:服务方法'public abstract java.util.List com.AL_CalendarPage.client.ZonkService.getEmployees()'引发了一个意外的异常:java.lang.NullPointerException