I hereby claim:
- I am bombe on github.
- I am bombe (https://keybase.io/bombe) on keybase.
- I have a public key ASDMNNihnq4QjHGBKK2HIHT68ovfdl59MAGx7Y1lba2ztAo
To claim this, I am signing this object:
I hereby claim:
To claim this, I am signing this object:
| import java.awt.* | |
| import java.awt.SystemColor.* | |
| import java.io.* | |
| import java.nio.charset.* | |
| import java.nio.file.* | |
| import java.time.* | |
| import java.time.DayOfWeek.* | |
| import java.time.Month.* | |
| import java.time.temporal.* |
I switched a codebase from EclipseLink as JPA provider to Hibernate and found out that with Hibernate you can not use inheritance in event listener classes. The JPA specs do not go into much detail on this topic so JPA providers are bound to handle this different from one another.
I separated my entity listeners from my entities even though it is possible to add methods annotated with e.g. @PostPersist directly in the entity class. The entity listeners themselves were less than trivial but only slightly so: I created a generic base class for all entity listeners and specialized subclasses for each entity.
public class EntityListenerBase<T> {
@PostPersist
public void postPersisted(T object) {
SomeEventBus.sendEvent(createPostPersistEvent(object));
When testing your JPA entity handling code with a real entity manager it will not only write your entities to a real database, it will also call all entity listeners you have defined. Your entity listeners might be easy to fix but sometimes it’s just better to remove the entity listeners from the entity manager so they are ignored.
Entity listeners are methods in the entity class annotated with special annotation (such as @PerPersist or @PostDelete), or they can be defined in custom classes which are associated with the entity using the @EntityListeners annotation on the entity itself.
Depending on your entity listeners it can be advantageous to disable all entity listeners during tests instead of trying to get them to run during tests; they might access singletons or frameworks that are not active during tests, and mocking or stubbing those would seriously distract from the test itself.
How entity listeners are created from annotations and
| #!/bin/bash | |
| # 8e38d288-e581-44f3-bf47-bb0962d25b63 | |
| function client_hello() { | |
| echo "ClientHello" | |
| echo "Name=${1}" | |
| echo "ExpectedVersion=2.0" | |
| echo "EndMessage" | |
| } |
| package main | |
| import "fmt" | |
| import "time" | |
| func main() { | |
| current_time := time.Now() | |
| time_in_millis := current_time.Hour()*(3600*1000) + current_time.Minute()*(60*1000) + current_time.Second()*(1000) + (current_time.Nanosecond() / 1000000) | |
| time_in_metric := time_in_millis * 100000 / (86400 * 1000) | |
| fmt.Printf("%d:%02d:%02d\n", time_in_metric/10000, (time_in_metric/100)%100, time_in_metric%100) |