Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!

Al Hobbs

Ranch Hand
+ Follow
since Aug 30, 2017
Al likes ...
Netbeans IDE
Cows and Likes
Cows
Total received
1
In last 30 days
0
Total given
0
Likes
Total received
3
Received in last 30 days
1
Total given
4
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Al Hobbs

Thanks for your reply!

I figured out the problem.   So the problem was with my janky setup with the roles in the user class.

I fixed it by properly writing the relationship with roles with @ManyToMany:





This got rid of that problem.

With that I got another problem. The controller returned the user object, but because the user object and the token reference each other, when it was being converted to JSON it was entering a recursive loop.

I added @JsonIgnore to the user object in token.  I haven't tested it out, but it should work.


thank you again!!!
2 days ago
I forgot to add a part of the user class.  The user class also has a list of roles:


I looked at the debugger and the roles list is a persistent bag, but it isn't null.  I think the problem has to do with the roles.

The role class isn't mapped back to the user because I haven't figured out that out yet.
2 days ago
Hi all,

My problem is happening when I update an entity.   It was working perfectly fine but then it broke and I can't seem to find why it's happening.  Maybe somebody can provide some insight on hibernate's merge. 

The exception I'm getting is:


That's not all but it seems to be the most relevant.
I have a user class with a verification token:


and then I have the token class with the user tied back:


I got the setup straight from the docs, and it did work at one point so I don't think the problem is in there.


The logic I have is this:


Everything is fine and dandy until it saves the user again with the token added.   I debugged it and everything works perfectly fine until that point. The user is saved, and then token is created from that user and then the token is added to the user.  When saving, hibernate merges it because it has the same ID, but for some reason there's a null causing a problem in there.  I have no idea what kind of null it's talking about.
When the user is first saved, the token is null.  Is that where the null is coming from?

Any guidance would be appreciated.


2 days ago

sinatra roger wrote:
I was analyzing these requests at the same time and sent him my analysis of the changes that would be required which was accepted and that was my second assignment.


Well, this seems to be a way for you to get work, so just keep doing that.
2 weeks ago

sinatra roger wrote:
What should I do? As I said, the pay is good and I would be dumb to find a new job due to lack of "work pressure".



I would suggest utilizing the time you have from lack of work to study.  The training you are supposed to receive isn't there so just train yourself.  You said the pay is good, so the only problem from not having work to do is your skill isn't improving.  You've obviously put in the effort letting them know you don't have work, so as long as you keep reminding whoever it is that assigns you work that you don't have any work, then you should be fine.

The real situation might be that you were originally brought in to eventually take over for the architect because his salary might be high, and he was supposed to train you so they could eventually get rid of him.   The architect knows this and is preventing that by not really training you.  The manager doesn't want to push him to hard because he thinks that he can't lose him at any cost.  Maybe I'm totally wrong, but it makes for a juicy office drama.

2 weeks ago

Jan de Boer wrote:In my year review my manager said she said she thought I was not motivated because I did not smile at the office.



Unless you feel like she is going to fire you because you don't smile, then just say you'll try your best and then leave it at that.  If you are really bothered by her asking you to pretend to be happy, then I don't necessarily think changing jobs would be a long term solution.  She seems like she should mind her own business with the smiling thing though.  Your job doesn't you require to serve people, so I would just ignore her and focus on what's important. 
2 weeks ago
Hi,

My question is more of a design question, but it's related to webservices, and I want to be in the drawing for the promoted book .  I'm not really sure the requirements to be entered.
I asked a question on stack overflow here:https://stackoverflow.com/questions/50226317/how-can-i-implement-the-search-for-a-location

I'm making an android widget and it uses data from a rest endpoint.  The data changes based on location, so the user will be able to enter the location or locations they want.  My problem is that I want the user to be able to search for their location like in the weather widget.

