-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed error when inserting a row in the database with a primary key o… #79
Fixed error when inserting a row in the database with a primary key o… #79
Conversation
…f type long from a table generated by `database.createTable(Class.class)`
yes it is the same error |
Your solution is actually pretty good. I was hoping they'd just fix the bug in the JDBC driver, but there has been no activity on the bug in two years (https://bugs.mysql.com/bug.php?id=101823), so it's time for a workaround. I haven't time to test your code thoroughly. Have you tried it out? |
I ran some tests with several different variable types and everything seems to work Yesterday I make a conditional to check if the type will be would be something like this if (value instanceof BigInteger) {
if (prop.field.getType().equals(Long.TYPE) || prop.field.getType().equals(Long.class)) {
value = ((BigInteger) value).longValue();
} else if (prop.field.getType().equals(Integer.TYPE) || prop.field.getType().equals(Integer.class)) {
value = ((BigInteger) value).intValue();
}
}
prop.field.set(pojo, value); if not needed, in my tests everything worked fine. |
I'd add the Integer code only if you can produce a test case that fails
without it.
…On Mon, Sep 12, 2022 at 8:10 AM Carlos Eduardo ***@***.***> wrote:
I ran some tests with several different variable types and everything
seems to work
Yesterday I make a conditional to check if the type will be long or Long
to avoid some kind of error when using int.
The type int and Integer have the same error, but I just fixed it for Long,
do you think it would be interesting to do the same for type int?
would be something like this
if (value instanceof BigInteger) {
if (prop.field.getType().equals(Long.TYPE) || prop.field.getType().equals(Long.class)) {
value = ((BigInteger) value).longValue();
} else if (prop.field.getType().equals(Integer.TYPE) || prop.field.getType().equals(Integer.class)) {
value = ((BigInteger) value).intValue();
}
}prop.field.set(pojo, value);
if not needed, in my tests everything worked fine.
—
Reply to this email directly, view it on GitHub
<#79 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAITHKUKFIRUVYEDVP6A2PLV54TTJANCNFSM6AAAAAAQJ7FQQM>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
it returns the exception but int is a bad type to use as a primary key, so I don't think need Integer
|
Where can I get the latest build with this issue fixed? |
@mrmrmystery I just now released 1.0.6 with the fix. It should be up on Maven Central shortly. Sometimes it takes them a while. |
Hello, I discovered the repository yesterday, but when I went to use it following the Readme I came across an error when generating a table with the @id with type long, after the generated table the RETURN_GENERATED_KEYS brings an object of type BigInteger and this triggers an exception
Could not write value into pojo. Property: id method: public void com.dieselpoint.norm.main.Pessoa.setId(long) value: 1 value class: class java.math.BigInteger
using both the method
getId()
and leaving the attribute publicpublic long id;
this was my code that I used to test which triggered the error
I also tried leaving the type
public BigInteger id;
but i also have another exceptionjava.sql.SQLSyntaxErrorException: Incorrect column specifier for column 'id'
I'm not sure if this is the best way to fix the problem, like I said, I met the project yesterday, so that's the way I thought, I'm still studying this repository better.