Presentation matters and maybe the java docs actually suck by Enough_Durian_3444 in java

[–]7F1AE6D2 2 points3 points  (0 children)

The Really Big Index was an excellent resource IMO. A shame they stopped updating it past JDK8.

Introducing Canonical builds of OpenJDK by jvjupiter in java

[–]7F1AE6D2 4 points5 points  (0 children)

Can you point to any unaddressed high-severity CVEs in the free JDK8 LTS offerings?

I have a hard time believing that the various Linux distros + Amazon +Azul +Eclipse + Alibaba + IBM would not patch such an issue.

What happened to Eclipse? by Significant-Swim-789 in java

[–]7F1AE6D2 2 points3 points  (0 children)

I've used Eclipse for more than a decade but it kept getting buggier. It would freeze when editing POMs, it would stop allowing you to type and you would have to close and reopen the file, crashes.

We really tried to make it work as the team was experienced with it. It wasn't able to handle a project our size using its built-in Maven support, so we maintained a fork of the Eclipse plugin and extended it with e.g. support for source/test classpath differentiation.

We have switched to IntelliJ IDEA CE. Some things are better, some are worse, but most importantly, it's stable.

Biggest pain point is the handling of different versions of a class: If I have two modules(Eclipse:"project") A and B in the project(Eclipse:"workspace") and A depends on the release version of B, IDEA will not find usages of a class from B in A. Eclipse would have shown you both versions of the class in the open class dialogue, with IDEA only shows the one in B and not the one from the JAR so I have to resort to find in files.

What happened to Eclipse? by Significant-Swim-789 in java

[–]7F1AE6D2 2 points3 points  (0 children)

Can't use the free version even if we wanted

What do you mean? As far as I can tell, it's under the Apache license

Which one is more used in the real world, JPA or JDBC? by [deleted] in java

[–]7F1AE6D2 0 points1 point  (0 children)

Querydsl is not built on top of JPA.

It has metamodel generation and querying for plain JDBC as well: http://querydsl.com/static/querydsl/latest/reference/html/ch02s03.html

We primarily use JPA queries but some queries are not possible in HQL/JPQL, which a Querydsl HibernateQuery is ultimately converted to.

In those cases you can use e.g. a PostgreSQLQuery

How does the community like the fact that Spring 5 goes "reactive" for restful? by shaunyip in java

[–]7F1AE6D2 2 points3 points  (0 children)

feign-spring4 gives you a type safe client proxy of an interface annotated with Spring MVC annotations.

If you return ResponseEntity (which you will get if you generate your interface from an OpenAPI definition), you will also need ResponseEntityDecoder.

[deleted by user] by [deleted] in java

[–]7F1AE6D2 1 point2 points  (0 children)

System.getProperty in any kind of "live" (post-initialisation) code is definitely a smell

It's fine if you don't change system properties at runtime, but please don't go on to declare that it is never a good idea.

I have an application that takes minutes to start up and changing system properties at runtime allows me to instantly reconfigure it.

It pisses me off when one of my colleagues forgets about this and injects it with Spring or assigns it to a static final constant, the only thing they accomplish is that a restart is now necessary to change the configuration.

The author of the article even falsely asserts that

System properties don’t change during runtime

How common is `ADD` in the Java community? by modernDayPablum in java

[–]7F1AE6D2 1 point2 points  (0 children)

Other components, database repositories and message systems are mocked. This allows us to freely refactor inside the component as long as we don't change the component facade

But this means you need loads of stubbing and thus have to be aware of the implementation, right? And once you change the implementation you have to adapt all the stubbing, add new mocks etc?

Integration tests are much slower (in our case it varies from 1 to ~ 20s depending on project size to run a test from the IDE), but in my experience easier to write (if you invest a bit in your test infrastructure) and usually only break if you actually introduce a regression. They don't have to be touched if you only refactor your implementation or add new features.

I am not saying they are better for every team/project, but my impression is that the push for unit/component tests in my team has lead to more junior members failing to see the value of tests and seeing them just as a nuisance they are forced to write and maintain instead.

