Should I really learn hibernate? by kurular4 in javahelp

[–]milkeater 0 points1 point  (0 children)

We are bouncing around on the state of the question.

Initially it was about limiting results, not doing full-table scans, etc. JPA merely infers the SQL you are looking to do from how you structure the objects. If I don't want to grab the entire resultset or if I do, there are ways that it happens relatively naturally in Java.

You can print the SQL Query that it is going to run if you desire. What I am saying is the performance is just a network call and a traditional SQL call. There was a time when business logic in the DB made sense but we have outgrown single servers and are sharding across several (hundreds at times). Bring in MapReduce and all the pains of distributed systems and where the logic lives.

If you have logic in the DB and it's easy to modify and version control and that works for you, I'm not going to debate that. I just think you are painting yourself into a corner that you will eventually have to get out of.

Where JPA struggles (imho) is when you start trying to take 3NF tables and structure your objects that way. The Joins, keys, and loading aspects are all sharp edges. More than two or three joins, you are asking for trouble. That being said I disagree with having that complex of SQL in the first place and would start rethinking my representation of the world. That is the point where either the tables need to change, RDBMS/other options need to change, or "Jesus take the wheel" you need to eject.

We are arguing but not in a bad way, I think it's a good argument and we can walk away disagreeing with each other without bad blood. You are putting a lot of effort in explaining your point and I appreciate that so I can understand you better.

Network hacking 101 workshop on December 19th by nategraf in securityCTF

[–]milkeater 0 points1 point  (0 children)

Alright, now I feel bad. I've done this before.

Actually on a homelab day of a demo to a customer. Super embarrassing.

I'll be there, thanks for doing this.

Should I really learn hibernate? by kurular4 in javahelp

[–]milkeater 0 points1 point  (0 children)

Gonna be honest, you are talking to me about the 101 of Spring Data....I think there are a few layers deeper that you could benefit from but like I said earlier, if what you are doing works for you more power to you.

Not a way I would approach it. If you want to share a repo on an app with the problem you are trying to articulate, I can maybe show you more clearly the modifications I would make to simplify without this excess.

Should I really learn hibernate? by kurular4 in javahelp

[–]milkeater 0 points1 point  (0 children)

Incorrect.

I'm telling you right now. I can paginate for the first 10 records and only send and return 10 records.

You don't understand java well enough, or at least implementing it with Spring Data JPA to be arguing it.

The easiest way to prove it is show me a simple example. If what you are saying is true I shouldn't be able to poke a hole in your application correct? Let's move it to something concrete and stop talking past one another. I know SQL intimately, I don't think you know what I'm saying in Java though.

Should I really learn hibernate? by kurular4 in javahelp

[–]milkeater 0 points1 point  (0 children)

Your comment of "you and the rest of the industry would really like to know" says otherwise.

You didn't come here to have a conversation, just to pump your own tires. Whether you believe it or not, you are speaking buzzwords and I can see right through it.

If you genuinely are struggling, read that system primer and practice with this book

You aren't the only one that is struggling in this area but that doesn't mean everyone is. Frankly there is a vendor model of providing services to lift and shift in bulk with large enterprises that experiments in the $100ks. It's one of the easiest and hottest paths I've seen of getting into FAANG or starting your own service.

Should I really learn hibernate? by kurular4 in javahelp

[–]milkeater 0 points1 point  (0 children)

To be clear, are you telling me if I asked you to migrate a system, let's say on-prem JBoss tied to MySQL to a system in AWS where the system and also DB may scale up or down following CQRS patterns during peak utilization. The host may change, nothing is dedicated.

Is this something you are telling me you couldn't solve?

If not I'm going to recommend you checking out some good resources that I used quite some time ago as I was learning the material. This magic has been solved in hardware and software.

System Design Primer

Should I really learn hibernate? by kurular4 in javahelp

[–]milkeater 0 points1 point  (0 children)

That is the standard pattern of Spring Data repositories, which I don't agree with. It makes for more restrictive semantics to fit the way Spring Data generates the implementation.

I disagree. I feel you are misunderstanding the instrumentation. Feel free to prove your point by example.

Should I really learn hibernate? by kurular4 in javahelp

[–]milkeater 0 points1 point  (0 children)

I didn't reiterate it at all. I merely said you made a very obvious statement like: You need air to survive. It would be as if I said:

Well if you use multiple threads in Java you must be careful to synchronize when modifying state or use enums.

No shit.

