Skip to content

Commit 5006805

Browse files
committed
🔀 merge: Integrate v0.3.1 bug fixes with v0.4.0 CRUD system - Resolved merge conflicts keeping 0.4.0 features - Included CHANGELOG.md and BaseRepositoryImpl.java improvements - Maintains backward compatibility
2 parents d36e801 + cb72abf commit 5006805

File tree

2 files changed

+127
-19
lines changed

2 files changed

+127
-19
lines changed

‎CHANGELOG.md‎

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Changelog
2+
3+
All notable changes to Jazzy Framework will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [0.3.1] - 2025-01-27
9+
10+
### Fixed
11+
- **BREAKING**: Fixed deprecated Hibernate API usage in BaseRepositoryImpl
12+
- Replaced deprecated `session.createQuery()` with `session.createMutationQuery()` for DELETE operations
13+
- This ensures compatibility with future Hibernate versions and removes deprecation warnings
14+
15+
### Changed
16+
- Updated Hibernate ORM from 6.4.1.Final to 6.4.10.Final for better performance and security
17+
- Updated H2 database from 2.2.224 to 2.2.232 for latest bug fixes
18+
19+
### Added
20+
- Enhanced transaction management in BaseRepositoryImpl with new helper methods:
21+
- `executeInTransaction()` for operations that return values
22+
- `executeInTransactionVoid()` for void operations
23+
- Both methods include proper rollback handling for improved reliability
24+
25+
### Technical Details
26+
- Improved error handling in repository operations
27+
- Better transaction safety with automatic rollback on exceptions
28+
- Removed FIXME comments related to deprecated API usage
29+
30+
## [0.3.0] - 2025-01-26
31+
32+
### Added
33+
- Comprehensive Spring Data JPA-like query system
34+
- Method name parsing for automatic query generation
35+
- Support for @Query, @Modifying, and @QueryHint annotations
36+
- Enhanced RepositoryFactory with query method support
37+
- Database-level query execution for improved performance
38+
39+
### Fixed
40+
- Resolved "socket hang up" errors in exception handling
41+
- Fixed excessive logging in ORM components
42+
- Improved code quality and reduced duplication in repository implementations
43+
44+
### Changed
45+
- Migrated from memory-based filtering to database-level queries
46+
- Enhanced query method parser with support for complex operations
47+
- Improved error messages and debugging capabilities
48+
49+
## [0.2.0] - 2025-01-25
50+
51+
### Added
52+
- Comprehensive dependency injection system
53+
- Spring-like annotations (@Component, @Named, @Primary, @PostConstruct, @PreDestroy)
54+
- Zero-configuration DI container
55+
- Automatic component scanning and registration
56+
57+
### Changed
58+
- Enhanced framework architecture with DI support
59+
- Improved documentation and examples
60+
61+
## [0.1.0] - 2025-01-24
62+
63+
### Added
64+
- Initial release of Jazzy Framework
65+
- Basic web framework functionality
66+
- Fluent API for request/response handling
67+
- Simple routing system
68+
- JSON operations support
69+
- Basic validation system

‎src/main/java/jazzyframework/data/BaseRepositoryImpl.java‎

Lines changed: 58 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import java.util.ArrayList;
1313
import java.util.List;
1414
import java.util.Optional;
15+
import java.util.function.Consumer;
16+
import java.util.function.Function;
1517
import java.util.logging.Logger;
1618