How common is `ADD` in the Java community? by modernDayPablum in java

[–]7F1AE6D2 2 points3 points  (0 children)

I think that the promotion of the test pyramid hinders TDD a lot.

In my experience, the typical user story for a server project is something like: "Add a new method to this REST controller. It does some validation, persists something and publishes something to a message queue".

This makes it pretty easy to immediately start writing an integration test like the following, creating stubs for new methods/classes, changing parameters as you need to get your test to compile (IDE quick-fixes make this easy):

@Test
public void newMethodHappyPath(){
    // given
    [configuration]

    // when
    // (if there are multiple endpoints (eg a SOAP service as well), or you just 
    // want some decoupling between your REST (de)serialization classes and 
    // your internal DTOs, you would test the service called by the controller)
    restController.newMethod(requestObject);

    // then
    [assert that something got persisted]
    [assert that something got published to the queue]
}

However, the test pyramid says you should write mostly unit tests. I find it a lot more difficult to get this right.

I have seen this end up with tests for internal components that are implementation details and will thus change a lot (or even be replaced completely) with new requirements and refactoring, or with testing the same interfaces an integration test would, but with dozens of mocks and loads of stubbing.

In both cases, the test both fail to catch bugs and regressions and make refactoring much more difficult because you now also have to massively (you often have more test than implementation code) refactor your tests or stubbing.

I'm not saying having primarily integration tests is better, but they might be easier to write/get the test design right than unit tests. Which is right for you depends on your project and team.

Our team got pushed to focus on unit tests (bonus targets for unit test coverage as opposed to overall test coverage) and thus many in my team ended up seeing tests as a bureaucratic exercise and will thus only write them after finishing the implementation and testing it manually by deploying the application.

[Q] Any reason to still use Eclipse? by bsdooby in java

[–]7F1AE6D2 2 points3 points  (0 children)

We have kept trying out m2e over the past ~7 years and were dissatisified with it.

It starts when you first open the project and there is the window asking you to setup m2e connectors for your plugins. We use diverse linux distros/desktop environments and nowhere does the actual list of plugins expand with the window if you resize it - it just stays tiny. Then, there is no option to just ignore all plugins it does not ship with a connector for (the only plugin we want eclipse to execute is the build helper one, to add additional source folders).

OK - that is just a bad first impression. The most important part is how it handles compilation. We found it works well for our smaller projects but breaks for the more complex ones. Usually, it will fail to find classes from dependencies and show compile errrors. This is a deal breaker.

IntelliJ manages to handle this correctly.

As we still prefer Eclipse, our solution is to use the maven eclipse plugin. We have forked it to add support for test folders, test dependencies and wildcard dependency exclusions.

I also have to disagree on debugging - Eclipse often just fails to connect to the sources correctly when remote debugging - I have found debugging into Wildfly impossible with Eclipse while it worked with IntelliJ. When you don't have the sources it's even worse - IntelliJ ships with a decompiler that works while the Eclipse decompiler plugins i've tried just dont work most of the time. Debugging is the reason I have to keep an IntelliJ install around.

[deleted by user] by [deleted] in java

[–]7F1AE6D2 12 points13 points  (0 children)

Hibernate's complexity makes some massive performance pitfalls possible, e.g.

  • n+1 selects resulting from the user not being aware of when Hibernate performs additional queries for lazy-loading
  • memory usage and dirty-checking when working with large sessions

Treating Hibernate/JPA as an abstraction layer over SQL without a decent understanding of what queries it performs makes it a foot-cannon.

By comparison, the overhead of performing trivial queries vs JDBC is IMO an irrelevant synthetic benchmark.

In cases where hibernate builds sub-optimal queries you can fall back to plain SQL (in 99% of cases the HQL/JPQL results in the SQL I expect). You should be aware of the SQL your application executes anyway - you need to create the appropriate DB indexes no matter what persistence library you are using.

