question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

JDBC not mapping properly in 4.5.0

See original GitHub issue

Curl request on the database:

/usr/bin/curl -on/json' -sSXPOST '127.0.0.1:4200/_sql?pretty' -d@- << EOF
 {"stmt":"SELECT allowed_users FROM myproject.projects WHERE allowed_users != [NULL]"}
EOF

Result:

{"cols":["allowed_users"],"rows":[[[{"accepted":false,"role":"developer","email":"email@gmail.com"}]]],
"rowcount":1,"duration":50.122208}

Java line on which error occurs:

Object[] array = (Object[]) rs.getArray("allowed_users").getArray();

Java model AllowedUser:

public class AllowedUser {

    @JsonProperty
    String email;
    @JsonProperty
    String role;
    @JsonProperty
    Boolean accepted;

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getRole() {
        return role;
    }

    public void setRole(String role) {
        this.role = role;
    }

    public Boolean getAccepted() {
        return accepted;
    }

    public void setAccepted(Boolean accepted) {
        this.accepted = accepted;
    }
}

Error that Crate returns:

Unrecognized field "type" (class models.AllowedUser), not marked as ignorable 
(3 known properties: "email", "role", "accepted"]) at [Source: (String)"[{"type":"json","value":
"{\"accepted\":false,\"email\":\"email@gmail.com\",\"role\":\"developer\"}"}]"; line: 1, column: 11] 
(through reference chain: java.util.ArrayList[0]->models.AllowedUser["type"])

Column allowed_users defined as:

allowed_users ARRAY(OBJECT(IGNORED))

Locally and on the QA server Crate doesn’t return any errors and works as expected. The issue occurs only on the production server. The dataset is identical on all envs.

Local and QA Crate version: 4.0.10 Production Crate version: 4.5.0

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
harispdevcommented, Apr 30, 2021

@proddata thank you so much for your patience and your assistance Georg. I’ve managed to solve the issue and If anyone comes across the same issue, you need to loop your data and parse the Object from the (Object[] array) to a method similar to this:

public static AllowedUser mapPGToModel(Object object) throws JsonProcessingException {
        PGobject pGobject = (PGobject) object;

        ObjectMapper mapper = new ObjectMapper();
        return mapper.readValue(pGobject.getValue(), AllowedUser.class);
}
0reactions
proddatacommented, Apr 30, 2021

I’m sorry, perhaps I’m missing something obvious, but how can I map this with Jackson?

Something like that:

public class Main {

    public static void main(String[] args) {

        try {
            Properties props = new Properties();
            props.put("user","crate");
            Connection conn = DriverManager.getConnection("crate://localhost:5432/",props);
            Statement statement = conn.createStatement();
            ResultSet resultSet = statement.executeQuery("SELECT allowed_users FROM myproject.projects where allowed_users != [null];");
            resultSet.next();
            Object[] array = (Object[]) resultSet.getArray("allowed_users").getArray();

            ObjectMapper objectMapper = new ObjectMapper();
            objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
            AllowedUser p = objectMapper.readValue( array[0].toString(), AllowedUser.class);

            System.out.println("Email: "+p.email);
            System.out.println("Role: "+p.role);
            System.out.println("Accepted: "+p.accepted);

        } catch (SQLException e) {
            System.out.println( e);
        } catch (JsonParseException e) {
            e.printStackTrace();
        } catch (JsonMappingException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}

class AllowedUser {
    @JsonProperty
    String email;
    @JsonProperty
    String role;
    @JsonProperty
    Boolean accepted;
}

I will close this issue now, as this is neither a bug report, nor feature request for CrateDB. I would kindly as you to open a new discussion on https://community.crate.io/ for that matter

Read more comments on GitHub >

github_iconTop Results From Across the Web

No Dialect mapping for JDBC type: 1111 - java - Stack Overflow
The error message means one column returns data in a type which cannot be mapped. No Dialect mapping for JDBC type: 1111 indicates...
Read more >
“How-to” Guides - Spring
A YAML file is parsed to a Java Map<String,Object> (like a JSON object), and Spring Boot flattens the map so that it is...
Read more >
Micronaut Data - GitHub Pages
Rewritten entity mapper allows more complex mapping for JDBC/R2DBC entities ... Since Micronaut Data is a build time tool, it will not work...
Read more >
Defects fixed in the IDM 4.5.0 release - Support - Micro Focus
Defect ID Component Description 848056 Audit Integration Audit events are not generated for .NET RL 894551 Audit Integration Latest IDM Collector not rebraned to NetIQ 867897...
Read more >
Use Spring Data JDBC with Azure Database for PostgreSQL
Learn how to use Spring Data JDBC with an Azure Database for PostgreSQL ... Cloud Azure currently supports passwordless connections only in version...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found