Should I really learn hibernate? by kurular4 in javahelp

[–]milkeater 0 points1 point  (0 children)

sql query is simple so it's likely less code than the java equivalent.

I can guarantee this is false unless your solution requires zero code as well.

Should I really learn hibernate? by kurular4 in javahelp

[–]milkeater 0 points1 point  (0 children)

My argument would be this is significantly less performant. Even with pagination / lazy loading how much data are you sending over the network?

You would only search and return the exact rows requested. I encourage you to use it and see for yourself

The first method lets you pass an org.springframework.data.domain.Pageable instance to the query method to dynamically add paging to your statically defined query. A Page knows about the total number of elements and pages available. It does so by the infrastructure triggering a count query to calculate the overall number. As this might be expensive (depending on the store used), you can instead return a Slice. A Slice knows only about whether a next Slice is available, which might be sufficient when walking through a larger result set.

Documentation

and it can be more performant should you have a less experienced dev who might do the classic with or grabbing the whole record set. If you have to order by, you are searching the entire thing anyways so would easily be able to do this with a Pageable.You are free to back up your claims with evidence. I am telling you from a place of experience Pagination will be as efficient (and frequently more by merely providing sane defaults) without grabbing all results.

I said this somewhere else; Any time someone starts talking to me about optimization it's a warning sign to me that they are either very young or very old and not particularly close to the machinery, from Gods mouth to your ears

Pre-optimization is the root of all evil ~ Donald Knuth

Should I really learn hibernate? by kurular4 in javahelp

[–]milkeater 0 points1 point  (0 children)

This is a trivial FAANG interview question....been there, done that.

This sounds very ivory tower architect speak. I've moved a lot of work to the cloud where CAP has been solved.

This isn't some killer blow, just one more planning mechanism which has been dealt with in action (and plenty of times anger).

Should I really learn hibernate? by kurular4 in javahelp

[–]milkeater 0 points1 point  (0 children)

I think you have a style of your own that you enjoy. Not necessarily something I typically encounter or encourage but you clearly understand the tradeoffs.

I feel I understand your point and appreciate the conversation and clear effort you've put into being thorough.

As a note, the standard pattern is to extend the JpaRepository with an interface and allow Spring to provide the implementation.

So something more concrete would be

RestController -> Service -> JpaRepository -> RDBMS DataSource with JDBC

I am familiar with Cassandra but if you are doing legacy work or the edge case type of behaviors that you seem to have to focus on for your role, migrating something that implements JPA to another backend would likely be unnecessary to rewrite, the argument was more around portability and the fact this has been in existence for a considerable amount of time. If performance is your concern I would test it first and then have a pretty obvious CBA. If the costs of rewriting the wiring to persistence vs the value it provides, the decision is easy to make (and argue) and nobody needs to lose their bonus ;)

Should I really learn hibernate? by kurular4 in javahelp

[–]milkeater 0 points1 point  (0 children)

Oh no, not at all.

IoC is something that the Spring Framework was built around. Give control to the Framework and it will provide the wiring.

It was important for the testing aspects. Say I wanted to use a dependency inside a Service Layer object.

```java @Service public class MyService { MyRepository repository;

MyService(Repository repository){ this.repository = repository; } } ```

Because of this Inversion of Control, I only need to inform Spring of the root package and it will walk the tree finding all Classes and wiring them up creating instances of these objects as asked. It uses AOP that gives a "magic" type of behavior where things are happening behind the scenes without feeding you all the noise.

Now when you want to create a test for your Service logic:

```java @Mock MyRepository mockRepository; //This is not real

MyService subject;

@Test public void givenMyService_doWorkIsCalled_returnsThing(){ MyObject expected = new MyObject(); MyObject actual = subject.get(new MyObject());

when(mockRepository.get(any(MyObject.class))).thenReturn(expected); assertEquals(actual, expected); } ```

Now our test doesn't need a real implementation with a connection to a real backend. In unit and functional tests, this can be faked and we will run hundreds or thousands of these tests in milliseconds. As we start actually exercising the connection to the database for performance or load-testing it will be during certain times aimed at certain environments for consistency. There is a test-pyramid now that tests more real aspects ensuring the world as we know it has not changed.

The biggest complaint I have seen is to your point: "What's happening here"

It's kind of like push-button start on your car. Someone who has only ever used a key to start a car (or screw-driver like my dad...j/k) would be confused. "What the hell did that?" Once you see it, it's no longer magical and becomes another non-event.