How can I best have the information of the rest endpoint variables stored for searching in the app?  Obviously persistence is overkill, and using a text file might not be efficient.  What is a good approach to my problem?


Thank you!!!
2 weeks ago

Junilu Lacar wrote:It looks like you have misapplied the idea of lazy initialization, which is to defer performing costly operations until the time you actually need to do it, so you only incur the cost at that time


Thanks for your reply.  I think i have a better understanding of lazy initialization now.
Well since you put it that way it doesnt really seem like lazy initialization fits in my situation.  the url is only visited once because the html document is stored in the book.class instance and then extra information is gotten from there.  
When i think about the analogy you gave what i am doing is getting the groceries but im not putting them in the fridge until i need them.  
Do you think taking the html doc scraping code out of the book.class is a good idea? I started making a class that would have a method to create a book instance using a html doc for a parameter and then another method that would take a book as a parameter and scrap the rest of the information using the html doc stored in the book instance.
Even though the book building class is stateless id want to be able to make a interface or extend the book builder for scraping on a different website.
1 month ago
After some thought I decided that I shouldn't even make a static utility class because the code now is coupled to a specific website.  If I wanted to make books using a different website I would have to rewrite the code yet again.  In order to be able to make polymorphic methods in that situation, I thought it would be better to make an class that is solely responsible for creating books and filling in the details.  For lazy instantiation I thought I would just call a method that would fill in the information before it is written to the excel file. 

Does it sound like that makes sense?  Should I just leave the datascraping code in the book.class?

Thanks!
1 month ago
Maybe my real question, is if I should just fill the book out initially because it is just scraping info from the Jsoup.Document object which is made anyways to get the isbn.
1 month ago
An example of what I would be doing is:


Right now how it's designed I would make a call from the getter methods in the Book.class to the fillOutBook() method if the attribute hasn't been added.

What other kinds of way could I do this 'lazy initialization' without coupling the utility class with the book class.
1 month ago
used to check it.  Only if the book has an oclc number and is not in website2 do I want the program to fill out the rest of the information, because it is searching through at least 2000 books.  Once I have the book, it is written to an excel and not persisted.

What I want to do is take the data scraping code out of the Book.class and put it into a static utility function. The problem is I only want the book information to be filled out once it is needed before it's written to the excel or once it is known it will be written to the excel.  Right now the code to fill it out is in the getter methods.
1 month ago
Sorry if my post was unclear. 
The book class is filled with information scraped from a website, website1.  There's a tool in my program that will check if the book has an oclc number and is not in the database of website2.
  During the checking process only the isbn number is
1 month ago
Hi all,

I have a Book class that I made a few months ago when I first start learning oop.  The book has a lot of code for initializing it that I realize now should be in maybe a static utility class.  The details come from a website, and I have it so that the details are filled in as needed because there are times when I just need the isbn to check if it's in a certain database.  If it is in the database then it probably won't be used, so there's no point in getting all the details because there are quite a few.
The problem I have is that I want to decouple the code to get the details of the book from the book, but how could I go about having a lazy initialization style?  Should I just put calls to the static utility class methods in the Book class?  I thought that wouldn't be good because the it would still be coupled, but maybe I am overthinking it?

thanks!!


  It shouldn't be that hard to rewrite the program because I can just add another method call to when the book instances are made. 
Any ideas would be appreciated!
Thanks!
1 month ago
Hi all,

I got basic authentication to work with  userdetails, and userdetailsservice,
but my ultimate goal was to set up oauth2.
When I try to access my rest api with post man I get this response.
]

My server debug:



It looks like it's trying to do basic authentication for the client id that I put in the request.
I know the PasswordEncoder problem has to do with a wrong password format
but while I was debugging it never used my userdetailsservice so it wasn't even looking at the database.

my configs:




The client name is my-client-with-secret, so the matching secret is "secret."
I ran a spring demo app with a similar request and it worked fine with even less configuration.
What could be the problem?

Thanks!
2 months ago