jhipster / generator-jhipster-micronaut

Micronaut blueprint for JHipster

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support entity filtering

amatosg opened this issue · comments

Overview of the issue

After I imported a JDL file, every repository was missing the JpaSpecificationExecutor dependency

Reproduce the error
  • Create a MN project
  • Import a JDL file
Related issues

None

Suggest a Fix

add this to the pom file

<dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-jpa</artifactId>
    <version>2.2.7.RELEASE</version>
</dependency>

Add the import in the Repository generator

import org.springframework.data.jpa.repository.JpaSpecificationExecutor;

EDIT:

When using JpaSpecificationExecutor, the method findAll in EntityQueryService is expecting Spring's Pageable, but is receiving Micronaut's Pageable. The import won't fix the issue :(

  • Checking this box is mandatory (this is just to show you read everything)

I don't think we should be using Spring for this. @amatosg would you attach a JDL that shows the problem?

I think the issue is with filtering not being yet supported?

Here's the file:

entity Region {
	regionName String
}

entity Country {
	countryName String
}

// an ignored comment
/** not an ignored comment */
entity Location {
	streetAddress String,
	postalCode String,
	city String,
	stateProvince String
}

entity Department {
	departmentName String required
}

/**
 * Task entity.
 * @author The JHipster team.
 */
entity Task {
	title String,
	description String
}

/**
 * The Employee entity.
 */
entity Employee {
	/**
	* The firstname attribute.
	*/
	firstName String,
	lastName String,
	email String,
	phoneNumber String,
	hireDate Instant,
	salary Long,
	commissionPct Long
}

entity Job {
	jobTitle String,
	minSalary Long,
	maxSalary Long
}

entity JobHistory {
	startDate Instant,
	endDate Instant,
	language Language
}

enum Language {
    FRENCH, ENGLISH, SPANISH
}

relationship OneToOne {
	Country{region} to Region
}

relationship OneToOne {
	Location{country} to Country
}

relationship OneToOne {
	Department{location} to Location
}

relationship ManyToMany {
	Job{task(title)} to Task{job}
}

// defining multiple OneToMany relationships with comments
relationship OneToMany {
	Employee{job} to Job,
	/**
	* A relationship
	*/
	Department{employee} to
	/**
	* Another side of the same relationship
	*/
	Employee
}

relationship ManyToOne {
	Employee{manager} to Employee
}

// defining multiple oneToOne relationships
relationship OneToOne {
	JobHistory{job} to Job,
	JobHistory{department} to Department,
	JobHistory{employee} to Employee
}

// Set an angular suffix
// angularSuffix * with mySuffix
paginate * with pagination
dto * with mapstruct
service all with serviceImpl
filter *

You're right. If you generate a new entity and say that you want to add filtering, it shows this issue.
image

I've added the bug label because the prompts allow for this situation.

It would be great to see filtering in all framework, whether it's quarkus, mn, helidon or anything else, the one implemented in main jhipster is brilliant.

Thanks @agilob , that's definitely made my day!

I would happily work on adding filtering for Micronaut, if no one else has started working on yet.

As neither Micronaut, and AFAIK nor Quarkus supports any dynamic criteria builder out of box, apart from what is available in JPA/Hibernate, I can imagine the following implementation:

  • using JPA Criteria API
    • pro: JPA is nearly universal, no extra dependency
    • cons: the API is not the most ergonomic, and it works only with JPA (which could be a problem, if every we want to add MongoDB support, or support reactive apps)
  • using QueryDSL
    • pro: nice, high level API. Supports MongoDB too
    • cons: extra dependency
  • using jOOQ
    • pro: nice, high level API, a bit closer to the SQL semantics, so I think, if someone wants to extend the generated code with advanced SQL features, they have an easier route (it's a subjective impression)
    • cons: extra dependency

QueryDSL has ~3k and jOOQ has ~4k stars on Github, based on Google trends jOOQ is a bit more popular.
What do you think, what should we use?

I started work on the subject a few days ago (mainly thinking about solutions).
My plan is to try to use micronaut support for Spring Data JPA specification.

I use JPA, but, IMHO it would be fair to also support other others

With micronaut-spring-data-jpa, the necessary changes are surprisingly small.
However, these spring dependencies are sort of cheating 😉 Ideally, we would need to separate the jhipster-framework to several smaller module, for example to jhipster-spring-framework / jhipster-spring-reactive / jhipster-jpa / etc ... and put the necessary supporting code there, so the generated pom could be smaller, and more focused on only the crucial dependencies.

IMO starting with micronaut-spring-data-jpa is a good enough solution, until micronaut-data supports dynamic query criteria: micronaut-projects/micronaut-data#89

Have you encountered "org.hibernate.HibernateException: Could not obtain transaction-synchronized Session for current thread" with this implementation? This is where I've stopped working on this.

Have you encountered "org.hibernate.HibernateException: Could not obtain transaction-synchronized Session for current thread" with this implementation? This is where I've stopped working on this.

Yes. Adding micronaut-spring dependency solves the issue.

hi! any update on this issue? 😃

Any updates on this issue? Looks like a lot has been done.