# Auto-generated key gets null pointer exception with MySQL

**URL:** <https://forum.cloverdx.com/t/auto-generated-key-gets-null-pointer-exception-with-mysql/1085>\
**Category:** CloverDX Platform\
**Created:** [June 21, 2012, 12:00am UTC](https://forum.cloverdx.com/t/auto-generated-key-gets-null-pointer-exception-with-mysql/1085 "2012-06-21T00:00:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bmuller](https://avatars.discourse-cdn.com/v4/letter/b/779978/32.png) [@bmuller](https://forum.cloverdx.com/u/bmuller)\
**Post date:** [June 21, 2012, 12:00am UTC](https://forum.cloverdx.com/t/auto-generated-key-gets-null-pointer-exception-with-mysql/1085/1 "2012-06-21T00:00:00Z")

</div>

I am using CloverETL 3.0.1. I’ve coded a new graph that inserts a record and gets back a generated key. The first attempt at this yields the following exception:

> ERROR [InsertPubObject\_0] - java.lang.NullPointerException  
> DEBUG [InsertPubObject\_0] - reset thread runId; runId:0 thread name:InsertPubObject\_0  
> ERROR [WatchDog] - Graph execution finished with error  
> ERROR [WatchDog] - Node InsertPubObject finished with status: ERROR caused by: null caused by: java.lang.NullPointerException  
> ERROR [WatchDog] - Node InsertPubObject error details:  
> org.jetel.exception.JetelException: null caused by: java.lang.NullPointerException  
> at org.jetel.component.DBOutputTable.execute(DBOutputTable.java:664)  
> at org.jetel.graph.Node.run(Node.java:425)  
> at java.lang.Thread.run(Thread.java:680)  
> Caused by: java.lang.NullPointerException  
> at org.jetel.connection.jdbc.AutoKeyGenerator.fieldMap(AutoKeyGenerator.java:216)  
> at org.jetel.connection.jdbc.AutoKeyGenerator.init(AutoKeyGenerator.java:157)  
> at org.jetel.connection.jdbc.AutoKeyGenerator.fillKeyRecord(AutoKeyGenerator.java:120)  
> at org.jetel.connection.jdbc.SQLCloverStatement.fillKeyRecord(SQLCloverStatement.java:664)  
> at org.jetel.connection.jdbc.SQLCloverStatement.executeUpdate(SQLCloverStatement.java:436)  
> at org.jetel.component.DBOutputTable.runInNormalMode(DBOutputTable.java:696)  
> at org.jetel.component.DBOutputTable.execute(DBOutputTable.java:640)  
> … 2 more

I debugged through this code, and it looks like the fillKeyRecord method is attempting to initialize the input record before actually creating the key record, but it dereferences that key record within the init call (leading to the null pointer exception).

Is there some configuration setting I need to do to set up auto\_generated key records correctly?

I am using JDBC-specific MYSQL in the connection.

The insert statement looks like this:

```auto

INSERT INTO pub_object (tair_object_id, name, table_name, date_entered, date_updated, 
       entered_by, updated_by, date_last_synchronized)
VALUES ($tair_object_id, $name, ${table_name}, CURRENT_DATE, CURRENT_DATE, 75, 75, CURRENT_DATE)
RETURNING $id := auto_generated, $tair_object_id := $tair_object_id

```

---

<div class="post-metadata">

**Author:** ![mzatopek](https://avatars.discourse-cdn.com/v4/letter/m/b5e925/32.png) [@mzatopek](https://forum.cloverdx.com/u/mzatopek)\
**Post date:** [June 22, 2012, 2:56pm UTC](https://forum.cloverdx.com/t/auto-generated-key-gets-null-pointer-exception-with-mysql/1085/2 "2012-06-22T14:56:36Z")

</div>

Hello,

unfortunately the error message is not too descriptive. But according my investigation, this NPE is thrown in case the second output port is not attached.

See our DBOutputTable documentation  
[http://doc.cloveretl.com/documentation/ … table.html](http://doc.cloveretl.com/documentation/UserGuide/topic/com.cloveretl.gui.docs/docs/dboutputtable.html)

The first output port is used for rejected records and the second port is used for auto-generated data fields and right this port needs to be attached.

Best regards, Martin

---

<div class="post-metadata">

**Author:** ![bmuller](https://avatars.discourse-cdn.com/v4/letter/b/779978/32.png) [@bmuller](https://forum.cloverdx.com/u/bmuller)\
**Post date:** [June 22, 2012, 5:07pm UTC](https://forum.cloverdx.com/t/auto-generated-key-gets-null-pointer-exception-with-mysql/1085/3 "2012-06-22T17:07:49Z")

</div>

Yes, that was the problem–I accidentally put the generated output edge onto the first port in reshuffling the components. I corrected that and the graph now works as intended, thanks very much.

I would suggest adding a bug report to improve detection of the situation. Given that the SQL statement has a RETURNING clause, Clover does know there is an intention to generate keys, so a missing edge on Port 2 should raise a component error saying that a RETURNING clause is incompatible with no edge on Port 2 (rather than the current NPE, which as you say is not very informative).

Thanks again for your prompt help on this.

---

<div class="post-metadata">

**Author:** ![mzatopek](https://avatars.discourse-cdn.com/v4/letter/m/b5e925/32.png) [@mzatopek](https://forum.cloverdx.com/u/mzatopek)\
**Post date:** [June 25, 2012, 11:48am UTC](https://forum.cloverdx.com/t/auto-generated-key-gets-null-pointer-exception-with-mysql/1085/4 "2012-06-25T11:48:11Z")

</div>

You are definitely right, I have reported the issue:

[http://bug.javlin.eu/browse/CL-2343](http://bug.javlin.eu/browse/CL-2343)

Martin