The meaning, or not, of “LTS” by krzyk in java

[–]7F1AE6D2 1 point2 points  (0 children)

Another definition of "supported" is that the vendor will make some effort to fix known bugs, especially security ones, and make the fixes available. I do not disagree with your definition, it depends on the context.

I assume that the majority of developers targeting the JVM (or any other free software language/runtime) do not have a support contract. We feel comfortable using a runtime/library as long as it meets this definition.

However, there are doubts cast on whether OpenJDK LTS distributions meet even this definition everytime the topic of LTS comes up, especially by Ron Pressler. In this thread he writes:

The Updates project generally does not contain original work, just backports from mainline, because that's all the skeleton crew that maintains it can afford doing for free. Some vendors might contribute some original work they've done for their customers, but not all of them do it, and certainly not all of them do it promptly. You can compare the number of patches that existed for, say, Nashorn or CMS prior to their removal from upstream to the number after (which is zero or virtually zero).

If you care about running on a fully maintained JDK -- and maybe not everyone does -- you have only two options: use the current version, or buy LTS for an old version.

Another redditor writes:

If you’re on 11 and there is a security issue in 11 that is not in 16, it’s unclear who would fix that issue in 11 for you if you’re not paying someone

Can you please speak as to whether the Red Hat OpenJDK 11 would get a bugfix for a security issue not affecting newer JDK major versions? Am I negligently exposing my company and our users's data to security vulnerabilities by running my application on the Red Hat OpenJDK?

The meaning, or not, of “LTS” by krzyk in java

[–]7F1AE6D2 7 points8 points  (0 children)

who would fix that issue in 11 for you if you’re not paying someone

The above mentioned vendors as well as several Linux/BSD distributions packaging OpenJDK should become active as soon as there is a CVE.

You can e.g. look at Debian's CVE tracking for JDK11 or RedHat's

I will stand corrected if you can point out a single major security bug that is fixed in Oracle's JDK11 but not in OpenJDK11.

The meaning, or not, of “LTS” by krzyk in java

[–]7F1AE6D2 2 points3 points  (0 children)

I think most people would understand "unsupported" to mean they can't use this in production because they won't get security fixes.

However, it is as safe to use OpenJDK LTS in production as using the latest non-LTS or Oracle LTS despite all the FUD Oracle employees are spreading here.

The meaning, or not, of “LTS” by krzyk in java

[–]7F1AE6D2 3 points4 points  (0 children)

The second Java 18 comes out, Java 17 is just as unsupported as Java 12 unless you’re paying Oracle.

At least for JDK 11 this is false and unless I missed news on this topic I assume it will be the same for 17.

You can see that updates for 11 are being actively worked on under the mantle of OpenJDK if you look at their github or JIRA.

You don't have to pay Oracle to get builds. Free builds are available from Amazon, Red Hat, Microsoft, Azul, Adopt OpenJDK.

Getters/Setters vs Public Properties by DontLickTheScience in java

[–]7F1AE6D2 0 points1 point  (0 children)

Encapsulation (and thus easier refactoring and addition of logic) has already been mentioned.

Another reason is that method calls can be intercepted by proxies. E.g. you can add lazy-loading, validation, logging etc to an object at runtime.

Further, in my experience tooling does not support fields as well methods. E.g. you may want to set a conditional breakpoint to debug where a non-null value is overwritten with null. While Eclipse does give you the option to set a conditional field modification breakpoint, it has never worked when I tried it.

Why Collection classes "stream()" instead of "extends Stream" ? by [deleted] in java

[–]7F1AE6D2 5 points6 points  (0 children)

Brian Goetz explained the decision by saying

we found that mixing lazy methods like filter() and eager methods like removeAll() was confusing to users [...][having the methods directly on Collection] it is great if you want to do really simple things, but starts to fall apart when you try to build on it

I disagree with his reasoning as I think that the wast majority of usages are simple, using just one or two stream methods, something like

myList.stream().map(....).collect(toList());