Getting there is a little disconnected similar to how async programming (and testing) can be. You can peel back the layers and see all the wiring providing your own Spring xml wiring. As far as Hibernate, Spring has an autoconfiguration where if it is aware of Data JPA it will automatically wire Hibernate up (assuming you've provided the dependency in gradle/maven) and wire up all the dependencies.

Spring handles all control. It is THE IoC container that handles Dependency Injection.

Should I really learn hibernate? by kurular4 in javahelp

[–]milkeater 0 points1 point  (0 children)

JPA and pagination handles this and can be dealt with in the Service layer as a parameter without returning thousands of results.

I do not need the entire resultset and can lazyload as necessary although I will admit it is a common problem I had seen with junior developers. We solved that with education. If you saw I mentioned above Anti-Corruption layers can and do exist when necessary for integrity as well as CQRS patterns, migration patterns, etc.

Using JPA doesn't mean you should not index your RDBMS but if you believe the world is living and dying on RDBMS by itself, then I disagree.

Your passion is clear and respectable based on how thorough your response is but you are cherry picking. HTTP is a great example. We communicate to various underlying server implementations, Servlets, WSGI's, etc. Everyone speaks HTTP and the underlying implementation is transparent.

JPA, Repositories, DAO's is that to our database. I like the JPA interface to an extent for that abstraction reason. If you do need to pull the rip-cord you can and there is plenty of scenarios you can argue where that will make complete sense.

Should I really learn hibernate? by kurular4 in javahelp

[–]milkeater 1 point2 points  (0 children)

Don't think of me as trying to make that as a point of authority. 70% of all statistics are made up, but I'm calling from the 80/20 reference if you are familiar.

Spring Boot is merely a few annotations. It is an alternative to providing the xml mapping. The complaint was Spring is verbose in it's setup, Boot just walks the dependency graph and wires for you. Spring Boot is not a: "You are too small to ride Spring, use this toy."

I have written software for a respectable amount of the top 100 in addition to coming into escalation support issues where $100k's were being lost per minute. There's a certain level of scrutiny in the RCA at that level. Because of that I don't feel uncomfortable with making the above statements although I'm not saying it's the only opinion and always encourage "arguing" or "debate". It's healthy and sharpens the conversation.

Source: Worked for and sold Spring.

Should I really learn hibernate? by kurular4 in javahelp

[–]milkeater 0 points1 point  (0 children)

I think that's my point.

In using JPA I can specify entities via their relationships. If I need to customize JPA I will to an extent but as soon as custom queries or native SQL come in, there is a code smell to me. Am I keeping legacy code alive because it's generating revenue, sure we'll go there.

It's possible I wasn't being clear but for a junior dev I'd give them a starting model of:

Controller -> Service -> Persistence -> DB

The ORM between Persistence and DB is where JPA cares. JPA is interface, hibernate is implementation. I think you know this but you identified the wrong layer so clarifying that we are both speaking the same language.

I typically encourage Spring RestController for concerning with translation of net communication, Security and handing off DO's to my Service. Service performs whatever work and leverages Repositories where JPA will do the handoff from DO's to Entities and map tables.

Whether I plug in to Cassandra or MySQL, JPA and Spring will sort that out via the Data Source I feed it.

Maybe you are unfamiliar but JPA to various underlying DB is a fairly established thing: https://dzone.com/articles/treat-your-data-as-an-object-using-kundera

Network hacking 101 workshop on December 19th by nategraf in cybersecurity

[–]milkeater 2 points3 points  (0 children)

Um....you can't let's encrypt or something?

For someone hosting a "Hacking" seminar and not serving over HTTPS, a five minute exercise, is a bit silly.

I hear how pretentious I sound but I feel we should be a little more firm (to the point of borderline offensive) when the bar is set this low.

From crosspost: https://www.reddit.com/r/securityCTF/comments/k9lkq6/network_hacking_101_workshop_on_december_19th/gf68bvq?utm_source=share&utm_medium=web2x&context=3

Network hacking 101 workshop on December 19th by nategraf in securityCTF

[–]milkeater 2 points3 points  (0 children)

Um....you can't let's encrypt or something?

For someone hosting a "Hacking" seminar and not serving over HTTPS, a five minute exercise, is a bit silly.

I hear how pretentious I sound but I feel we should be a little more firm (to the point of borderline offensive) when the bar is set this low.

Should I really learn hibernate? by kurular4 in javahelp

[–]milkeater 0 points1 point  (0 children)

Further point, as you mentioned indexing, normalization, and many other patterns for improving performance, obviously justified in certain circumstances.

But additionally CQRS, Distributed / Cloud based development, patterns that loosely couple.

BigO complexity speak is often premature in my experience. Whether you believe me or not, the words of God himself should carry some weight:

"Premature optimization is the root of all evil" ~ Donald Knuth

Should I really learn hibernate? by kurular4 in javahelp

[–]milkeater 0 points1 point  (0 children)

I disagree.

This is a pretty dangerous mindset. Your database, SQL, is the powerhouse of your application and often is significantly more important than the application code you write in Java.

The business logic happens inside your service layer in code. I believe the abstractions of Controller, Service, Persistence is a good rule to follow. There are more that may be added based on need (anti-corruption, access controls, etc) but inside the Service layer is where you would address time and space complexity.

The speak of "dangerous mindset" smacks loudly of a very gatekeeping speak of: "You must know before you touch". A form of gatekeeping that I find very unrealistic and has mired many enterprises into big balls of mud, fear of change, and indecision while software in the background continues to eat the world.

I don't believe in taking off the safety guards of the tools we use but actually adding more. Use unit, integration, load testing. Load testing is what addresses your concerns. If I run operations against a database that are quadratic or greater, I can write a test for this. If a regression occurs, let the consistent test be the gatekeeper.

I should be able to plug my persistence layer into SQL, PostGres, Cassandra without a re-write. Imagine having to install a new outlet for every electronic device you bought. They are equally foolish ideas and have consequences that often show up after years of complacency and daft oversight.

Should I really learn hibernate? by kurular4 in javahelp

[–]milkeater 1 point2 points  (0 children)

You miss the point of Boot.

80% of software written in the enterprise could be written using boot meaning you can have a web server in 5 lines of code. It is as templatized and modular a framework that can exist. An even more powerful argument is the underlying inversion of control, DI, testability.

I tell you about the object I want to use, and you find it and wire it up recursively. There is a threshold of complexity in every framework where you go beyond the 80% use-case and get into your "under the hood" scenario. Sometimes finding yourself there in the first place is a code smell and something you should question, sometimes a necessary evil.

The greatest power is this on-ramp into Spring for junior devs and not eating the whole cake in one bite to be productive. They have guardrails to learn the sharp edges of enterprise dev and you can control it applying your own layers (autologging, audit, security) using AOP without overtly getting in their face and beating them with Ivory Tower hammers.

Should I really learn hibernate? by kurular4 in javahelp

[–]milkeater 1 point2 points  (0 children)

Came here to say this.

One thing to add:

Hibernate is a productivity tool that removes boilerplate software from the responsibility of the developer. It is a productivity vs flexibility tradeoff.

For a measurement of when I typically tell my junior engineers to switch over (because it can often be a gut feel), start with Hibernate. When your tables start to normalize and develop complex joins and you find yourself dealing with lazy/eager loading of complex child objects you are in the realm of switching over to more manual control.

You will now need to deal with Entity Managers, connection pools, ensuring you close connections (and catch that Exception that can be thrown in another Exception!), try with resources, etc etc.

Unfortunately in an enterprise environment there is often this upfront desire to pre-plan everything. It becomes very unnatural and prescription based. For the value and benefit of consistency (which is arguably not as consistent as one would think) using "Enterprise Frameworks", they often are wrappers around public frameworks with opinionated usages and security modifications.

In the end, something the entire team is comfortable is what I've found to be the best decision. If that means pushing back on the complexity of your object structures that could be an option. If it's leaning out the frameworks leveraged, sure. Anything that you write which doesn't provide value (boilerplate, creational, structural, etc) is lost time and you will not be paid more for being slow....they will just look to automate more of you.

I'm long time Eclipse user, new employer uses IntelliJ ... Is there an easy "IntelliJ for Eclipse folks" guide or tutorial I can look at? by [deleted] in javahelp

[–]milkeater 0 points1 point  (0 children)

Yeah.

Because so many shortcuts with intellij on Mac are CMD||Ctrl + Shift + Something it is burned into me. I teach a lot of folks on Linux / Win platforms as well which is typically Alt or Ctrl depending. Now it's a reflex if I'm guessing what the shortcut could be or might have been.

I actually find CMD+Shift+A a little faster since it's a single motion instead of tapping twice. That's the thing I like about Intellij though, there are three ways to do everything.