-
Notifications
You must be signed in to change notification settings - Fork 359
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: support JPA annotation mapping for object model #14626
Conversation
@@ -42,8 +42,6 @@ public interface ReservedValueStore extends GenericStore<ReservedValue> { | |||
List<ReservedValue> getAvailableValues( | |||
ReservedValue reservedValue, List<String> values, String ownerObject); | |||
|
|||
List<ReservedValue> reserveValuesJpa(ReservedValue reservedValue, List<String> values); | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a code clean up done by Luca from tracker team. He helped to fix one of the unit test failed after using entityManager.
if (isEmpty(values) || !reservedValue.getOwnerObject().equals(ownerObject)) { | ||
return List.of(); | ||
} | ||
List<String> availableValues = getIfAvailable(reservedValue, values); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
code clean up done by Luca.
@Override | ||
public Serializable getIdentifier(Object object) { | ||
return sessionFactory.getCurrentSession().getIdentifier(object); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those methods are not in use
JsonNode node = mapper.readTree(result.getResponse().getContentAsString()); | ||
assertEquals(valueToCheck, node.get("displayName").asText()); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this test class as it is obsolete. The translations api is covered in AbstractCrudControllerTest.replaceTranslationsOk() and some other tests in that class.
public void setDatabaseInfoProvider(DatabaseInfoProvider databaseInfoProvider) { | ||
this.databaseInfoProvider = databaseInfoProvider; | ||
} | ||
private final DatabaseInfoProvider databaseInfoProvider; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is to fix a circular dependency between DataBaseInfoProvider and DhisConfigurationProvider
...-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/objectbundle/DefaultObjectBundleService.java
Outdated
Show resolved
Hide resolved
private String[] loadResources() { | ||
try { | ||
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); | ||
Resource[] resources = resolver.getResources("classpath*:org/hisp/dhis/**/*.hbm.xml"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this file check be more targeted? It looks like it's going to look through every package on the classpath when we know exactly where all hbm.xml
files are located.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure how to do this. Will check later and update on next PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice work Viet
Kudos, SonarCloud Quality Gate passed! |
https://dhis2.atlassian.net/browse/TECH-1517
Scope
As mentioned here , hbm.xml mapping format is considered deprecated and will no longer supported beyond 6.x.
The goal of this PR is to support both Hibernate xml and JPA annotation mapping for object model in DHIS2. It doesn't upgrade Hibernate to version 6.x
Tasks
org.hibernate.Criteria
is completely replaced by JPA query api.SessionFactory
withEntityManager
.EntityManager
through constructor instead of field injection with@PersistenceContext
, this is needed for unit tests with Mockito. Reference spring-projects/spring-data-jpa@7b54253Next PRs
hibernate.allow_update_outside_transaction
as JPA doesn't allow callingsession.update
orsession.flush
outside of a transaction. This requires refactoring in places where we explicitly callsession.update
orsession.flush
without@Transactional
wrapper.session.flush()
inside a transaction should be carefully tested in metadata import service. May need to be removed and let the objects to be managed by JPA PersistenContext.BaseIdentifiableObject
into multiple base objects in order to support entity inheritance mapping for only required properties. Such asBaseShareableIdObject
,BaseIdObject
,BaseAttributeObject
, etc..save
/update
withpersist
/merge