Custom numbers in Jhipster jdl - java

I am trying to modify my existing entity using the .jdl file for jhipster.
Now, my requirement for the field is to have only numbers till 1 to 10.
I know this can be easily handled in the fronted or the ts file.
However, is there any way JHipster can do it ??
For example we have maxlength and minlength attributes for a field:
entity test {
label String required minlength(3);
}
Thank you in advance.

Thank you... I guess this problem can be solved using the pattern where I can add my custom regular expression.
Issue Resolved

Related

swagger 2.0 - how to solve same response class names in different packages issue in spring boot application

For example there are two classes with same name Group in different packages.
But when referring to models in swagger ui only one model is being shown and even the response mapping is not proper, swagger is incorrectly referring to these models.
Yes. Adding the below property solves this issue.
springdoc.use-fqn=true
But after adding this, the schemas in swagger ui start showing up with the complete package name. To avoid this try annotating your model classes with:
#Schema(name = "class name to be displayed")
I meet the same problem today with springdoc-openapi-ui:1.5.9, and maybe solved it.
Simply add key-value pairs to application.properties.
springdoc.use-fqn=true
Then org.springdoc.core.SpringDocConfigProperties read this value, and pass it to io.swagger.v3.core.jackson.TypeNameResolver.

include_in_all setting in spring data elasticsearch

According to Elasticsearch documentation it is possible to exclude a field from _all field using include_in_all setting (set to false). I need to exclude a field from _all and I'm using spring data elasticsearch do define my mappings. I haven't found a way to do it this way.
Is this possible using spring data elasticsearch annotations?
Unfortunately, Spring Data Elasticsearch cannot do this thing. The improvement request is already a year old, but its priority is minor, so there is no hope for now:
https://jira.spring.io/browse/DATAES-226
In my last project I had to do a lot of simple searches (instead of one by "_all" fields, I used 1 search per each field), and then I united all the results. I assume that there is no nice solve for that problem by Spring Data Elasticsearch.
You can save the mapping of your type into a json file. Then you add the '"include_in_all": false' to the field you want to exclude. This should look something like this.
{
"my_type": {
"properties": {
"excludedField": {
"type": "text",
"include_in_all": false
}
}
}
}
Then you load the file using your favorite JSON reader, parse it as a string and change your mapping with the elasticsearch api .
client.admin().indices()
.preparePutMapping("my_index")
.setType("my_type")
.setSource(loadedFileString)
.get();
EDIT: I just noticed you wanted to use annotations for it. Maybe the #Field annotation has a parameter for it? I'm sorry, I have no experience with the annotations.

Java Spring 4 JSON response - missing attributes

I'm using Spring 4 JPQL / Criteria API to get results for aggregate query, i've created the special constructor in the entity class (with sum and key) and it works without any issues, however the return JSON does not return all the attributes from that class...any idea how I can control what the JSON return structure is? What's even weirder - when running in debug mode then in the following break point:
List<ActivityResponse> tActivityResponses = responseRepository.getTRXByMonths(months);
return tActivityResponses;
I am looking at the list and each member of the model class has the correct attributes, like month but month does not appear in the JSON.
Thanks.
Thanks everyone for the replies, i found the answer:
In the REST config class I had to specify config.exposeIdsFor(class name), and that showed all those missing fields.
Thanks.

Get annotation parameter with IntelliJ IDEA structural search

I'm trying to generate named queries for JPA entities using table name specified in #Table annotation with structural search and replace.
So to start I'm trying the following template:
#Table($param$ = $value$)
public class $clazz$
I have many classes like:
#Table(name = "Some Table")
public class SomeClass
and if I replace with the same template, it correctly grabs that $param$ is name, $clazz$ is correct class name, but $value$ is empty.
I'm using IDEA 12 build 128.101
What am I doing wrong? Thank you.
I think this issue was already reported a long time ago, but no one seems to care about it. Try voting up the ticket in youtrack.

All my fields have a prefix. How can I tell that to hibernate?

E.g. I have:
#Column(name = "username")
private String m_username;
Note that the #Column annotation only affects the database column name.
Hibernate still thinks the name of the property is 'm_username'.
How can I tell Hibernate that the property name is just 'username'?
Please tell me there is a way to do this...
Edit: I removed the #AccessType annotation in my code example, as it is not relevant for this question.
Update: After switching everything to field access, this exception happens:
org.hibernate.QueryException: could not resolve property: username of: mypackage.model.User
It happens here:
Criteria criteria = session.createCriteria(User.class);
criteria.add(Restrictions.eq("username", username));
User result = (User) criteria.uniqueResult();
And the reason is most likely that hibernate only 'knows' of a property called 'm_username', while I think of it and program against a property named 'username'. Also note that my getters/setters are called: "getUsername()" and "setUsername(String value)" (automatically generated).
why do you use AccessType.PROPERTY?
remove it and it is accessed by 'field'.
do not mix field and property annotations. stick to one or the other.
As per my knowledge we can't* .
There is still one issue with the way hibernate looks up the methods
for a given property name.
Suppose you have a property with a name like "mProperty" (first
lowercase, second uppercase, rest doesn't matter). Not the accessor
methods in the source code will be getMProperty and setMProperty.
The way BasicPropertyAccessor.getterMethod is implemented in that way .
I found one lead here: https://forum.hibernate.org/viewtopic.php?f=1&t=943110
But the thread is 7 years old and I don't know how to apply this to annotation based configuration (I don't have an xml configuration file).

Categories

Resources