Question

Platform: TomEE Web profile 1.5.0.

I am trying to do a very basic thing, setup a data source for MySQL. I have read the official guide (http://openejb.apache.org/configuring-datasources.html). It asks us to enter a Resource element in openejb.xml. I can not find that file anywhere in tomee-webprofile-1.5.0. I read in other places that I could use tomee.xml for the same purpose. So, I added this to my conf/tomee.xml.

<Resource id="TestDS" type="DataSource">
    JdbcDriver  com.mysql.jdbc.Driver 
    JdbcUrl jdbc:mysql://localhost/test 
    UserName    root 
    Password    some_pass 
</Resource>

I copied MySQL driver JAR to tomee/lib folder.

I wrote this code. Showing snippets here:

@Resource(name="TestDS") 
DataSource ds; 

Connection con = ds.getConnection(); 
PreparedStatement ps = con.prepareStatement("select * from UserProfile"); 

The prepareStatement() call is throwing this exception:

java.sql.SQLSyntaxErrorException: user lacks privilege or object not found: USERPROFILE 
    at org.hsqldb.jdbc.Util.sqlException(Unknown Source) 
    at org.hsqldb.jdbc.Util.sqlException(Unknown Source) 

Why is the system using hsqldb driver? In fact, no matter what is use as name for @Resource, I get the same exception.

What am I doing wrong? I am starting TomEE from Eclipse, if that makes any difference.

Was it helpful?

Solution

I have tracked down the root cause. The problem happens only when I start TomEE from Eclipse. If I start it from command line, my data source definition works just fine.

It appears that when I run TomEE from command line, it uses configuration files from /.metadata/.plugins/org.eclipse.wst.server.core/tmp0/conf. To change this, I had to take these steps in Eclipse:

  1. Remove all deployed projects from the server.
  2. Open server settings and from "Server Locations" choose "Use Tomcat installation". This section is greyed out if you have at least one project still deployed to the server. So, make sure you have done step #1.
  3. Restart the server and redeploy the application. Now, my application is finding the data source.

OTHER TIPS

normally the installation is explained here http://tomee.apache.org/tomee-and-eclipse.html

[I would make this a comment to the answer of RajV, but do not have enough reputation to do so.]

Platform: Tomee 1.6.0 Webprofile, eclipse-jee-kepler-SR2-linux-gtk-x86_64 and OpenJDK 1.7.0_51

After doing the steps in http://tomee.apache.org/tomee-and-eclipse.html (including "Workspace Metadata Installation") I got the same error "user lacks privilege or object not found". My reaction was to:

$ ln -s [workspace_path]/Servers/tomee.xml \ [workspace_path]/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/conf/

As an advantage of this solution TomEE in eclipse is always using the current version of Workspace/Servers/tomee.xml without any further manual operation.

For me, better solution is to put tomee.xml file in your wpt server directory (/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/conf) and define your datasource there.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top