0
votes

I am trying to use JPA with SQL Server. Eclipse has great tools to map entities from database and vice-versa. For this to work, I need to associate a connection to a JPA project.

So I created a database (named it "rowcount") and a table on this database. Then when I go to Eclipse, open the JPA perspective, log in the database (Datasource Explorer / Database Connections), I cannot see any Schema associated to this particular database.

Looking in the "Error Log" view of Eclipse, I've got the following error everytime I click on "Schemas" tree-view item on Eclipse:

eclipse.buildId=M20130204-1200
java.version=1.7.0_15
java.vendor=Oracle Corporation
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=pt_BR
Framework arguments:  -product org.eclipse.epp.package.jee.product
Command-line arguments:  -os win32 -ws win32 -arch x86_64 -product org.eclipse.epp.package.jee.product

Error
Tue May 21 10:34:42 BRT 2013
com.microsoft.sqlserver.jdbc.SQLServerException

com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near the keyword 'rowcount'.
    at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:216)
    at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1515)
    at com.microsoft.sqlserver.jdbc.SQLServerStatement.doExecuteStatement(SQLServerStatement.java:792)
    at com.microsoft.sqlserver.jdbc.SQLServerStatement$StmtExecCmd.doExecute(SQLServerStatement.java:689)
    at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:5696)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1715)
    at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:180)
    at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:155)
    at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeQuery(SQLServerStatement.java:616)
    at org.eclipse.datatools.connectivity.sqm.internal.core.connection.StatementAdapter.executeQuery(StatementAdapter.java:73)
    at org.eclipse.datatools.enablement.msft.internal.sqlserver.loaders.SQL2005SchemaLoader.createResultSet(SQL2005SchemaLoader.java:53)
    at org.eclipse.datatools.connectivity.sqm.loader.JDBCSchemaLoader.loadSchemas(JDBCSchemaLoader.java:111)
    at org.eclipse.datatools.connectivity.sqm.core.rte.jdbc.JDBCCatalog.loadSchemas(JDBCCatalog.java:101)
    at org.eclipse.datatools.connectivity.sqm.core.rte.jdbc.JDBCCatalog.getSchemas(JDBCCatalog.java:64)
    at org.eclipse.datatools.connectivity.sqm.server.internal.ui.explorer.providers.content.layout.vnode.ServerExplorerVNodeContentProviderNav.displaySchemaNodeChildren(ServerExplorerVNodeContentProviderNav.java:126)
    at org.eclipse.datatools.connectivity.sqm.server.internal.ui.explorer.providers.content.layout.AbstractOnDemandContentProviderNav.getChildren(AbstractOnDemandContentProviderNav.java:169)
    at org.eclipse.datatools.connectivity.sqm.server.internal.ui.explorer.providers.content.layout.AbstractOnDemandContentProviderNav.getChildren(AbstractOnDemandContentProviderNav.java:243)
    at org.eclipse.datatools.connectivity.sqm.server.internal.ui.explorer.providers.content.layout.AbstractLayoutProviderNav.getChildren(AbstractLayoutProviderNav.java:85)
    at org.eclipse.datatools.connectivity.sqm.server.internal.ui.explorer.providers.content.impl.ServerExplorerContentProviderNav.load(ServerExplorerContentProviderNav.java:153)
    at org.eclipse.datatools.connectivity.sqm.server.internal.ui.explorer.loading.LoadingJob.run(LoadingJob.java:43)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)

I am using the latest sqljdbc4.jar and "Microsoft SQL Server 2008 JDBC Driver" in the JPA Driver properties.

This error prevents me to deploy the application in an EAR file. Even if I manage to deploy it manually on Weblogic, the application fails for the following reason:

openjpa-1.1.1-SNAPSHOT-r422266:957329 nonfatal user error> org.apache.openjpa.persistence.ArgumentException: An error occurred while parsing the query filter "SELECT N FROM Note N". Error message: The name "Note" is not a recognized entity or identifier. Known entity names: []

Oddly, "master" database shows some of its objects and schemas. Is there a workaround in SQL Server, in the JDBC driver or Eclipse for this?

1
Name the database something other than rowcount. That is a reserved keyword in SQL server. msdn.microsoft.com/en-us/library/ms189822.aspx - Display Name is missing
Precisely what I've done. After I renamed it, the application worked fine. Sometimes you just need to put some sleep and try something different. - Adriano Kretschmer

1 Answers

0
votes

Shame on me. The problem was caused because the database name was a reserved word for SQL Server. After I renamed it, it worked fine.

See the comments above, on the question.

My sincere apologies to all who stumbled here while being stressed by real problems.