Get Current Date and Time in Java: now(), Clock and Time Zones
Get the current date and time in Java with LocalDate, LocalDateTime, ZonedDateTime and Instant now(), in any time zone, formatted and testable.
Get the current date and time in Java with LocalDate, LocalDateTime, ZonedDateTime and Instant now(), in any time zone, formatted and testable.
Find the difference between two dates in Java in years, months, days, hours and minutes with Period, Duration and ChronoUnit, including DST cases.
Hibernate 4.3 to 5.2 throw QueryException: Cannot mix named and positional parameters when a stored procedure call registers parameters by name and by position. See the message in each version, what Hibernate 7.4 does with mixed HQL and native queries, and the fix.
HSQLDB throws “data exception: invalid character value for cast” when text reaches a number column. See the four real causes in Hibernate 7.4 and the fix for each.
@NamedStoredProcedureQuery declares a stored procedure call once on an entity and runs it by name. Learn every attribute, parameter modes, result mapping to entities and records, hints and the errors you meet.
A JPA native DELETE query runs plain SQL with executeUpdate(). Learn createNativeQuery() and @NamedNativeQuery, foreign key errors and their fixes, and why callbacks, cascades and @SoftDelete are skipped.
Hibernate 3.6 to 4.1 stop at startup with NotYetImplementedException when a named native query has no resultClass or resultSetMapping. See the real error, the @ColumnResult workaround and how Hibernate 7 returns scalar values.
A JPA native UPDATE query runs our own SQL with executeUpdate() and returns the row count. Learn createNativeQuery() and @NamedNativeQuery, why loaded entities go stale, and how to declare the changed tables.
A JPA native query sends our own SQL to the database and still returns managed entities, scalar values, Tuples or records. Learn createNativeQuery(), @NamedNativeQuery, result set mappings, joins and paging with Hibernate 7.
The Java Persistence API (JPA) is a Java application programming interface specification that describes the management of relational data in applications using Java Platform, Standard Edition and Java Platform, Enterprise Edition. This page lists down all tutorials available on this blog related to JPA. JPA Basics CRUD Operations Integration Related Happy Learning !!
Learn to configure the JPA in Spring application without the persistence.xml. We will see the XML and Java configuration examples.
Spring MVC Interview Questions and answers. These have been written to help beginners as well as experienced developers to prepare for their next interview.
Learn to create Spring REST client using Spring RestTemplate class and it’s template methods to access HTTP GET, POST, PUT and DELETE requests in easy step.
A Hibernate criteria query builds SQL from Java objects with CriteriaBuilder, CriteriaQuery and Root. Learn filters, joins, fetch joins, group by, subqueries, pagination, dynamic filters, bulk updates and the static metamodel in Hibernate 7, with the generated SQL for each query.
Hibernate Query Language (HQL) queries entities and attributes instead of tables and columns. Learn HQL select, joins, join fetch, aggregates, subqueries, update, delete and insert in Hibernate 7, with the SQL Hibernate generates for each query.
A reference of the JPA annotations used on almost every Hibernate entity, from @Entity and @Column to @Embedded, @Version and @Convert, each with the DDL Hibernate 7.4 generates for it.
Hibernate reads mapping metadata from annotations or from XML files. We map one Bicycle entity with annotations, orm.xml and the deprecated hbm.xml, and override annotations with orm.xml in Hibernate 7.4.
Hibernate save(), update() and saveOrUpdate() were deprecated in Hibernate 6 and removed in Hibernate 7. We run the old methods on Hibernate 6.6, then show how persist() and merge() replace them for new, detached and managed entities.
Configure c3p0 as Hibernate 7’s connection pool with hibernate.c3p0 settings, check it in the logs and with pool statistics, size it, close and test idle connections, find leaks, and use c3p0 as the DataSource in Spring Boot 4.
Unit test Hibernate repositories against an in-memory H2 database with JUnit 6: one EntityManagerFactory per test class, data from import.sql, a fresh copy of the data before every test with truncate(), and the H2 settings and pitfalls that break tests.
Build a Hibernate SessionFactory in Hibernate 7.4 with HibernatePersistenceConfiguration, the native StandardServiceRegistryBuilder and MetadataSources API, the Configuration class, hibernate.cfg.xml, or unwrap() from an EntityManagerFactory. Then share one factory across threads and close it at shutdown.
OpenCSV 5.12 examples to read and write CSV files in Java as arrays, maps and beans, with quoting, appending, bad rows and large files explained.
Java reflection examples from real frameworks, with a test runner, CSV export, DI container, plugin loader, dynamic proxy and the Java 17+ module rules.
Java Fork/Join framework with ForkJoinPool examples. RecursiveTask, RecursiveAction, work stealing, thresholds, errors and when to use executors instead.
Calculate age from date of birth in Java with Period.between() and ChronoUnit, plus leap-day birthdays, time zones, parsing and a minimum age check.
Reader Sreenath Ravva shared these questions from an Oracle Enterprise Manager interview. This is a historical account, not an official Oracle question bank or a prediction of a current interview. The answers below make the original questions useful for revising Java, concurrency, JDBC and project discussions. I have tried to put links to web pages … Read more
AbstractRoutingDataSource is a very useful feature if we have a design which permits multiple databases based on certain criteria which may change for each user request. An example can be when we can use a particular database when the user belongs to a certain locale and switch to another locale if the user belongs to … Read more
Spring throws “Bean property ‘configurationClass’ is not writable” when XML written for Hibernate 3 sets configurationClass on a newer LocalSessionFactoryBean. See the real error on Spring 7, the XML fix, and the Spring Boot 4 setup that needs no SessionFactory bean.
NoClassDefFoundError: org/hibernate/engine/SessionFactoryImplementor means a class built for Hibernate 3, usually Spring’s orm.hibernate3 transaction manager, runs with Hibernate 4 or newer. Find the jar, switch to the matching Spring package or align the Hibernate modules, and unwrap the SPI interface on Hibernate 7.
Checked vs unchecked exceptions in Java explained with the Throwable hierarchy, compiler rules, Java 25 examples and when to choose each kind.
Map BLOB and CLOB columns in Hibernate 7 with @Lob on byte[], String, Blob and Clob fields. See the generated column types on H2, MySQL and PostgreSQL, how to stream large files with Blob, and why @Basic(fetch = LAZY) needs bytecode enhancement.
So far we have learned about securing spring application using login form based security, custom user details security and many more such security related concepts. In this post, I am giving an example of scenario where use is already authenticated via any third party application or tool e.g. site minder which is very common interface … Read more
Map a natural id such as a license plate with Hibernate’s @NaturalId, load entities with em.find(…, KeyType.NATURAL), handle mutable and composite natural ids, and cache lookups with @NaturalIdCache, with the SQL and statement counts from Hibernate 7.4.
Java password hashing done right with PBKDF2, bcrypt, scrypt and Argon2id, OWASP parameters, salts, real timings, and why MD5 and SHA-256 fail.
Learn Java try-with-resources with runnable examples, close order of multiple resources, suppressed exceptions, custom AutoCloseable and JDBC usage.
Hibernate throws “No row with the given identifier exists” when a proxy or an eager load asks for an id that has no row. See the real Hibernate 7.4 exceptions for getReference(), lazy and eager associations and concurrent deletes, and fix them with find(), orphan cleanup, a foreign key constraint or @NotFound.
A good programmer is one who write programs (not just code). It means writing the code units which are independent enough to be re-used in multiple ways, and still they remain robust. So let’s start identifying and learning some java best practices which can transform any code into the programs. 1. Java Design Best Practices … Read more
Hibernate stops at startup with “Errors in named queries” when a JPQL named query uses a table name, a column name, SQL syntax or a broken parameter. See how to read NamedQueryValidationException in Hibernate 7 and fix each cause.
A Hibernate named query is a JPQL or SQL query declared once and run by name. Learn @NamedQuery, @NamedNativeQuery, orm.xml, parameters, result types, the startup check and JPA 3.2 typed references.
The Hibernate second level cache shares entity data across all sessions of an EntityManagerFactory. Learn the lookup order, what the cache stores, the concurrency strategies, collection and query caching, statistics and eviction with Hibernate 7.4 and Ehcache 3.
The Hibernate first level cache is the persistence context of one EntityManager. See with counted SQL on Hibernate 7.4 when find() and queries hit the database, how detach(), evict(), clear() and refresh() work, and how to keep long transactions small.
To insert an object with Hibernate, we pass a new entity to persist() inside a transaction. Learn when the INSERT runs for IDENTITY, SEQUENCE and assigned ids, how merge() and HQL insert statements work, and what replaced Session.save() in Hibernate 7.
Test Spring Security authentication with JUnit 6 and Spring Boot 4.1.1 using @WithMockUser, @WithUserDetails, httpBasic(), csrf() and 401 and 403 checks.
So far in previous tutorials, we have learned about securing your application behind login form, custom user detail service and even method level security also. All these security implementations were on controller or model layer of MVC. Its time to add security in view layer. It is mostly needed when we want to hide certain … Read more
Learn about the contract that spring security expects from UserDetailsService and PasswordEncoder, initial defaults and basic customizations.
Read all the Java interview questions and answers in this article to refresh your concepts and possibly have some new ones added to the list.
Build your first Hibernate application with Hibernate 7.4, Java 25 and H2: the Maven dependencies, an entity, the configuration, and save, read, update and delete with the SQL each call runs.
Java String interview questions with answers and runnable code. Immutability, string pool, == vs equals, StringBuilder, and coding tasks for Java 25.
Abstraction in Java with interfaces, abstract classes and sealed interfaces, a CSV and JSON export example, a comparison table and common FAQs.
HowToDoInJava provides tutorials and how-to guides on Java and related technologies.
It also shares the best practices, algorithms & solutions and frequently asked interview questions.