last day (15 days later) » 

8:59 PM
0
A: How to combine 3 rows into one object (1 row) in java / spring boot?

user27158This answer is based off of what I remember of comments on your previous post so I hope it is correct, it very much based off of the assumption that all three objects are identical except for the wage types. Please let me know if I am wrong. You had a method that did this; public List<AutoC...

 
these goes inside Repository class?
 
I don't remember which class that was from. You'd have to link to your git hub again
 
it should be in AutoCompleteService, right?
and when you said rateType do I need to create a local variable in my AutoComplete class? it wont find rateType
 
Ah yes, I was thinking about the method in AutoCompleteService. As for the variable names I'm not really sure, I was guessing what they might be called but looking over the AutoComplete class I can't see anything that matches up to your schema. Are they perhaps the 'Range', 'Flat Rate' and 'Per Event' from AutoCompleteSerializer?
 
yes. the range part is just get the data columns for rate_type.
 
8:59 PM
Sorry, I misread your last comment. The AutoComplete class already has a public variable 'rateType', can you not access that directly? I was assuming you can because it is used in AutoCompleteSerializer jgen.writeObjectField(value.rateType, flatJobs);
 
ok. But, how can I access the rateType? That means your answer needs to be change?
 
hello
 
hi
 
So the idea I was going for is mainly based of of the code in the serializer class. It already switches between the three rates (as far as I can tell) so you should be able to use that same style in the retrieveSalary() method?
 
ok. So, it wont fine rateType inside my retrieveSalary method
find*
give me a second.
 
9:05 PM
I might be missing something here, but why is that? findByJobClassCdStartsWith() returns a complete object so shouldn't that field be filled out?
 
it what class?
 
In the AutoCompleteService.retrieveSalary()
 
this line says: ` else if (item.rateType("yearly"))`` method call expected?
let me check
 
damn, sorry I should have saved this until the morning. You're right that should have been a variable not a method call
if(item.rateType.equals("yearly"))
 
should I comment my ` public Stream<AutoComplete> retrieveAllSalaries`?
it also says missing return statment
 
9:10 PM
Honestly I ignored that method because I couldn't see anywhere it was used. Is it necessary to you? Otherwise I would probably only keep the code you need
 
ok.
does this look good too you?
 
I see why ti says that though. In the class AutoCompleteRepository, you haven't returned anything yet. You could possibly apply the same fix there if you're confident about what objects are stored
 
public List<AutoComplete> retrieveSalary(String jobClassCd) {
List<AutoComplete> salaries = autocompleteRepository.findByJobClassCdStartsWith(jobClassCd);
if (salaries.size() <= 0) {
throw new AutoCompleteNotFoundException(jobClassCd);
}

AutoComplete combined = new AutoComplete();

for (AutoComplete item : salaries) {
if (item.rateType.equals("hourly")) {
combined.hourly = item.hourly;
}
if (item.rateType.equals("weekly")) {
combined.weekly = item.weekly;
}
if (item.rateType.equals("yearly")) {
 
I believe so
 
it needs a return statement?
give me a sec
sorry
 
9:12 PM
Sorry, yes return the combined object
 
return salaries, right?
or return combined?
 
You may also want to add some checks in there to make sure that no more than 3 objects are returned from the findByJobClassCdStartsWith() method
return combined;
which would mean changing the method return type from 'List<AutoComplete>' to 'AutoComplete'
 
let me run it
i get an error: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet
its because I dont have a column name "hourly", etc.. it is a row for my rate_type column
ORA-00904: "AUTOCOMPLE0_"."HOURLY": invalid identifier
it autocomplete I have. public String hourly;
public String weekly;
public String yearly;
 
sorry, do you mind showing you original results again? I'm not sure how it matched up to your atuocomplete class
 
my schema?
give me a second maybe I wrote the local variables wrong
 
9:20 PM
No, in previous posts you showed the outputs of your queries didn't you?
 
repository?
class
@Query("select e from AutoComplete e where e.jobClassCd like %:jobClassCd%")
 
No, I mean I can see in the edit history of one your previous post you had a section titled 'My result as of now'. Could you post the full output of your query like you did then?
 
[
{

"Annual": [
" $100,000.00",
null,
null,
null,
null,
null
]
},
{

"Biweekly": [
" $1,000.00",
null,
null,
null,
null,
null
]
},
{

"Hourly": [
" $10.00",
null,
null,
null,
null,
null
]
}
]
 
Okay thanks. I can't actually see anything titled 'Biweekly'. Are you able to point me in the right direction for where that came from?
 
well its weekly
and it is coming from my row under rate_type column
 
9:25 PM
I mean, that's the output from your actual result though right? That must have been written somewhere
 
yes
what can I share with you?
it says "AUTOCOMPLE0_"."HOURLY": invalid identifier
is it maybe my local variable?
 
The flatRate is just a String in your AutoComplete class, so I'm trying to work out where the list of String for the values come from. Sorry I mainly work with Java rather than Spring so it may be that I've overlooked something
 
Ok. I will wait for your answer. thanks so far for your effort.
Do i need to share any more code?
 
By any chance, is the result you are showing only generated when the value.sectionToDisplay is 'range'? Or do you get this every time?
i.e for Flat Rate as well?
 
when the value.sectionToDisplay is range, when I put put a jobClassCd it will go through that switch statement to see if the jobClassCd contains - range, flat_rate, etc...
flat_rate is fine. I need the range part
 
9:35 PM
Sorry what I'm trying to ask is if '' $100,000.00" is step1?
 
yes
 
okay. I massively missed something then. My code was only going to work in the case that the valueToDisplay was 'range. It completely ignores the other two cases. Sorry Mike I think we're going down the wrong route here
I'm going to have to leave it here. I need to be going and I'm not likely to continue on this for a while
I really would recommend leaving up your old posts though, it will help people trying to answer a lot
 
when will you be working on it?
its ok for two cases
 
Sorry, I won't be able to. Your best of posting this again tomorrow to look for more help. I can't guarantee any time on this
 
to be ignore though
your code is correct
it just it gets
"AUTOCOMPLE0_"."HOURLY": invalid identifier
 
9:39 PM
It's missing a lot of cases. It was making too many assumptions, even if we get rid of the error messages there are going to be a lot of times when it fails
 
as long it these part works I am fine
 
ok then
 
so, how can we fix these?
 
where is the invalid identifier error coming from? Compiler or runtime?
 
runtime
when its deployed and I test it.
 
9:51 PM
Sorry Mike. I'm going to leave it here, it's going to take a lot more time and effort than I had hoped. I'm not sure how to continue from here any more
I hope someone else can help you out though
 
thanks
 

last day (15 days later) »