大家好,所以我正在Vaadin / GWT做我的第一步,我发现也许我没有得到一些其统治或其他的机制。首先,我在仪表板上进行了修改 - 演示,你可以在这里查看 - > https://github.com/vaadin/dashboard-demo
我试图从我的数据库中获取一些数据。我在spring项目中经常使用JPA所以我配置了所有属性,但只是为了确保这是我的persistance.xml:
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" 版本=" 2.0">
<persistence-unit name="transactionUnit" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<properties>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/testDb?UseUnicode=true&characterEncoding=utf8" />
<property name="javax.persistence.jdbc.user" value="root" />
<property name="javax.persistence.jdbc.password" value="root" />
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.hbm2ddl.auto" value="create" />
</properties>
</persistence-unit>
我还有一些非常简单的用户类:
@Entity(name = "USERS")
public class UserImpl implements User, java.io.Serializable {
/**
*
*/
private static final long serialVersionUID = -7872836283108223143L;
@Id
@Column(name = "USER_ID")
@GeneratedValue(strategy = GenerationType.AUTO)
protected Long id;
@Column(name = "USERNAME", unique = true)
protected String username;
@Column(name = "FIRST_NAME")
protected String firstName;
@Column(name = "LAST_NAME")
protected String lastName;
@Column(name = "EMAIL")
protected String email;
@Column(name = "PHONE_NUMBER")
protected String phoneNumber;
@Column(name = "PASSWORD")
protected String password;
@Column(name = "ENABLED")
protected boolean active;
@Override
public Long getId() {
return id;
}
@Override
public void setId(Long id) {
this.id = id;
}
@Override
public String getUsername() {
return username;
}
@Override
public void setUsername(String username) {
this.username = username;
}
@Override
public String getPassword() {
return password;
}
@Override
public void setPassword(String password) {
this.password = password;
}
@Override
public boolean isActive() {
return active;
}
@Override
public void setActive(boolean active) {
this.active = active;
}
@Override
public String getFirstName() {
return firstName;
}
@Override
public void setFirstName(String firstName) {
this.firstName = firstName;
}
@Override
public String getLastName() {
return lastName;
}
@Override
public void setLastName(String lastName) {
this.lastName = lastName;
}
@Override
public String getEmail() {
return email;
}
@Override
public void setEmail(String email) {
this.email = email;
}
@Override
public String getPhoneNumber() {
return phoneNumber;
}
@Override
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
}
并指出我有这样的方法(也简单UBER):
@Subscribe
public void userLoginRequested(final UserLoginRequestedEvent event) {
EntityManager em = Persistence
.createEntityManagerFactory("transactionUnit")
.createEntityManager();
TypedQuery<com.vaadin.demo.dashboard.domain.classes.UserImpl> query = em.createQuery("SELECT user FROM com.vaadin.demo.dashboard.domain.classes.UserImpl user WHERE LOWER(username) = :username", com.vaadin.demo.dashboard.domain.classes.UserImpl.class);
com.vaadin.demo.dashboard.domain.classes.UserImpl testUser;
testUser = query.getSingleResult();
User user = getDataProvider().authenticate(event.getUserName(),
event.getPassword());
VaadinSession.getCurrent().setAttribute(User.class.getName(), user);;
}
方法应该简单地返回对象但是没有我有这样的错误:
[EL Info]:2015-11-24 15:43:16.62 - ServerSession(1650623529) - EclipseLink,版本:Eclipse 持久性服务 - 2.2.0.v20110202-r8913 [EL Info]:2015-11-24 15:43:16.797 - 的ServerSession(1650623529) - 文件:/ d:/Serwery/apache-tomcat-8.0.15/webapps/ROOT/WEB-INF/classes/_transactionUnit 登录成功lis 24,2015 3:43:16 PM com.vaadin.server.DefaultErrorHandler doDefault SEVERE: java.lang.NoSuchMethodError: javax.persistence.EntityManager.createQuery(Ljava /郎/字符串; Ljava /郎/类;)Ljavax /持久/ TypedQuery; 在 com.vaadin.demo.dashboard.DashboardUI.userLoginRequested(DashboardUI.java:103) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 在java.lang.reflect.Method.invoke(Method.java:497)at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) 在 com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) 在com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) 在 com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) 在com.google.common.eventbus.EventBus.post(EventBus.java:275)at com.vaadin.demo.dashboard.event.DashboardEventBus.post(DashboardEventBus.java:17) 在 com.vaadin.demo.dashboard.view.LoginView $ 1.buttonClick(LoginView.java:102) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 在java.lang.reflect.Method.invoke(Method.java:497)at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:508) 在com.vaadin.event.EventRouter.fireEvent(EventRouter.java:198)at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:161)at com.vaadin.server.AbstractClientConnector.fireEvent(AbstractClientConnector.java:1003) 在com.vaadin.ui.Button.fireClick(Button.java:393)at com.vaadin.ui.Button $ 1.click(Button.java:61)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 在java.lang.reflect.Method.invoke(Method.java:497)at com.vaadin.server.ServerRpcManager.applyInvocation(ServerRpcManager.java:158) 在 com.vaadin.server.ServerRpcManager.applyInvocation(ServerRpcManager.java:118) 在 com.vaadin.server.communication.ServerRpcHandler.handleInvocations(ServerRpcHandler.java:313) 在 com.vaadin.server.communication.ServerRpcHandler.handleRpc(ServerRpcHandler.java:202) 在 com.vaadin.server.communication.UidlRequestHandler.synchronizedHandleRequest(UidlRequestHandler.java:95) 在 com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:41) 在 com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1408) 在com.vaadin.server.VaadinServlet.service(VaadinServlet.java:351) 在javax.servlet.http.HttpServlet.service(HttpServlet.java:725)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291) 在 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) 在 org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) 在 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) 在 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) 在 org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219) 在 org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106) 在 org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501) 在 org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142) 在 org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) 在 org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610) 在 org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) 在 org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:537) 在 org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1085) 在 org.apache.coyote.AbstractProtocol $ AbstractConnectionHandler.process(AbstractProtocol.java:658) 在 org.apache.coyote.http11.Http11NioProtocol $ Http11ConnectionHandler.process(Http11NioProtocol.java:222) 在 org.apache.tomcat.util.net.NioEndpoint $ SocketProcessor.doRun(NioEndpoint.java:1556) 在 org.apache.tomcat.util.net.NioEndpoint $ SocketProcessor.run(NioEndpoint.java:1513) 在 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) 在 java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:617) 在 org.apache.tomcat.util.threads.TaskThread $ WrappingRunnable.run(TaskThread.java:61) 在java.lang.Thread.run(Thread.java:745)
问题是我的做法有什么问题?
答案 0 :(得分:0)
您的类路径中是否是正确的java持久性版本?
您尝试调用的createQuery
方法自版本2.0起首次可用
/**
* @since Java Persistence 2.0
*/
public <T> TypedQuery<T> createQuery(CriteriaQuery<T> criteriaQuery);
如果您使用maven,请执行以下操作:
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>javax.persistence</artifactId>
<version>2.1.0</version>
</dependency>
不喜欢:
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0.2</version>
</dependency>