https://github.com/timnguyen99/code_demo
Java, SpringBoot, React, Angular, Oracle, PL/SQL, Ellucian Banner, Puppet, Docker, Terraform technical notes
Wednesday, April 14, 2021
Tuesday, March 16, 2021
Hibernate 3 to 5 migration
Some notes and tips:
1. 1. Typical current code
getCurrentSession().createCriteria(BT.class)
.add(Restrictions.eq("replacedBT",
replaced))
.addOD(OD.desc("id")).list();
Will be replaced by
CriteriaQuery<BT> criteriaQuery =
getCurrentSession().getCriteriaBuilder().createQuery(BT.class);
Root<BT> root = criteriaQuery.from(BT.class);
CriteriaBuilder cb =
getCurrentSession().getCriteriaBuilder();
criteriaQuery.select(root).where(getCurrentSession().getCriteriaBuilder().equal(root.get("replacedBT"),
replaced));
criteriaQuery.ODBy(cb.desc(root.get("id")));
2.
Mapping
|
Hibernate |
JPA |
1 |
setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY) |
criteriaQuery.select(root).distinct(true) |
2 |
setProjection(Property.forName("id") |
criteriaQuery.multiselect(root.get("id")) |
|
|
|
3 |
Disjunction |
CriteriaBuilder disjunction(); Ex: Predicate predicate =
cb.disjunction(); predicate.getExpressions().add(cb.isNull(root.get("effectiveEndDate"))); predicate.getExpressions().add(cb.greaterThanOrEqualTo(root.get("effectiveEndDate"),
DateUtil.getLienDateForTestY(testY.intValue()))); |
4 |
Criterion |
predicate.getExpressions().add( |
5 |
Restrictions.in ("testY",
Ys) |
root.get("testY").in(Ys) |
|
|
|
6 |
Restrictions.le |
lessThanOrEqualTo |
7 |
Restrictions.ilike - case insensitive |
cb.like(cb.lower(root.get("assesseeName")),
"%"+name.trim().toLowerCase() + "%" |
8 |
Build list of conditions
many if else |
List<Predicate>
predicates = new ArrayList<>(); predicates.add(join.get("testId").in(oidSub)); predicates.add(cbSub.notEqual(rootBT.get("pmStatus"),
BTPmStatus.paidStatus)); predicates.add(cbSub.notEqual(rootBT.get("status"),
TestBTStatus.canceled)); predicates.add(cbSub.notEqual(rootBT.get("status"),
TestBTStatus.purged)); predicates.add(cbSub.notEqual(rootBT.get("status"),
TestBTStatus.rolledToUnsecured )); |
9 |
Join BTCrit.createCriteria("testCharges","chg"); BTCrit.add
(Restrictions.in("chg.testId", oidSub) ); |
Join<BT,
Charge> join = rootBT.join("testCharges", JoinType.INNER); criteriaQueryBT.select(rootBT).where(join.get("testId").in(oids),
cbBT.equal(rootBT.get("testY"), testY), rootBT.get("BTType").in(types) ); |
10 |
Multiple Join List<JTestOD> chains =
getCurrentSession()
.createCriteria(JTestOD.class) .add(Restrictions.not(Restrictions.eq("state",
JTestODState.open))) .createCriteria("traTranss") .createCriteria("JTransProperties")
.add(Restrictions.eq("id.apn",prop.getPropertyId()))
.add(Restrictions.eq("propertyAvTestY",prop.getTestY())) // .add(Restrictions.eq("chainedToTestOD",
co)) // .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY) // .list(); |
CriteriaQuery<JTestOD>
criteriaQuery = getCurrentSession().getCriteriaBuilder().createQuery(JTestOD.class); CriteriaBuilder cb =
getCurrentSession().getCriteriaBuilder(); Root<JTestOD> root = criteriaQuery.from(JTestOD.class); Join<JTestOD, JTraTrans> join =
root.join("traTranss", JoinType.INNER); Join<JTraTrans, JTransProperty>
join2 = join.join("JTransProperties", JoinType.INNER);
criteriaQuery.select(root).distinct(true) .where( cb.notEqual(root.get("state"),
JTestODState.open), cb
.equal(join2.get("id").get("apn"), prop.getPropertyId()), cb.equal(join2.get("propertyAvTestY"),
prop.getTestY()), cb
.equal(join2.get("chainedToTestOD"), co)); List<JTestOD> chains =
getCurrentSession().createQuery(criteriaQuery).getResultList(); |
Hibernate 3 to Hibernate 5 migration
Hibernate 3 to Hibernate 5 migration Tips and Steps
Package name changes
Friday, March 8, 2019
Multiple authentication mechanism chaining in OAM: Card 2FA authentication
http://www.ateam-oracle.com/multiple-authentication-mechanism-chaining-in-oam/
Tuesday, February 19, 2019
Ellucian banner : Search by name in keyblock
Ellucian banner : Search by name in keyblock
Order of struct is for Next item default, and search by name need ID next to Name
AWS how to delete VPC when it has error with Network interface , Gateway decencies
how to delete VPC when it has error with Network interface , Gateway decencies in AWS 1. Check if it is running on EC2 instance then Sto...
-
ORA-29273: HTTP request failed ORA-06512: at "SYS.UTL_HTTP", line 1525 ORA-29261: bad argument ORA-29273: HTTP request failed ...
-
Banner 9 Admin: Invalid Object Name fix do steps: A record in GUBOBJS with a UI Version of D. • Records in GURAOBJ to define the defau...
-
chown root $ORACLE_HOME/bin/extjob chmod 4750 $ORACLE_HOME/bin/extjob chown root $ORACLE_HOME/rdbms/admin/externaljob.ora chmod 640 $ORA...