1

I'm working within Eclipse. I've added a TomEE server which starts up fine but there seems to be a problem creating a MySQL DataSource.

I defined the following DataSource in TomEE 1.7.2:

<Resource id="jdbc/WCMDS" type="javax.sql.DataSource">
    jdbcDriver com.mysql.jdbc.Driver
    jdbcUrl jdbc:mysql://localhost:3306/wcm?useUnicode=yes&amp;characterEncoding=utf8&amp;autoReconnect=true
    jtaManaged false 
    password pass
    userName user
    InitialSize 50 
    MaxActive 100
    MaxIdle 3   
</Resource>

In my bean, I retrieve the DataSource

@PostConstruct
public void postConstruct() {
    InitialContext context = new InitialContext();
    String dataSourceName="java:/comp/env/"+getDatasourceJndiName();
    DataSource dataSource = (DataSource) context.lookup(dataSourceName);
    DATASOURCE = dataSource;

In bean method that executes a query, I use retrieved DataSource to obtain a connection.

Connection connection = DATASOURCE.getConnection();

Then I build a PreparedStatement

connection.prepareStatement("select * from myTableName");

While preparing the statement, I run into javax.el.ELException: org.hsqldb.HsqlException: user lacks privilege or object not found: myTableName

=============================================================

Please note, this isn't a problem on the database side. When I replace the jndi lookup with manually created datasource, things work fine.

MysqlDataSource datasource = new MysqlDataSource();
datasource.setURL("jdbc:mysql://localhost:3306/wcm?useUnicode=yes&amp;characterEncoding=utf8&amp;autoReconnect=true");
datasource.setUser("user");
datasource.setPassword("pass");
DATASOURCE=datasource;

=============================================================

So the error I'm getting must have something to do with the datasource being managed by TomEE. Why would a connection from such datasource prevent me from creating statements?

jacekn
  • 1,521
  • 5
  • 29
  • 50
  • did you copy the latest mysql-connector-5.1.x.jar into your `tomee/lib` folder? if not, this could be the cause, as the container has no mysql driver in the early startup phase when the container initializes the data source from the xml based configuration. For this reason, a stub/dummy hsqldb is being brought up by default (which does have nothing in common with your mysql DB). – MWiesner Mar 15 '16 at 16:07
  • Yes, I have mysql-connector-java-5.1.18-bin.jar in `C:/TomEE_1_7_2/lib`. – jacekn Mar 16 '16 at 12:42

2 Answers2

0

the resource hasn't been created and you got the default hsqldb datasource instead.

Did you define it in conf/tomee.xml?

Tip: you can check the configured datasource using JMX console in openejb

Romain Manni-Bucau
  • 3,354
  • 1
  • 16
  • 13
  • I've added it to tomee.xml, as per snippet in my question. I have also tried `type="com.mysql.jdbc.jdbc2.optional.MysqlDataSource"`. Notice, I am not getting a NameNotFound exception. It's finding a Managed datasource with GeronimoTransactionManager. – jacekn Mar 23 '16 at 21:10
  • I found a post that says there's a problem with setting up TomEE datasources on servers under Eclipse. So I should add to my question that I'm working within Eclipse. I have copied tomee.xml under the `/servers/` directory but that did not make any difference. – jacekn Mar 23 '16 at 21:36
  • type should be "DataSource" (it is a resource type not the qualified name) and the MysqlDataSource should be JdbcDriver property value or class-name attribute value depending the config you do. – Romain Manni-Bucau May 02 '16 at 21:18
0

So this seems to be a problem with TomEE under Eclipse. Another user has run into this issue and presented his findings. I have followed his instructions and I am now getting a MySQL data source.

How to define MySQL data source in TomEE?

Community
  • 1
  • 1
jacekn
  • 1,521
  • 5
  • 29
  • 50