1719
/**
@@ -108,11 +110,8 @@ public T save(T entity) {
108110
throw new IllegalArgumentException("Entity must not be null");
109111
}
110112

111-
try (Session session = sessionFactory.openSession()) {
112-
Transaction transaction = session.beginTransaction();
113-
T savedEntity = session.merge(entity);
114-
transaction.commit();
115-
return savedEntity;
113+
try {
114+
return executeInTransaction(session -> session.merge(entity));
116115
} catch (Exception e) {
117116
logger.severe("Error saving entity: " + e.getMessage());
118117
throw new RuntimeException("Failed to save entity", e);
@@ -152,11 +151,8 @@ public Optional<T> findById(ID id) {
152151
throw new IllegalArgumentException("ID must not be null");
153152
}
154153

155-
try (Session session = sessionFactory.openSession()) {
156-
Transaction transaction = session.beginTransaction();
157-
T entity = session.get(entityClass, id);
158-
transaction.commit();
159-
return Optional.ofNullable(entity);
154+
try {
155+
return executeInTransaction(session -> Optional.ofNullable(session.get(entityClass, id)));
160156
} catch (Exception e) {
161157
logger.severe("Error finding entity by ID: " + e.getMessage());
162158
throw new RuntimeException("Failed to find entity", e);
@@ -244,13 +240,13 @@ public void deleteById(ID id) {
244240
throw new IllegalArgumentException("ID must not be null");
245241
}
246242

247-
try (Session session = sessionFactory.openSession()) {
248-
Transaction transaction = session.beginTransaction();
249-
T entity = session.get(entityClass, id);
250-
if (entity != null) {
251-
session.remove(entity);
252-
}
253-
transaction.commit();
243+
try {
244+
executeInTransactionVoid(session -> {
245+
T entity = session.get(entityClass, id);
246+
if (entity != null) {
247+
session.remove(entity);
248+
}
249+
});
254250
logger.fine("Deleted entity with ID: " + id);
255251
} catch (Exception e) {
256252
logger.severe("Error deleting entity by ID: " + e.getMessage());
@@ -290,7 +286,7 @@ public void deleteAllById(Iterable<ID> ids) {
290286

291287
try (Session session = sessionFactory.openSession()) {
292288
Transaction transaction = session.beginTransaction();
293-
Query<?> query = session.createQuery( // FIXME: deprecated method
289+
var query = session.createMutationQuery(
294290
"DELETE FROM " + entityName + " e WHERE e." + idFieldName + " IN (:ids)");
295291
query.setParameterList("ids", idList);
296292
int deletedCount = query.executeUpdate();
@@ -329,7 +325,7 @@ public void deleteAll(Iterable<T> entities) {
329325
public void deleteAll() {
330326
try (Session session = sessionFactory.openSession()) {
331327
Transaction transaction = session.beginTransaction();
332-
Query<?> query = session.createQuery("DELETE FROM " + entityName); // FIXME: deprecated method
328+
var query = session.createMutationQuery("DELETE FROM " + entityName);
333329
int deletedCount = query.executeUpdate();
334330
transaction.commit();
335331
logger.fine("Deleted all " + deletedCount + " entities of type: " + entityName);
@@ -386,4 +382,47 @@ public void deleteInBatch(Iterable<T> entities) {
386382
public void deleteAllInBatch() {
387383
deleteAll();
388384
}
385+
386+
/**
387+
* Helper method to execute operations in a transaction with proper rollback handling.
388+
*
389+
* @param operation the operation to execute
390+
* @param <R> the return type
391+
* @return the result of the operation
392+
*/
393+
protected <R> R executeInTransaction(Function<Session, R> operation) {
394+
try (Session session = sessionFactory.openSession()) {
395+
Transaction transaction = session.beginTransaction();
396+
try {
397+
R result = operation.apply(session);
398+
transaction.commit();
399+
return result;
400+
} catch (Exception e) {
401+
if (transaction.isActive()) {
402+
transaction.rollback();
403+
}
404+
throw e;
405+
}
406+
}
407+
}
408+
409+
/**
410+
* Helper method to execute void operations in a transaction with proper rollback handling.
411+
*
412+
* @param operation the operation to execute
413+
*/
414+
protected void executeInTransactionVoid(Consumer<Session> operation) {
415+
try (Session session = sessionFactory.openSession()) {
416+
Transaction transaction = session.beginTransaction();
417+
try {
418+
operation.accept(session);
419+
transaction.commit();
420+
} catch (Exception e) {
421+
if (transaction.isActive()) {
422+
transaction.rollback();
423+
}
424+
throw e;
425+
}
426+
}
427+
}
389428
}

0 commit comments

Comments
 (0)