Replies: 2 comments
-
Hibernate/JPA use reflection, nothing can be done about that, but at least it is isolated only to your entity model It is pretty simple to get going with Micronaut Launch and JPA:
Modify content to: package jpa.example;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
@Entity
class Person {
@Id
@GeneratedValue
private Long id;
private String name;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
package jpa.example;
import io.micronaut.test.extensions.junit5.annotation.MicronautTest;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Assertions;
import javax.inject.Inject;
@MicronautTest
public class JpaExampleTest {
@Inject
PersonRepository repository;
@Test
void testItWorks() {
Assertions.assertEquals(0, repository.count());
}
}
|
Beta Was this translation helpful? Give feedback.
-
Thanks. I totally agree with "... It is pretty simple to get going with Micronaut Launch and JPA...". You have answered half of my question. You said "... Hibernate/JPA use reflection, nothing can be done about that". And my straight question is: is not it against or downgrade the advantage of Micronaut AOT feature? I guess yes, right? And what about spring-data? If I add spring-data dependency am I adding reflection on top of Micronaut, right? If not, I would seriously consider use Spring-data dependencies like spring-boot-starter-data-mongodb-reactive beacuse it has been a nightmare work with Micronaut and access database like MongoDb. You may argue that the using Hibernate is quite straighforward but assuming I don't want to use Hibernate because I don't the pain of its performance. What do you recomend when using Micronaut in high performance scenarious with MongoDb or ElasticSearch. You don't use your above suggestion, right? |
Beta Was this translation helpful? Give feedback.
-
So my question is: if I added Spring Data or Hibernate to Micronaut am I not going to lose somehow the AOT benefits of Micronaut? I am adding reflection and caches engine, am not I? If not, I would prefer mix Micronaut with Spring-data to make my life easier.
Main current goal: I want to code "gRPC Web Application/Kafka Producer" microservice which saves the request message in database before posting it to Kafka topic and another Kafka consumer microservice which listen such topic and save in other database. Both saving must be done without HiIbernat in order to be faster as possible and avoid unnecessary crud repositories. Addionaly I am preparing my knowledge for Reactive design similar as we can easily reach with Spring-Data-Reactive drivers. The gRPC and Kafka part are working but saving to database without using Hibernate has caused me headakes (you will find few questions on StackOverFlow from me trying to simply insert a record either with micronaut-vertx-mysql-client or micronaut-mongo-reactive)
Context: I work in a big company and, after long and careful searches, we shift our main stack to rely on Micronaut. I am studing and trying to code commun and basic Hello Worlds in typical scnearios with Micronaut and avoiding add Spring. The motivation is exactly this statement:
Copied from micronaut.io
FAST STARTUP TIME — LOW MEMORY CONSUMPTION
Reflection-based IoC frameworks load and cache reflection data for every single field, method, and constructor in your code, whereas with Micronaut®, your application startup time and memory consumption are not bound to the size of your codebase.
Well, after watching several devvox and reading many blogs I am convinced that Spring increase the consunption of memory caused by reflection. I am not expert to dive deep in frameworks and compare them but the arguments I have studied seems reasonable enough for believe in it. So far so good.
Nevertheless, I am surprise how much effort I have invested to create a simple Hello World accessing databases and I am still completely stuck. The start point is always micronaut.launch so I assume I am picking up dependencies well tested.
I am sure if I was trying same Hello World using Spring Data or simply Hibernate I was done quickly.
PS. in this question I want learn fundamentals but if you had any hello world working to save to a NoSql database and another to relational dabase I will be so gratefull if you share with me or give me tricks in one of my questions bellow. All questions bellow are some issue I falled down because I started from Micronaut.launch dependencies and I avoid typical Spring Data uses.
1
https://stackoverflow.com/questions/64886249/how-execute-an-object-which-was-wrapped-into-a-reference-object-to-be-modified-w
2
https://stackoverflow.com/questions/64885819/io-vertx-mysqlclient-mysqlpool-query-execute-is-never-really-executed-and-r
3
https://stackoverflow.com/questions/64866719/connecting-to-mysql-causing-connection-refused-no-further-information
4
https://stackoverflow.com/questions/64852970/how-save-document-to-mongodb-with-com-mongodb-reactivestreams-client
5
https://stackoverflow.com/questions/64840834/how-retrieve-and-add-new-document-to-mongodb-collection-throw-com-mongodb-reacti
Beta Was this translation helpful? Give feedback.
All reactions