Giter Club home page Giter Club logo

Comments (9)

aley2003 avatar aley2003 commented on June 22, 2024

Created pull request #458

from datanucleus-rdbms.

andyjefferson avatar andyjefferson commented on June 22, 2024

Please provide a simple testcase that demonstrates the problem. Test suites need to be able to recreate such things.

from datanucleus-rdbms.

aley2003 avatar aley2003 commented on June 22, 2024

How can I write a test case that shows how Datanucleus fetch data from the database (in this case which ResultSet getter has been called)?

I have problems with the mapping of SQL queries to ResultObjects (with Oracle 11g).
I have seen in debugger, that there was a call of ResultSet.getObject() for all my number columns.
In Oracle ResultSet.getObject() deliveres a BigDecimal for all number types.
This leads to error messages like

Query needs to return objects of type "..." but it was impossible to set the field "..." type "java.math.BigDecimal". The field should have either a public set/put method, or be public.

I have to add an setter with a BigDecimal parameter to my result class for all number fields (of type short, int, Integer, Long, ...).

from datanucleus-rdbms.

aley2003 avatar aley2003 commented on June 22, 2024

Using ResultSet.getInt()/getLong()/... hides a problem with setting the values in the result object fields.
For example the BigDecimal got from Oracle has to be converted to an int.
This works on the first row of the ResultSet because of the conversion in the catch in ResultClassROF.getObject() line 456 .
For the following rows ResultClassFieldSetter.set will be called directely with the BigDecimal. At this point, there will be no conversion of the BigDecimal to Integer, because Integer is not assignable from BigDecimal (ResultClassROF:889).
This results in the 021204 NucleusUserException in ResultClassROF:343 mentioned above.

from datanucleus-rdbms.

aley2003 avatar aley2003 commented on June 22, 2024

My test case can reproduce the problem but I was able to reproduce the problem with Oracle only.
Strangely it does get no error with 'mvn clean compile test' but if I call SimpleTestMain directly.

test-jdo-sql-ResultSetROF-getObject.zip

from datanucleus-rdbms.

andyjefferson avatar andyjefferson commented on June 22, 2024

Thx. The testcase reproduces a problem using Junit on Oracle (11g) (no need for any "main"), due to how Oracle JDBC maps types

from datanucleus-rdbms.

andyjefferson avatar andyjefferson commented on June 22, 2024

Suggest that you try with the change made above, since that is way simpler than your PR and works.for.me

from datanucleus-rdbms.

aley2003 avatar aley2003 commented on June 22, 2024

It looks like your commit solves the conversions problem for Oracle. Thx.

My commit would be an additional enhancement for the way the data is fetched from the ResultSet.
ResultClassROF.getResultObject(ResultSet, int) has an optimization to use the suitable getter (instead of getObject()), if the query has a simple return type. My commit expands this optimization for the fields of the class in case of a class return type.

from datanucleus-rdbms.

andyjefferson avatar andyjefferson commented on June 22, 2024

Marking as fixed, but retaining PR since would be nice to rework the whole class and could use as part of that

from datanucleus-rdbms.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.