I'm struggling to understand how to use the matches method on the String class when using regular expressions.
I have a small example with two classes. The TempPhysicalPartDetails class is embedded in the TempPhysicalPart class.
@Entity @Data @AllArgsConstructor @NoArgsConstructor public class TempPhysicalPart { private Long id; private TempPhysicalPartDetails physicalPartDetails; }
@Embeddable @Data @AllArgsConstructor @NoArgsConstructor public class TempPhysicalPartDetails { String partNumber; String serialNumber; }
I am trying to compare the partNumber and serialNumber against the user provided regex expression.
For example, if a user wanted all part numbers ending in 802. They would pass the expression *802.
I just can't figure out where this would be in the criteria builder.
{ CriteriaBuilder cb = emf.getCriteriaBuilder(); CriteriaQuery<TempPhysicalPart> q = cb.createQuery(TempPhysicalPart.class); Root<TempPhysicalPart> c = q.from(TempPhysicalPart.class); q.select(c).where(cb.equal(c.get("details").get("partNumber"), "82382")); q.select(c).where(cb.equal(c.get("details").get("serialNumber"), "00012"));
}
The EntityManagerFactory implementation is excluded from.