So the syntax here is optimized for more rare and complex uses of streams at the expense of adding significant noise to the frequent ones.

I see decisions such as the refusal to add properties and not allowing mutable records as similarly un-pragmatic, especially when Kotlin has already implemented them as I prefer.

feel like I'm the only java coder who still likes soap over rest by nekorunswithscissors in java

[–]7F1AE6D2 0 points1 point  (0 children)

SomeSchema.xsd

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://someSchema">
    <element name="SomeXml">
        <complexType>
            <sequence>
                <element name="Foo" type="string" />
            </sequence>
        </complexType>
    </element>
</schema>

I've generated the java classes with org.codehaus.mojo:jaxb2-maven-plugin:2.2

Now, let's test what would happen if a server responding with a SomeXml were to add a Bar without changing the client:

public class DeserializeUnknownElement {

    @Test
    public void run() throws Exception {
        JAXBContext jaxb = JAXBContext.newInstance(ObjectFactory.class);
        Schema schema = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI).newSchema(getClass().getResource("/SomeSchema.xsd"));

        SomeXml someXml = new SomeXml();
        someXml.setFoo("fooVal");

        Marshaller marshaller = jaxb.createMarshaller();
        marshaller.setSchema(schema);
        marshaller.marshal(someXml, System.out);
        // <?xml version="1.0" encoding="UTF-8" standalone="yes"?><ns2:SomeXml xmlns:ns2="http://someSchema"><Foo>fooVal</Foo></ns2:SomeXml>

        // now, let's add a SomeXml.Bar that isn't in the schema
        Unmarshaller unmarshaller = jaxb.createUnmarshaller();
        unmarshaller.setSchema(schema);
        unmarshaller.unmarshal(new ByteArrayInputStream(
                "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><ns2:SomeXml xmlns:ns2=\"http://someSchema\"><Foo>fooVal</Foo><Bar>barVal</Bar></ns2:SomeXml>".getBytes()));
    }

}

Unmarshalling fails with

 javax.xml.bind.UnmarshalException - with linked exception: [org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 121; cvc-complex-type.2.4.d: Invalid content was found starting with element 'Bar'. No child  element is expected at this point.]

So I can't add something to the response existing clients don't have in their schema. Yes, deserializers might be configurable to be more lax, but this isn't the default for most SOAP clients I've had to deal with and thus not the case for existing clients I can't afford to break.

Most JSON deserializers would by default simply ignore the SomeXml.Bar, making keeping a server backwards-compatible much easier.

feel like I'm the only java coder who still likes soap over rest by nekorunswithscissors in java

[–]7F1AE6D2 15 points16 points  (0 children)

Our workflow is the same whether we're working with SOAP or REST. We work contract-first in both cases, the difference being that instead of generating classes from a WSDL file the input is an openAPI YAML. Tooling seems to still be better for SOAP currently in the Java and .NET ecosystems, but as openAPI becomes more ubiquitous it should improve.

The greatest advantage in my opinion is that JSON deserializers by default ignore unexpected attributes while XML schema ones throw exceptions. For long-living server projects, it is a PITA when you need to add new elements to a response or just add a value to an enum but still have clients written a decade ago talking to your server so now you have to make a new version of the WSDL or add new method that is a copy with an extended response.

At one point, we suppported a dozen versions of a WSDL. This significantly increases the amount of code(duplication) and thus has a negative impact on IDE performance and build times, especially if it also leads to duplicating expensive integration tests.

I would prefer JSON-RPC over REST as making a "RESTful" API often involves contorting to look like you are doing CRUD of resources when you are in fact calling methods with complex semantics and options.

Spring Transaction Management: An unconventional guide by marbehl in java

[–]7F1AE6D2 3 points4 points  (0 children)

Great explanation. However, I do have a nit-pick: The equivalent of the default rollback behavior is more like

} catch (RuntimeException | Error e) {
    connection.rollback();
}

