# More than 100 fields as IN parameter is not permitted -- cannot map Yugabyte UDT, used as a parameter of a function, from Java

**URL:** https://forum.yugabyte.com/t/more-than-100-fields-as-in-parameter-is-not-permitted-cannot-map-yugabyte-udt-used-as-a-parameter-of-a-function-from-java/2304
**Category:** General
**Created:** [November 5, 2023, 7:25pm UTC](https://forum.yugabyte.com/t/more-than-100-fields-as-in-parameter-is-not-permitted-cannot-map-yugabyte-udt-used-as-a-parameter-of-a-function-from-java/2304 "2023-11-05T19:25:46Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Pro9](https://avatars.discourse-cdn.com/v4/letter/p/ac8455/32.png) [@Pro9](https://forum.yugabyte.com/u/Pro9)
#### Post date: [November 5, 2023, 7:25pm UTC](https://forum.yugabyte.com/t/more-than-100-fields-as-in-parameter-is-not-permitted-cannot-map-yugabyte-udt-used-as-a-parameter-of-a-function-from-java/2304/1 "2023-11-05T19:25:46Z")

</div>

Hi,  
I am using YugabyteDB YSQL. I have a use case where I need one conditional upsert to a table which has more than 100 fields, which is restricted in Yugabyte. I don’t want to use in that way too. I checked with jsonb and UDT and found UDT is handy.  
I have created one Type where I have used all the fields that are required, passed it as IN parameter in a function. The function is working well. But from Java I am not able to map it properly. Below is what I have written:

## Dependency :
 com.yugabyte jdbc-yugabytedb 42.3.0
## My Java Code :

public void generateBatch(List myData) {  
if (org.springframework.util.CollectionUtils.isEmpty(myData)) {  
return;  
}  
log.info(“Called”);

```
	try (Connection connection = dataLakeDriverManager.connect()) {
		boolean autoCommit = connection.getAutoCommit();
		connection.setAutoCommit(false);
		handlePreparedStatement(connection, myData);
		connection.setAutoCommit(autoCommit);
	} catch (SQLException e) {
		log.error("", e);
	}

}

```

public Connection connect() throws SQLException {  
Connection conn = null;  
String dbConnectionString = connectionString();  
conn = DriverManager.getConnection(dbConnectionString);  
return conn;  
}

private void handlePreparedStatement(Connection connection, List myData)  
throws SQLException {

```
	final int size = myData.size();
	try (PreparedStatement prepareStatement = connection.prepareStatement("SELECT my_upsert(?)")) {
		int rowNum = 1;
		for (TxnDetails curTxnDetails : myData) {

			prepareStatement.addBatch();
			prepareStatement.setObject(1,
					connection.createStruct("my_type", curTxnDetails.populate(prepareStatement, 0)));
			if (rowNum % batchSize == 0 || rowNum == size) {
				prepareStatement.executeBatch();
			}
		}
		prepareStatement.executeBatch();
		connection.commit();
	} catch (SQLException e) {
		log.error("", e);
		connection.rollback();
	}
}

```

## The below error I am getting in runtime from the app log :

com.yugabyte.jdbc.PgConnection.createStruct(String, Object) is not yet implemented.  
at com.yugabyte.Driver.notImplemented(Driver.java:848)  
at com.yugabyte.jdbc.PgConnection.createStruct(PgConnection.java:1395)  
at

## ysqlsh =\> my\_upsert(data my\_type) :

CREATE OR REPLACE FUNCTION db.my\_upsert(data my\_type)  
RETURNS void  
LANGUAGE plpgsql  
AS $function$  
BEGIN  
IF (condition 1) THEN  
BEGIN  
insert into db.table (data.col1,data.col2,data.col3,…,data.col109);  
RETURN;  
EXCEPTION  
WHEN unique\_violation THEN  
–Let it go forward  
END;  
UPDATE db.table SET col1=data.col1, col2=data.co2, col3=data.col3, … , col109=data.col109 WHERE col20 = data.col20 and col5 = data.col5 and col104 = data.col104;

```
            IF found THEN
                    RETURN;
					END IF;

    ELSE
            LOOP
                    -- first try to update the key
                    UPDATE db.table SET col29=data.col29, col30=data.col30, col31=data.col30 WHERE col25 = $20 and rrn = $5 and txn_ts = $104;
                    IF found THEN
                            RETURN;
                    END IF;
                    -- not there, so try to insert the key
                    -- if someone else inserts the same key concurrently,
                    -- we could get a unique-key failure

                    BEGIN

```

**Please let me know:**  
**whether using UDT is a correct approach in this case.**  
**How to bind the parameter from java.**

---

<div class="post-metadata">

### Author: ![dorian\_yugabyte](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.yugabyte.com/dorian_yugabyte/32/206_2.png) [@dorian\_yugabyte](https://forum.yugabyte.com/u/dorian_yugabyte)
#### Post date: [November 6, 2023, 9:02am UTC](https://forum.yugabyte.com/t/more-than-100-fields-as-in-parameter-is-not-permitted-cannot-map-yugabyte-udt-used-as-a-parameter-of-a-function-from-java/2304/2 "2023-11-06T09:02:39Z")

</div>

This is being discussed in slack [#yb-users](https://yugabyte-db.slack.com/archives/CG0KQF0GG/p1699261283635829?thread_ts=1699084849.906149&cid=CG0KQF0GG) channel.
