This week's book giveaway is in the Artificial Intelligence and Machine Learning forum.
We're giving away four copies of Succeeding with AI and have Veljko Krunic on-line!
See this thread for details.
Win a copy of Succeeding with AI this week in the Artificial Intelligence and Machine Learning forum!

Mike Gosling

Ranch Hand
+ Follow
since May 19, 2016
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Mike Gosling

Thank you Tim once again. I'll get my hands on some quality book on Spring and Hibernate, so I can learn all that sh** Tnx
Yes Tim, you are right. But I cannot make your idea work.

In my repository if I do like this (what you suggested):

I get error 500, saying:

If I ommit nativeQuery = true:

I get

Now, I don't see a way how to get around this, and to get Entity directly as a record? I'll be sending these as JSON to andorid and will have to eventually create Folder object there anyway...

Wooo, my 100th post LOL Thank you Code Ranch very much, planning on at least couple of hundred posts more
I got what I need, that is, name of the folder and its Id. I did it with following query:

   @Query(value = "Select folder_id, name, parent From folders f Where f.parent = ?1", nativeQuery = true)

If I were to left out nativeQuery = true, I got:

Caused by: java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: folders is not mapped [Select folder_id, name, parent From folders f Where f.parent = ?1]

Thanks Tim, I'll look it up. For now, I was I able to get what I need in MySQL Workbench. But there is no way to tell that to Hibernate.

I have these query I it gets me what I need:

But when I type this:

in Hibernate, I get error saying:

In model I just placed Lazy instead of Eager and set @JsonIgnore on parent.

To be honest, I still haven't looked up about native queries yet, I think I saw it somewhere in TA's project and I just copy-paste it..Not very nice of me
Tried with Lazy fetch, no luck. I'm new to Hibernate and ORMs. Getting error that query is not well formed.

I have a Folder entity in Hibernate, like so:

I'm trying to write a finder method or custom query which will do what I wrote in the subject.

So if I send a request going like folders/{parent_folder_id}, let's say value being 1, I should get objects 4 and 5, but without their children, so not including 6,7,8 and 9.

Ideally, hibernate query would be preferred. If not, any sql language is also fine. I'll try to tumble it up to hibernate.

This is what I got, I still get children...

Stephan van Hulst wrote:Sorry, I missed your reply. Did you manage to make progress in the meantime?

No problem Stephan, thank you very much for keeping an interest. Actually I did make progress, I'll post thorough answer (more like a tutorial of steps) here, as soon as I find some time. They are killing us at university
3 weeks ago
First of all, thank you everyone for finding spare time to post your answers And thank you Stephan for detailed answer/tutorial (finally to see what Spring Security offers out of the box)!

Tim Holloway wrote:You basically just have to set all of the properties with values appropriate to the mailserver that you will be sending through. Same as with gmail, but each of those services has their own host address, port, security prototocols and connection credentials.

Yes, this sounds reasonable. So for each User, which has different mail service provider, different credentials. For now at least, I would like for Gmail users only to enable sending/receiving email without them having to to check "Enable less secure apps". For other ones I'll see later what to do.

Stephan van Hulst wrote:Mike is supposed to use Retrofit2 to send REST requests from Android to the Spring service, and the Spring service uses OAuth to access Gmail.


However I'm kind confused about direction I should go. For now (before I move all the UI to Android), my goal is to send/receive emails using JavaMail API, by using OAuth (in order to avoid to check "Enable less secure apps"), which JavaMail API already supports, (as per Tim Holloway's previous post). Please correct me if I'm wrong.

By following JavaMail's OAuth support instructions, there are few steps I took, to obtain access token:

1. Went to Google Developers Console
-Made some app (marked as "Other") and got Client_ID and Client_Secrete

2. Run python script. program to generate a Refresh Token, from which you I generated an Access Token. Essentially, result I got looked something like this:

Now, since I need that JavaMail library to work somehow, I followed this tutorial. I adjusted the code so in my app it looks like this:

Of course, JavaMailAuthenticationException hit me like a rock. What I'm I doing wrong here? Do I have to use Spring Boot's OAuth classes and methods in order to make this work or I only need access_token?
And, that token is valid for one hour, how to do use refresh token to get new access_token during runtime?

Once again thank you all for your patience and time to read and hopefully answer on these posts
3 weeks ago
Thank you all for taking your time to post your answers.

Bob Winter wrote:From as far as I know and understand ...

This all is very vague for me since I'm beginner in Spring Boot and building web-apps in general. I'll try to use this, along with Stephan van Hulst's comments, in the future.