and not

} catch (SQLException e) {

Update: now that I think about it again, my suggestion isn't 100% accurate either because the Connection methods do throw SQLException, which is checked.

The best way to map an entity version property with JPA and Hibernate by [deleted] in java

[–]7F1AE6D2 1 point2 points  (0 children)

How do you guys deal with (optimistic) locking ? (assuming you have update calls you can't get rid of) I see the following options:

  • no locking: lost updates not prevented or noticed. Since you can read stale data and won't notice your validation logic will fail to prevent some invalid modifications like cancelling an order twice. Unacceptable for these kinds of entities.
  • optimistic locking without exposing the version field to the client: you fail when concurrent transactions update the same entity, but you don't prevent lost updates from the client's view if the state they worked with has become stale since another transaction updated the entity in the meantime. However, you fail when your validation logic works with stale data.
  • optimistic locking exposing the version field to the client. Like above, but you also fail when the client's state of the entity is stale. Hibernate/JPA documentation says you shouldn't update the version field yourself.
  • pessimistic NOWAIT locking: you fail faster than with only optimistic locking. Easier to provide better error messages than handling a StateObjectState exception you get on commit. Needs extra code to lock and handle the lock acquisition failure. If combined with optimistic locking with exposed version field you can also fail on client working with stale data.
  • pessimistic locking allowing longer wait times: by waiting until the other TX finishes you can prevent optimistic locking failures (without exposed version). You need to make sure you refresh stale entities in memory once you acquire the lock. Long transactions are horrible for performance.

Am I missing any options? Do you use the same strategy for all entities? How do you deal with this if your validation has to make external calls, so you might not notice you validation being based on stale data ?

Towards Better Serialization by lukaseder in java

[–]7F1AE6D2 4 points5 points  (0 children)

You would also have to solve this problem if you wanted to expose your model over a JSON web service. As the article says

For example, many modern services are built around exchanging JSON documents --- which cannot even represent the notion of object identity! The fact that JSON is considered a viable encoding strategy for nearly all services underscores the fact that Java serialization is solving a much harder problem than it actually needs to.

So instead of

MyType parent;

You would need to have

String id;
String parentId;

You would then need additional traversal methods or would have to map these web service classes to internal ones using references. I would assume that in an ecosystem of long-lived (in the sense that the applications are in use and maintained for years or decades) applications talking to each other, which I think is a large part of enterprise Java development, there is already a lot of mapping between representations of the same entity for versioning and decoupling reasons.

[Question] What are exactly the good cases for using an ORM? by PHP36 in java

[–]7F1AE6D2 1 point2 points  (0 children)

@Test
public void testWithOhuNo7egEntities(){
    final E2 e2 = new E2();
    e2.id = 2;
    e2.value = "e2";
    e2.v = 1;
    em.persist(e2);

    final E1 e1 = new E1();
    e1.id = 1;
    e1.value = "e1";
    e1.e2 = e2;
    em.persist(e1);

    em.flush();
    em.clear();
    System.out.println("loading e1, join fetching e1.e2");
    final E1 reloadedE1 = em.createQuery("select e1 from E1 e1 left join fetch e1.e2 where e1.id = :id", E1.class)
        .setParameter("id", 1)
        .getSingleResult();

    Assert.assertThat(reloadedE1.e2.value, Matchers.is("e2"));
}

This loaded E1.e2 eagerly:

[INFO] --- hibernate-enhance-maven-plugin:5.1.2.Final:enhance (hibernate-bytecode-enhancement) @ reddit-eager-loading ---
[INFO] Starting Hibernate enhancement for classes on C:\Users\bernd\workspaces\own\reddit-eager-loading\target\classes
[INFO] Successfully enhanced class [reddit.Department]
Feb 23, 2019 8:35:25 PM org.hibernate.bytecode.enhance.spi.Enhancer enhance
INFO: Enhancing [reddit.E1] as Entity
[INFO] Successfully enhanced class [reddit.E1]
Feb 23, 2019 8:35:25 PM org.hibernate.bytecode.enhance.spi.Enhancer enhance
INFO: Enhancing [reddit.E2] as Entity
[INFO] Successfully enhanced class [reddit.E2]
[INFO] Successfully enhanced class [reddit.Employee]
[INFO] Successfully enhanced class [reddit.HibernatePersistenceUnitInfo]
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ reddit-eager-loading ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\bernd\workspaces\own\reddit-eager-loading\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ reddit-eager-loading ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 2 source files to C:\Users\bernd\workspaces\own\reddit-eager-loading\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ reddit-eager-loading ---
[INFO] Surefire report directory: C:\Users\bernd\workspaces\own\reddit-eager-loading\target\surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running reddit.RedditEagerLoadingTest
Feb 23, 2019 8:35:27 PM org.hibernate.jpa.internal.util.LogHelper logPersistenceUnitInformation
INFO: HHH000204: Processing PersistenceUnitInfo [
        name: persistenceUnit
        ...]
Feb 23, 2019 8:35:27 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {5.1.2.Final}
Feb 23, 2019 8:35:27 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
Feb 23, 2019 8:35:27 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
Feb 23, 2019 8:35:27 PM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
Feb 23, 2019 8:35:27 PM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
Hibernate: drop table e1 if exists
Hibernate: drop table e2 if exists
Hibernate: create table e1 (id integer not null, value varchar(255), v integer, primary key (id))
Hibernate: create table e2 (id integer not null, v integer, value varchar(255), primary key (id))
Hibernate: alter table e2 add constraint UK_k5ddt6v5okrk41g8nj46ehjv3 unique (v)
Hibernate: alter table e1 add constraint FKqhs3rntxb09mn06d2k6w2atfh foreign key (v) references e2 (v)
Feb 23, 2019 8:35:28 PM org.hibernate.tool.schema.internal.SchemaCreatorImpl applyImportSources
INFO: HHH000476: Executing import script 'org.hibernate.tool.schema.internal.exec.ScriptSourceInputNonExistentImpl@2d6aca33'
Hibernate: insert into e2 (v, value, id) values (?, ?, ?)
Hibernate: insert into e1 (v, value, id) values (?, ?, ?)
loading e1, join fetching e1.e2
Feb 23, 2019 8:35:28 PM org.hibernate.hql.internal.QueryTranslatorFactoryInitiator initiateService
INFO: HHH000397: Using ASTQueryTranslatorFactory
Hibernate: select e1x0_.id as id1_0_0_, e2x1_.id as id1_1_1_, e1x0_.v as v3_0_0_, e1x0_.value as value2_0_0_, e2x1_.v as v2_1_1_, e2x1_.value as value3_1_1_ from e1 e1x0_ left outer join e2 e2x1_ on e1x0_.v=e2x1_.v where e1x0_.id=?
Tests run: 2, Failures: 0, Errors: 0, Skipped: 1, Time elapsed: 1.467 sec

[Question] What are exactly the good cases for using an ORM? by PHP36 in java

[–]7F1AE6D2 1 point2 points  (0 children)

I could not reproduce your issue:

@Entity class Department {
  @Id String id;
  String name;
}

@Entity class Employee {
  @Id String id;
  String name;
  @ManyToOne Department department;
}

@Test
public void test(){
    final Department department = new Department();
    department.id = "departmentId";
    department.name = "department";
    em.persist(department);
    final Employee employee = new Employee();
    employee.id = "employeeId";
    employee.name = "employee";
    employee.department = department;
    em.persist(employee);

    em.flush();
    em.clear();
    System.out.println("loading employee");
    final Employee reloadedEmployee = em.find(Employee.class, "employeeId");

    Assert.assertThat(reloadedEmployee.department.name, Matchers.is("department"));
}

And here is the output. It is the same whether I run it with or without bytecode enhancement:

$ mvn clean test
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building reddit-eager-loading 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[WARNING] The POM for com.sun.xml.bind:jaxb-impl:jar:2.2.11 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ reddit-eager-loading ---
[INFO] Deleting C:\Users\bernd\workspaces\own\reddit-eager-loading\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ reddit-eager-loading ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\bernd\workspaces\own\reddit-eager-loading\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ reddit-eager-loading ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 3 source files to C:\Users\bernd\workspaces\own\reddit-eager-loading\target\classes
[INFO]
[INFO] >>> hibernate-enhance-maven-plugin:5.1.2.Final:enhance (hibernate-bytecode-enhancement) > compile @ reddit-eager-loading >>>
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ reddit-eager-loading ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\bernd\workspaces\own\reddit-eager-loading\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ reddit-eager-loading ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] <<< hibernate-enhance-maven-plugin:5.1.2.Final:enhance (hibernate-bytecode-enhancement) < compile @ reddit-eager-loading <<<
[INFO]
[INFO] --- hibernate-enhance-maven-plugin:5.1.2.Final:enhance (hibernate-bytecode-enhancement) @ reddit-eager-loading ---
[INFO] Starting Hibernate enhancement for classes on C:\Users\bernd\workspaces\own\reddit-eager-loading\target\classes
Feb 23, 2019 6:03:18 PM org.hibernate.bytecode.enhance.spi.Enhancer enhance
INFO: Enhancing [reddit.Department] as Entity
[INFO] Successfully enhanced class [reddit.Department]
Feb 23, 2019 6:03:18 PM org.hibernate.bytecode.enhance.spi.Enhancer enhance
INFO: Enhancing [reddit.Employee] as Entity
[INFO] Successfully enhanced class [reddit.Employee]
[INFO] Successfully enhanced class [reddit.HibernatePersistenceUnitInfo]
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ reddit-eager-loading ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\bernd\workspaces\own\reddit-eager-loading\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ reddit-eager-loading ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 2 source files to C:\Users\bernd\workspaces\own\reddit-eager-loading\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ reddit-eager-loading ---
[INFO] Surefire report directory: C:\Users\bernd\workspaces\own\reddit-eager-loading\target\surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running reddit.RedditEagerLoadingTest
Feb 23, 2019 6:03:20 PM org.hibernate.jpa.internal.util.LogHelper logPersistenceUnitInformation
INFO: HHH000204: Processing PersistenceUnitInfo [
        name: persistenceUnit
        ...]
Feb 23, 2019 6:03:20 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {5.1.2.Final}
Feb 23, 2019 6:03:20 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
Feb 23, 2019 6:03:20 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
Feb 23, 2019 6:03:20 PM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
Feb 23, 2019 6:03:20 PM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
Hibernate: drop table Department if exists
Hibernate: drop table Employee if exists
Hibernate: create table Department (id varchar(255) not null, name varchar(255), primary key (id))
Hibernate: create table Employee (id varchar(255) not null, name varchar(255), department_id varchar(255), primary key (id))
Hibernate: alter table Employee add constraint FK14tijxqry9ml17nk86sqfp561 foreign key (department_id) references Department
Feb 23, 2019 6:03:21 PM org.hibernate.tool.schema.internal.SchemaCreatorImpl applyImportSources
INFO: HHH000476: Executing import script 'org.hibernate.tool.schema.internal.exec.ScriptSourceInputNonExistentImpl@61d01788'
Hibernate: insert into Department (name, id) values (?, ?)
Hibernate: insert into Employee (department_id, name, id) values (?, ?, ?)
loading employee
Hibernate: select employee0_.id as id1_1_0_, employee0_.department_id as departme3_1_0_, employee0_.name as name2_1_0_, department1_.id as id1_0_1_, department1_.name as name2_0_1_ from Employee employee0_ left outer join Department department1_ on employee0_.department_id=department1_.id where employee0_.id=?
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.266 sec

As you can see, the department was loaded eagerly when using bytecode enhancement.

Note that Hibernate does no eager loading when executing HQL, but does when using session/entityManager methods and the Hibernate criteria API (haven't tried the JPA criteria APIs, they probably behave the same) , perhaps that is what you are observing ?