Mantis Bugtracker

Viewing Issue Simple Details Jump to Notes ] View Advanced ] Issue History ] Print ]
ID Category Severity Reproducibility Date Submitted Last Update
0002579 [Resin] minor always 04-08-08 09:55 04-09-08 10:13
Reporter emil View Status public  
Assigned To ferg
Priority normal Resolution fixed  
Status closed   Product Version 3.1.6
Summary 0002579: NPE when using Amber with recommended MySQL driver
Description (Reported by Charles Lyon)

After a very frustrating day I still haven't got Amber to work as it should
on Resin 3.1.5. I have managed to get my examples to read things out of the
databases and update objects from data (and vice-versa) already in the
databases and this works beautifully. However, whenever I try to write a
new object into the databases, I get an NPE:

====== java.lang.NullPointerException at
at com.caucho.sql.UserConnection.prepareStatement(
at tests.TestObject.__caucho_create( at
tests.TestObject.__caucho_flush( at
at example.TestServlet.service( at
javax.servlet.http.HttpServlet.service( at
at com.caucho.server.http.HttpRequest.handleRequest(
at at
com.caucho.util.ThreadPool$Item.runTasks( at
com.caucho.util.ThreadPool$ at ======

This is what I'm doing in a Servlet's service method:

  TestObject to = new TestObject();
  _entityManager.persist(to); // this is the problem line

and if I comment out the penultimate line I have no problem, so it is just
the _entityManager.persist(to) invocation that causing the problem.

If I persist() any object already in the database that works without
exception (though granted it is not necessary to do this since it happens
automatically at commit).

My TestObject class is quite simple:

package tests;

import java.util.Collection;
import javax.persistence.*;

public class TestObject {
    private int id;

    private String primaryHostname;
    private String primaryIP;

    // and then just setters/getters for those properties

Okay, I have successfully traced the source of this problem. Firstly, I'm
using the current MySQL Connector/J 5.1.5 binary.

I was using the recommended MySQL driver (as per all the Resin tutorials)
which is:


However, if I change this to:


then the problem I faced resolves itself. So one might think it's a problem
with that driver (which it might be - I haven't checked older versions of
Connector/J). As a temporary fix I'm leaving this as my driver - unless you
have a good reason not to?

However, I've gone further and delved into the source for the latest
snapshot (31st March). Using the MysqlConnectionPoolDataSource driver, I've
traced the problem to the following method:


and the pair of lines:

if(resultType > 0)
  return conn.prepareStatement(sql,resultType);

This is returning null since the resultType passed in to the
prepareStatement method is 1. If I force resultType=0 in this method,
everything works as expected. I guess this is something to do with caching
statements (and for a new object being persisted those haven't already been
cached?), but I'll leave such inferences up to the experts ;)

Additional Information
Attached Files

- Relationships

- Notes
04-09-08 10:13


- Issue History
Date Modified Username Field Change
04-08-08 09:55 emil New Issue
04-09-08 10:13 ferg Note Added: 0002950
04-09-08 10:13 ferg Assigned To  => ferg
04-09-08 10:13 ferg Status new => closed
04-09-08 10:13 ferg Resolution open => fixed
04-09-08 10:13 ferg Fixed in Version  => 3.1.6

Mantis 1.0.0rc3[^]
Copyright © 2000 - 2005 Mantis Group
29 total queries executed.
26 unique queries executed.
Powered by Mantis Bugtracker