Use Table for MySQL exception

I’m new at Vaddin and get some problems recently…

I’m trying to do a simple practice - get data from MySQL and display in table. However, I’m stuck for many days…
Here are my codes: JDBCConnectionPool connectionPool = new SimpleJDBCConnectionPool("com.mysql.jdbc.Driver","jdbc:mysql://172.16.88.206:3306/openfire", "openfire", "openfire", 2, 2); //TableQuery TableQuery tQuery = new TableQuery("MessageArchive", connectionPool); tQuery.setVersionColumn("OPTLOCK"); SQLContainer container = new SQLContainer(tQuery); Table table = new Table("Demo",container); layout.addComponent(table); The exception is:

Jun 30, 2014 4:04:14 PM org.atmosphere.cpr.AtmosphereFramework interceptor INFO: Installed AtmosphereInterceptor Track Message Size Interceptor using | with priority BEFORE_DEFAULT java.lang.IllegalArgumentException: Primary key constraints have not been defined for the table "MessageArchive". Use FreeFormQuery to access this table. at com.vaadin.addon.sqlcontainer.query.TableQuery.fetchMetaData(TableQuery.java:508) at com.vaadin.addon.sqlcontainer.query.TableQuery.<init>(TableQuery.java:87) at com.vaadin.addon.sqlcontainer.query.TableQuery.<init>(TableQuery.java:101) Indeed, no primary key is set for table: MessageArchive. So I change to use “FreeformQuery”, as below:

FreeformQuery fquery = new FreeformQuery ("SELECT * FROM openfire.ofMessageArchive",connectionPool,"sentDate"); SQLContainer container = new SQLContainer(fquery); Table table = new Table("demo",container); table.setSelectable(true); table.setImmediate(true); table.setSizeFull(); layout.addComponent(table); Still exception…

Jun 30, 2014 4:23:29 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [com.example.messagemanager.MsgUI$Servlet]
 in context with path 
[/MessageManager] threw exception [com.vaadin.server.ServiceException: java.lang.AbstractMethodError]
 with root cause
java.lang.AbstractMethodError
    at com.vaadin.ui.AbstractSelect.setContainerDataSource(AbstractSelect.java:1031)
    at com.vaadin.ui.Table.setContainerDataSource(Table.java:2737)
    at com.vaadin.ui.Table.setContainerDataSource(Table.java:2682)
    at com.vaadin.ui.Table.<init>(Table.java:603)
    at com.example.messagemanager.MsgUI.init(MsgUI.java:126)
    at com.vaadin.ui.UI.doInit(UI.java:641)
    at com.vaadin.server.communication.UIInitHandler.getBrowserDetailsUI(UIInitHandler.java:222)
    at com.vaadin.server.communication.UIInitHandler.synchronizedHandleRequest(UIInitHandler.java:74)
    at com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:41)
    at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1405)
    at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:237)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:315)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)

Can anyone help? Thanks thanks a lot

First a question: Which line is MsgUI.java:126 in your code snippet?
Also if you don’t have a primary key, don’t define in your FreeformQuery constructor that “sentDate” is a primary column. Just use the query string and the connectionpool in your case.

Hi Marius,

MsgUI.java:126 is below:

Table table = new Table("demo",container); I also try to take out the “sentDate”, like below:

FreeformQuery fquery = new FreeformQuery ("SELECT * FROM openfire.ofMessageArchive",connectionPool); But I get the same exception…

Jun 30, 2014 8:37:00 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [com.example.messagemanager.MsgUI$Servlet]
 in context with path 
[/MessageManager] threw exception [com.vaadin.server.ServiceException: java.lang.AbstractMethodError]
 with root cause
java.lang.AbstractMethodError
    at com.vaadin.ui.AbstractSelect.setContainerDataSource(AbstractSelect.java:1031)
    at com.vaadin.ui.Table.setContainerDataSource(Table.java:2737)
    at com.vaadin.ui.Table.setContainerDataSource(Table.java:2682)
    at com.vaadin.ui.Table.<init>(Table.java:603)
    at com.example.messagemanager.MsgUI.init(MsgUI.java:126)
    at com.vaadin.ui.UI.doInit(UI.java:641)
    at com.vaadin.server.communication.UIInitHandler.getBrowserDetailsUI(UIInitHandler.java:222)
    at com.vaadin.server.communication.UIInitHandler.synchronizedHandleRequest(UIInitHandler.java:74)
    at com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:41)
    at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1405)
    at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:237)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:315)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)

Do you have any idea? Thanks a lot!

Okay i just had a quick look around and it seems to be a problem in your classpath.
Have a look at Henri’s post:
https://vaadin.com/forum/#!/thread/1678324/2768280

Hi,

I’ve checked the post but still no clue.
I’m using Eclipse Kepler + jdk1.7.0_60 + tomcat apache-tomcat-7.0.53, to create a Vaadin project 7.2.2. I put the lib mysql-connector-java-5.1.30 under tomcat lib folder and also include in project web lib. Is there any I miss? Very very appreciate your help.

Did you check if you maybe have multiple version of vaadin-jars in your classpath?

Check in eclipse project properties → Java build path → Order and Export. Is something duplicated there? I know at least that tomcat in that list might sometimes cause issues and you should move it to the bottom of the list. However it probably isn’t the case here, but it might be something similar.

Hi,

My problem solved!!! Many thanks for your help!

How I fix my issue? Use

import com.vaadin.data.util.sqlcontainer.SQLContainer;

instead of

import com.vaadin.addon.sqlcontainer.SQLContainer; (Although I don’t know why/when I import com.vaadin.addon… )

Thanks again!!!

Thanks so much for posting your solution! I was porting a project over from Vaadin 6 to 7 and had this exact same issue and couldn’t figure it out.

Chialin,

Thank you! I am having the same problem, you saved my day!