Spring Miscellaneous#
Spring AOP#
ProxyFactory:
// class IntImpl implements Int { … }
ProxyFactory pf = new ProxyFactory(new IntImpl());
Int eye = (Int) pf.getProxy();
MethodAdvice:
pf.addAdvice(new MethodBeforeAdvice() {
@Override
public void before(Method m, Object[] args, Object target) {
…
}
});
Pointcut:
@Pointcut("execution(* adviseMe(..))")
private void anyMethodCalledAdviseMe() {
}
Spring JPA Id Generation#
Use sequences for @Id columns:
@Id
@SequenceGenerator(name "gen_name", sequenceName = "…", schema = "…")
@GeneratedValue(generator = "gen_name")
Use default for non-primary key columns
ALTER TABLE pimcatalog.BUNDLE_MASTER_INFO add constraint df_bundle_cin default next value for pimcatalog.bundle_id_seq for CONSUMER_ITEM_NUMBER;
Use saveAndFlush to get the updated entities having some column values as default.