Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
77thAirhacksQ&A.md

Ask questions and see you at August, 3rd, 8.PM. CET: https://vimeo.com/event/154379

Also checkout recent episode:

76th airhacks.tv

Please keep the questions Jakarta EE-stic. Means: as short and as concise as only possible. Feel free to ask several, shorter questions.

Upcoming airhacks.tv events are also going to be announced at meetup.com/airhacks

@Bukama

This comment has been minimized.

Copy link

@Bukama Bukama commented Jul 12, 2020

We have following setup:

An abstract GenericDAO class which provides general methods like find() and the EntityManager which it gets injected. The EnitiyManager is produced by a producer class using @Produces. Then each concrete DAO class extends the abstract one and therefor only needs to implements its concrete context base methods to create queries (using CriteriaAPI) and execute them using the inherited EnitiyManager.

Now we are struggling how to test those classes / our queries to see if they are returning the correct / expected values. I don't want to test the service which uses the DAO classes, there I can use mocks, but I want to test our queries. Of course the database can be a real one or a containerized using testcontainers thats not the point.

If I understand you right, that's exactly a case to use Arquillian to get the CDI and TX context done, am I?

@AdamBien

This comment has been minimized.

Copy link
Owner Author

@AdamBien AdamBien commented Jul 13, 2020

Bulkhead behavior / scope clarification in future MicroProfile versions

@AlexeyMalkovskiy

This comment has been minimized.

Copy link

@AlexeyMalkovskiy AlexeyMalkovskiy commented Jul 22, 2020

Hi Adam,
If I have master-detail entities relationship, e.g. Departmnet-employees and I want in the REST endpoint serialize only master entity, what is the best option to do that? I can create DTO without this details entity or I can just set it to null, when I out of transaction scope. What do you do in the similar situations?

@Bukama

This comment has been minimized.

Copy link

@Bukama Bukama commented Jul 23, 2020

Hi Adam,
If I have master-detail entities relationship, e.g. Departmnet-employees and I want in the REST endpoint serialize only master entity, what is the best option to do that? I can create DTO without this details entity or I can just set it to null, when I out of transaction scope. What do you do in the similar situations?

Always use DTO, never expose your entities!

@AlexeyMalkovskiy

This comment has been minimized.

Copy link

@AlexeyMalkovskiy AlexeyMalkovskiy commented Jul 27, 2020

But actually entity in the detached state is a DTO.

@Bukama

This comment has been minimized.

Copy link

@Bukama Bukama commented Jul 28, 2020

But actually entity in the detached state is a DTO.

But you expose your database structure and (mostly) information not needed for the API but which are present in the entities.

@AlexeyMalkovskiy

This comment has been minimized.

Copy link

@AlexeyMalkovskiy AlexeyMalkovskiy commented Jul 28, 2020

I don't see any problem with exposing entities structure because it usually reflects the real world objects. And json-b by default don't serialize null fields, so I won't send any redundant information if I set to null fields which UI doesn't need. That is why I'm interested in Adam's opinion about that. Set one field to null looks more productive than copy other fields to a new object. I think DTO is useful when we need a response with different structure than existing entities or we need some non default json-b mapping.

@AdamBien

This comment has been minimized.

Copy link
Owner Author

@AdamBien AdamBien commented Aug 3, 2020

@AdamBien

This comment has been minimized.

Copy link
Owner Author

@AdamBien AdamBien commented Aug 3, 2020

"I have a couple of JavaEE micros in prod for 2+ years running on thorntail. Openshift. Would you say Quarkus is stable enough to make the effort and migrate them or just move them back to Wildfly now it supports microprofile?"

--@aviles (@Aviles_Tri) https://twitter.com/Aviles_Tri/status/1289998048865574912

@thehpi

This comment has been minimized.

Copy link

@thehpi thehpi commented Aug 3, 2020

If I have two jaxrs endpoints, one producing json, one producing xml, is there a generic way to also produce json or xml when an error occurs?
I want to use one exception mapper that e.g returns an object which is automatically converted Into json or xml based on the @produces settings

@thehpi

This comment has been minimized.

Copy link

@thehpi thehpi commented Aug 3, 2020

Using JPA it is easy to add tables, relations etc. But how do you manage the db update in production? Do you use tools like liquibase or flyway or is there support within JPA for this? I guess I would need migration scripts to be executed. Can they be generated?

@thehpi

This comment has been minimized.

Copy link

@thehpi thehpi commented Aug 3, 2020

If there is one database but I have several servers e.g. in the cloud in different servers in different zone’s, how would you handle the entity manager cache? Changes in one server are not visible to another.

@thehpi

This comment has been minimized.

Copy link

@thehpi thehpi commented Aug 3, 2020

