Open Celebes opened 6 years ago
First, good point on item #1. In fact, that wasn't originally required (earlier versions of the code worked fine without it, but something changed...I don't recall what...and now that is necessary. I added it post-production on the book and thus mention of it didn't make it into the book. I'll see to it that the errata list is updated to mention it, though.
On point #2, I just ran through the code for ch03/tacos-jdbc, as it appears in the master branch of this repository. The only change I made was to add some logging to the saveTacoInfo()
method to log the ID. Other than that, I was able to create multiple tacos with no issue (and without having to call setReturnGeneratedKeys(true)
).
I'm not saying that calling setReturnGeneratedKeys()
isn't a good idea. Maybe it is. But I'm curious as to why it works fine for me without it, but not so much for you until you add it. I wonder what's different.
Hi, can you please let us know when the errata is updated? I'm curious to find out what changed. Thanks very much.
- In chapter 3 there isn't a mention about adding "IngredientByIdConverter" - without it the app crashes after saving taco design.
- The code in JdbcTacoRepository.saveTacoInfo() often results in NullPointerException. The solution is to set flag "setReturnGeneratedKeys(true)" on PreparedStatementCreatorFactory object:
PreparedStatementCreatorFactory pscf = new PreparedStatementCreatorFactory(QUERY_SAVE_TACO, Types.VARCHAR, Types.TIMESTAMP); pscf.setReturnGeneratedKeys(true); PreparedStatementCreator psc = pscf.newPreparedStatementCreator(Arrays.asList(taco.getName(), new Timestamp(taco.getCreatedAt().getTime())));
Reproed No.2 and fixed by calling the same method.
Thanks for your solution! @Celebes
OMG Thank you so much @Celebes !!! It was driving me crazy!
I am also facign #1 issue. So where and do I need to add IngredientByIdConverter?
Got the answer.
But now I face another issue. Whenever I save Taco, the Order object is always a new one with previous tacos not part of it.
You should add the IngredientByIdConverter inside the "Tacos" package. Look for it in the GitHub project. Once you do that the conversion cab be made and everything works!
On Sun, Jun 9, 2019, 06:07 mghildiy notifications@github.com wrote:
Got the answer.
But now I face another issue. Whenever I save Taco, the Order object is always a new one with previous tacos not part of it.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/habuma/spring-in-action-5-samples/issues/25?email_source=notifications&email_token=AGBBPJYE54BQ7OK7C7SKRMTPZR6XHA5CNFSM4GBTIA6KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODXIDCZI#issuecomment-500183397, or mute the thread https://github.com/notifications/unsubscribe-auth/AGBBPJ66B77HA7V4BBAGOS3PZR6XHANCNFSM4GBTIA6A .
I just ran into this issue, thanks very much!
Even I wonder about this issue. I cloned the project from Craig's repository and let the test cases run with mvn and Intellij community IDE. The result was perfect - all test cases are passing. So I copied the folder src and the pom.xml into my projects but the result depends where the code is running. If running with maven all test cases passes. Running inside the IDE all test cases of DesignAndOrderTacosBrowserTest are failing with the NPE. :-(
Can someone explain to me why we have created the class Integrientbyidconverter, but do not use its method anywhere?
@Alexandr-Gubkin You can try that: delete the @Component
annotation from IngredientByIdConverter
and run DesignTacoControllerTest
. There's a validation error (it cannot convert a String to an Ingredient):
2020-10-08 09:02:27.794 ERROR 16396 --- [ main] tacos.web.DesignTacoController : Validation error: Field error in object 'taco' on field 'ingredients': rejected value [FLTO,GRBF,CHED]; codes [typeMismatch.taco.ingredients,typeMismatch.ingredients,typeMismatch.java.util.List,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [taco.ingredients,ingredients]; arguments []; default message [ingredients]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.List' for property 'ingredients'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'java.lang.String' to required type 'tacos.Ingredient' for property 'ingredients[0]': no matching editors or conversion strategy found]
@Alexandr-Gubkin You can try that: delete the
@Component
annotation fromIngredientByIdConverter
and runDesignTacoControllerTest
. There's a validation error (it cannot convert a String to an Ingredient):2020-10-08 09:02:27.794 ERROR 16396 --- [ main] tacos.web.DesignTacoController : Validation error: Field error in object 'taco' on field 'ingredients': rejected value [FLTO,GRBF,CHED]; codes [typeMismatch.taco.ingredients,typeMismatch.ingredients,typeMismatch.java.util.List,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [taco.ingredients,ingredients]; arguments []; default message [ingredients]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.List' for property 'ingredients'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'java.lang.String' to required type 'tacos.Ingredient' for property 'ingredients[0]': no matching editors or conversion strategy found]
okay, it doesnt work without IngredientByIdConverter =) But I wanted to understand where in General it is used in this application? Which entity uses it ? I can't see the convert method being applied...
@Alexandr-Gubkin You can try that: delete the
@Component
annotation fromIngredientByIdConverter
and runDesignTacoControllerTest
. There's a validation error (it cannot convert a String to an Ingredient):2020-10-08 09:02:27.794 ERROR 16396 --- [ main] tacos.web.DesignTacoController : Validation error: Field error in object 'taco' on field 'ingredients': rejected value [FLTO,GRBF,CHED]; codes [typeMismatch.taco.ingredients,typeMismatch.ingredients,typeMismatch.java.util.List,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [taco.ingredients,ingredients]; arguments []; default message [ingredients]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.List' for property 'ingredients'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'java.lang.String' to required type 'tacos.Ingredient' for property 'ingredients[0]': no matching editors or conversion strategy found]
okay, it doesnt work without IngredientByIdConverter =) But I wanted to understand where in General it is used in this application? Which entity uses it ? I can't see the convert method being applied...
Did you find an answer ? i have the same question, it's maybe a thing with thymleaf and spring, but i don't know what it is.
@Alexandr-Gubkin You can try that: delete the
@Component
annotation fromIngredientByIdConverter
and runDesignTacoControllerTest
. There's a validation error (it cannot convert a String to an Ingredient):2020-10-08 09:02:27.794 ERROR 16396 --- [ main] tacos.web.DesignTacoController : Validation error: Field error in object 'taco' on field 'ingredients': rejected value [FLTO,GRBF,CHED]; codes [typeMismatch.taco.ingredients,typeMismatch.ingredients,typeMismatch.java.util.List,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [taco.ingredients,ingredients]; arguments []; default message [ingredients]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.List' for property 'ingredients'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'java.lang.String' to required type 'tacos.Ingredient' for property 'ingredients[0]': no matching editors or conversion strategy found]
okay, it doesnt work without IngredientByIdConverter =) But I wanted to understand where in General it is used in this application? Which entity uses it ? I can't see the convert method being applied...
Did you find an answer ? i have the same question, it's maybe a thing with thymleaf and spring, but i don't know what it is.
i think we need it to tell spring that how convert String to ingredient why ? cuz we will get String ( ingredient id) from design.html and Spring don't know how convert it to Ingredient and create out taco object
1) In chapter 3 there isn't a mention about adding "IngredientByIdConverter" - without it the app crashes after saving taco design.
2) The code in JdbcTacoRepository.saveTacoInfo() often results in NullPointerException. The solution is to set flag "setReturnGeneratedKeys(true)" on PreparedStatementCreatorFactory object: