# Update record using influxdb-java client

**URL:** https://community.influxdata.com/t/update-record-using-influxdb-java-client/11931
**Category:** Welcome & Getting Started
**Tags:** influxdb, client-libraries
**Created:** [November 14, 2019, 11:14am UTC](https://community.influxdata.com/t/update-record-using-influxdb-java-client/11931 "2019-11-14T11:14:16Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![mns](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/mns/32/3715_2.png) [@mns](https://community.influxdata.com/u/mns)
#### Post date: [November 14, 2019, 11:14am UTC](https://community.influxdata.com/t/update-record-using-influxdb-java-client/11931/1 "2019-11-14T11:14:16Z")

</div>

I am trying to update a record (only the field values) using influxdb java client.  
Specifically, I am using InfluxDBMapper to store the queried result, I update the POJO with new field values and build the PointBuilder as below:  
final Builder b = Point.measurementByPOJO(reqInProgress.getClass()).addFieldsFromPOJO(reqInProgress);

I then use the influx.write() to send it to the DB. Batching is enabled. However I get 400 error and the values are not updated in the DB.

Is this not the right way to update values?

Update:  
I think I found the reason. My DBs are with precision of Milliseconds. I have set the TimeUnit correctly for the POJO too. However when I Build the Point as above, it does not take into consideration the TimeUnit set by me and defaults to Nanoseconds.  
This is probably the reason it fails.

I changed to below lines but it still does not change the time unit:

final long time = reqInProgress.getTime().getLong(ChronoField.MILLI\_OF\_SECOND);  
final Builder b = Point.measurementByPOJO(reqInProgress.getClass()).addFieldsFromPOJO(reqInProgress).time(time, TimeUnit.MILLISECONDS);

---

<div class="post-metadata">

### Author: ![Anaisdg](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/anaisdg/32/6401_2.png) [@Anaisdg](https://community.influxdata.com/u/Anaisdg)
#### Post date: [November 15, 2019, 5:00pm UTC](https://community.influxdata.com/t/update-record-using-influxdb-java-client/11931/2 "2019-11-15T17:00:56Z")

</div>

Hello @mns,  
What version of influx and client are you using?

---

<div class="post-metadata">

### Author: ![mns](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/mns/32/3715_2.png) [@mns](https://community.influxdata.com/u/mns)
#### Post date: [November 18, 2019, 5:43am UTC](https://community.influxdata.com/t/update-record-using-influxdb-java-client/11931/3 "2019-11-18T05:43:47Z")

</div>

Hi @Anaisdg my influx DB version is 1.7.8 and influxdb-java client version is 2.15

---

<div class="post-metadata">

### Author: ![mns](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/mns/32/3715_2.png) [@mns](https://community.influxdata.com/u/mns)
#### Post date: [November 18, 2019, 6:46am UTC](https://community.influxdata.com/t/update-record-using-influxdb-java-client/11931/4 "2019-11-18T06:46:30Z")

</div>

So I fixed my problem. Seems like using write is not the way to go when using influxDBMapper and instead influxDBMapper.save() should be used.  
The reason being when write is used, time is added as a field in the line protocol and this is invalid in influxDB.

IMHO the client library should take care of converting the time appropriately especially if we annotate it as a time column.

Also, save seems like an update by default.

---

<div class="post-metadata">

### Author: ![sjoshid](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/sjoshid/32/3212_2.png) [@sjoshid](https://community.influxdata.com/u/sjoshid)
#### Post date: [May 7, 2020, 4:57pm UTC](https://community.influxdata.com/t/update-record-using-influxdb-java-client/11931/5 "2020-05-07T16:57:43Z")

</div>

@mns and @Anaisdg  
The OP is very similar, if not exact, to what I faced. Im using Influx db version 1.5 with java client 2.15.  
I also have a POJO to map tags and fields. But for some reason `InfluxDBMapper.save(T model)` didnt work for me.  
Fetching results from db were correctly mapped to POJO. Here’s a snapshot of what I was doing:

- Get point from influx and map it to MyPOJO.
- Update it.
- Save the update with `InfluxDBMapper.save(udpatedPOJO)`.

But for some reason the update never reflected in influx. I had to manually build a `Point` and then `write()` to make it show up in Influx.

Im wondering how `save()` worked for you but not in my case.