Tim Holloway wrote:However, on an Android app, you probably shouldn't be sending email directly, but rather contacting the email/gmail intent.

Since this is a sophomore student project, we cannot just contact gmail intent, tho, it would be much easier xD

Stephan van Hulst wrote:Yes, using OAuth should allow access to your mail server without having to "Allow less secure app access".

As I said that I'm new to building back-end web apps, can you maybe recommend some resource (tutorial, blog etc) on how to actually implement OAuth? By your comments, you seem to have an in-depth knowledge

Tim Moores wrote:If for some reason no user interaction is desired, have the app contact a REST service on your server with the relevant details, and then the server can send out mails.

You are correct Tim! We are supposed to send http request (using retorfit2) from mobile app to our back-end and then JavaMail library (along with appropriate mail server configuration parameters) will actually send email.

I do have one question if you guys can help I would be very grateful. Question is a bit off topic. Okey, I managed to send an email for someone who is using gmail, but what if a User have Account for lets say yahoo or hotmail or university mail. How to set (programmatically) mail server configuration parameters for each of this mail service, how do they differ? For Google, I found necessary Bellow is part of our UML, which we need to follow up.

4 weeks ago
I'm trying to build Email messaging app in Spring Boot with Android app as client. Since for every Account it is required to have mail server configuration parameters, like so:

I still have to "Allow less secure app access" from my Google Account. Now, is there any way to get around this? When some User try to send his email, that he doesn't need to enable this button. And is it true that if OAuth is implemented during login, that my app will be considered "secure enough" so the User doesn't have to click that "Enable" button?
4 weeks ago
Hi all,

I would like some clarification about JavaMali API and dependency in Spring Boot.

Story goes like this, our professor gave us a project to build an email messaging system, where the client would be Android app (which will communicate with back-end using Retrofit2 library) and back-end will be in Spring Boot with Hibernate. Here is the small part of UML, just to give you a better understanding about idea.

Also professor told us to use I just downloaded the, I'm not sure if it is going to be useful in order to be able to use classes, interfaces and functionalities. Now, what I don't understand is, whether the JavaMali API is just jar/dependency with concrete classes to be used or Spring Boot's spring-boot-starter-mail provides us with implementation with JavaMali API? If I can make an analogy with JPA and Hibernate, JPA is a standard and Hibernateis just implementation of that standard? In simple words, if I add mentioned dependency, am I good to go?

One more thing, I really have no idea what are these five fields means: smtpAddress smtpPort inServerType inServerAddress inServerPort. I looked couple of YT tutorials but they only set (in values for smtpPort and smtpAddress, like they are hard-coded. For example, in one of tutorials in, there is following code:

What if I want to register new User with yahoo email, or some other email, or to create new email, how to set above mentioned fields?  

How to (or should I) make them individual for each user? And in which way they interact with other fields?

P.S. I get that these are all questions for professor or TA's, but trust me they are as****s, and they will just tell you: manage it yourself...So I sincerely hope that here there are good people willing to at least give some foundation on top of which to build up. Thank you.  
4 weeks ago
Hi Randy,

Here is link to GitHub project.
1 month ago
Hi all,

I really hope anyone can help me. I'm busting my head for daaays.

I have a simple MainActivity, with activity_main.xml, which has a DrawerLayout (which shows nicely) and FrameLayout (which is intended for Fragment). Both DrawerLayout and FrameLayout are childrens of simple LinearLayout.

Now, once I start my simple app from phone/emulator, weird thing happen. First, activity appears (as expected) and then Fragment appears but with small delay. So I have to press back button two times in order to get out of the app, even tho I explicitly said to FragmentManager no to put Fragement on the back stack.

My main goal for this demo exercise is to show Fragement (which has couple of Cinema objects through RecyclerView) from within activity. Key idea is to use that FrameLayout (fragment_container) and through it to display fragment's view. (I don't know if this is possible or maybe this is the place where mistake is hidding) And I want Drawer to be present, but froM Activity. Like I said, I did succeed to display, through RecyclerView, those Cinema object (stored in some Singleton helper class). Now, I have to press two times Back to get out of the app, don't want that.

Here is code.

FragmentTransition class (I could have posted right there in MainActivity, but our TA told us to do it this way)

XML for MainActivity

Here is the Fragment from the beginning of the post, I called it CinemaListFragment

And finally code for simple RecyclerView for this Fragement (fragement_cinema_list):

I apologize for this long code post. If necessary, I could send zip of the project. It is not big, simple student exercise.

Lets go Ranchers
1 month ago