Can I enable SQL logging in payara without requiring to put the (e.g. eclipse link) logging properties in the persistence.xml?

@thehpi

This comment has been minimized.

Copy link

@thehpi thehpi commented Aug 3, 2020

Sometimes when a bigger application is deployed, you cannot redeploy and need to restart payara.
What can be reasons for this? Is there an easy way to find out what causes it?

@thehpi

This comment has been minimized.

Copy link

@thehpi thehpi commented Aug 3, 2020

Which do you prefer: @transactional or @TransactionManagementType.BEAN, and why?

@thehpi

This comment has been minimized.

Copy link

@thehpi thehpi commented Aug 3, 2020

I use JaxRS (jersey) where my DTO objects are automagically (de)serialized.
Is there a generic way to configure jaxrs to allow unknown fields?
Or is this up to the (de)serialization provider?

@thehpi

This comment has been minimized.

Copy link

@thehpi thehpi commented Aug 3, 2020

Is it possible to specify an element name once for xml and json (now I need XmlElement and JsonbProperty)

@thehpi

This comment has been minimized.

Copy link

@thehpi thehpi commented Aug 3, 2020

Can I specify the field naming strategy in a generic way for xml and json? Eg. I want snake case for json and xml?

@thehpi

This comment has been minimized.

Copy link

@thehpi thehpi commented Aug 3, 2020

When JPA manages the transaction, what happens if e.g. in payara the max jdbc connection count is reached.
Is there a way to influence this?

@thehpi

This comment has been minimized.

Copy link

@thehpi thehpi commented Aug 3, 2020

How can I monitor the number of beans in the EJB pool in payara?

@thehpi

This comment has been minimized.

Copy link

@thehpi thehpi commented Aug 3, 2020

Is it possible to have an executor with multiple threads where a thread acts as an execution pipe for a session?
So that all work for a session is sequentialized within that pipe?

The executor threads would then need to be linked to e.g. a session id.

@dempile

This comment has been minimized.

Copy link

@dempile dempile commented Aug 3, 2020

Hi Adam,
When using MicroProfile Metrics to retrieve business metrics, how would you store the metrics to prevent loosing metrics data if the server stops or restart.
Thanks

@AdamBien

This comment has been minimized.

Copy link
Owner Author

@AdamBien AdamBien commented Aug 3, 2020

@FDelporte

This comment has been minimized.

Copy link

@FDelporte FDelporte commented Aug 3, 2020

Thanks for mentioning my blog post. FYI based on feedback on it, for a potential follow-up blog post, I tried to set up an initial helidon example but am I right there is no similar approach as Quarkus/Panache available so needs more "complicated" code and configuration? This guide https://helidon.io/docs/latest/#/mp/guides/09_jpa doesn't invite really to test further... ;-)

@leon-g96

This comment has been minimized.

Copy link

@leon-g96 leon-g96 commented Aug 7, 2020

Hello Adam, asking here because i don't find 78th Q&A gist.

I'm experimenting/learning Microservices with Java (Quarkus in this case). I have one boundary resource where clients use to create something. I want to do like this: After client calls resource, I want to commit the entity in database first with status of AWAITING_ACCEPTANCE, and return to client with message that he now can track status of entity in /resources/get/id. After persisting to database with status AWAITING_ACCEPTANCE, I want to publish message to Kafka topic and let my other microservice subscribe to that message and so on...

I have one @transactional class with method like this
create(TheEntity en) {
en.persist(); // using quarkus panache
kafka.publish();
}

Is it safe to do like this?
Can it happen that even after en.persist(), maybe JPA not catch any eventual error in database? And if it doesn't catch, in that case I am publishing now non-reliable message to topic? And the whole entity now across microservices is non-reliable...

Is the @PostPersist callback really called after entity has been successfully written to database. Can it happen any error in database itself, and even in that case the callback @PostPersist is fired??

How to publish message to topic after fully success entity is written to database?

--Thanks

@leon-g96

This comment has been minimized.

Copy link

@leon-g96 leon-g96 commented Aug 7, 2020

And two more questions

  1. Is there anyway to monitor JTA transaction with MicroProfile metrics out out the box? Like for e.g. in application server where you can monitor in admin console?
    Or this is not done by MicroProfile out of the box? In that case I was thinking to use callbacks of JPA and then use MetricsRegistry to register every callback?

  2. In microservices application with Java, should you create exceptions like for .e.g. CustomerNotFoundException, SomethingElseException and each of these exceptions extends RuntimeException. I want maybe to throw them maybe inside a lambda expression, or just throw them from a method? Or should I create one more generic exception that extends WebApplicationException and each time that it happens any exception just to throw that exception with maybe Response-Header cause with my own message, or non header but maybe Response.Status.Ok but with json message with description what failed?

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment