diff --git a/pom.xml b/pom.xml index 7a68a9e..745fbdf 100644 --- a/pom.xml +++ b/pom.xml @@ -131,7 +131,8 @@ org.hibernate.orm hibernate-jpamodelgen - ${maven.hibernate.version} + + 6.4.8.Final jakarta.xml.bind diff --git a/src/main/java/com/entityassist/BaseEntity.java b/src/main/java/com/entityassist/BaseEntity.java index e0d86e9..0f7fcd9 100644 --- a/src/main/java/com/entityassist/BaseEntity.java +++ b/src/main/java/com/entityassist/BaseEntity.java @@ -1,6 +1,5 @@ package com.entityassist; -import com.entityassist.exceptions.QueryBuilderException; import com.entityassist.querybuilder.QueryBuilder; import com.entityassist.services.entities.IBaseEntity; import com.fasterxml.jackson.annotation.JsonAutoDetect; @@ -43,8 +42,7 @@ public BaseEntity() { @SuppressWarnings("unchecked") @NotNull public J persist() { - builder().persist((J) this); - return (J) this; + return builder().persist((J) this).getEntity(); } /** diff --git a/src/main/java/com/entityassist/querybuilder/QueryBuilder.java b/src/main/java/com/entityassist/querybuilder/QueryBuilder.java index 8dd758f..e02dceb 100644 --- a/src/main/java/com/entityassist/querybuilder/QueryBuilder.java +++ b/src/main/java/com/entityassist/querybuilder/QueryBuilder.java @@ -91,7 +91,7 @@ public Long getCount() } catch (NoResultException nre) { - Logger.getLogger(getClass().getName()).log(Level.WARNING, "Couldn''t find object with name : " + getEntityClass().getName() + "}\n", nre); + Logger.getLogger(getClass().getName()).log(Level.WARNING, "Couldn't find object with name : " + getEntityClass().getName(), nre); return 0L; } } diff --git a/src/main/java/com/entityassist/querybuilder/QueryBuilderSCD.java b/src/main/java/com/entityassist/querybuilder/QueryBuilderSCD.java index c8984a7..bd26651 100644 --- a/src/main/java/com/entityassist/querybuilder/QueryBuilderSCD.java +++ b/src/main/java/com/entityassist/querybuilder/QueryBuilderSCD.java @@ -1,19 +1,23 @@ package com.entityassist.querybuilder; -import com.entityassist.*; +import com.entityassist.RootEntity; +import com.entityassist.SCDEntity; import com.entityassist.enumerations.Operand; - - +import com.entityassist.enumerations.OrderByType; import jakarta.validation.constraints.NotNull; import java.io.Serializable; import java.sql.SQLException; -import java.time.*; +import java.time.LocalDateTime; +import java.time.OffsetDateTime; +import java.time.ZoneId; +import java.time.ZonedDateTime; import java.util.logging.Level; import java.util.logging.Logger; -import static com.entityassist.SCDEntity.*; -import static java.time.ZoneOffset.*; +import static com.entityassist.SCDEntity.EndOfTime; +import static com.entityassist.SCDEntity.getNow; +import static java.time.ZoneOffset.UTC; @SuppressWarnings("unused") public abstract class QueryBuilderSCD, E extends SCDEntity, I extends Serializable> @@ -285,5 +289,10 @@ public static LocalDateTime convertToLocalDateTime(OffsetDateTime ldt, String ti ZonedDateTime zonedDateTime = ldt.atZoneSameInstant(ZoneId.of(timezone)); return zonedDateTime.toLocalDateTime(); } - + + public J latestFirst() + { + orderBy(getAttribute(WAREHOUSE_UPDATED_DATE_COLUMN_NAME), OrderByType.DESC); + return (J)this; + } } diff --git a/src/main/java/com/entityassist/querybuilder/builders/QueryBuilderRoot.java b/src/main/java/com/entityassist/querybuilder/builders/QueryBuilderRoot.java index 5c716d3..ee1d358 100644 --- a/src/main/java/com/entityassist/querybuilder/builders/QueryBuilderRoot.java +++ b/src/main/java/com/entityassist/querybuilder/builders/QueryBuilderRoot.java @@ -245,12 +245,14 @@ public J persist(E entity) boolean transactionAlreadyStarted = false; getEntityManager().persist(entity); entity.setFake(false); + setEntity(entity); } } catch (IllegalStateException ise) { Logger.getLogger(getClass().getName()) .log(Level.SEVERE, "This entity is not in a state to be persisted. Perhaps an update merge remove or refresh?", ise); + throw new UnsupportedOperationException(ise); } catch (Exception e) {