In the project I work with Hibernate ORM version 4.2.6.Final previously was used. Now I'm trying to update it to the latest release, which is 4.3.10.Final. However, org.hibernate.service.jdbc.connections.internal.DatasourceConnectionProviderImpl is no longer mentioned in the docs and no longer supplied.
This is how this class is used in the code I work with:
( (DatasourceConnectionProviderImpl) (
(SessionFactoryImpl) getDAO().getSessionFactory() )
.getConnectionProvider() )
.setDataSource(ds);
What can it be replaced with? And where can I find the mention of its removal in the Hibernate docs or release notes?
Finally, by using GrepCode.com multi-repository search engine I figured out that DatasourceConnectionProviderImpl class was not actually removed. Instead, since Hibernate 4.3.0, some classes are moved:
from org.hibernate.service.jdbc.connections.internal
to org.hibernate.engine.jdbc.connections.internal.
So import statement has to be changed to
import org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl;
Related
Let's have a simple MongoDB Document class with Lombok annotations
import lombok.Data;
import com.mongodb.lang.NonNull;
import org.springframework.data.mongodb.core.mapping.Document;
#Document
#Data
public class Car {
#NonNull
private String plate;
}
and simple test
#Test
public void test() {
Car c = new Car();
c.setPlate(null);
}
With Lombok v1.18.22 this worked well and test succeeded. However since v1.18.24, the test starts to fail since apparently Lombok now understands more annotations that indicate that field/param shouldn't be null
https://projectlombok.org/changelog
I'm not sure if MongoDB uses these #NonNull annotations for anything (I think not?) but at least for a documentation purposes it's nice to have them. Also the field can be null in some cases for MongoDB documents f.e. when using Spring Data's filtering using Example
repository.findByExample(Example.of(car))
where I might filter by only some specific field, leaving also mandatory fields to null.
If it'd be about #lombok.NonNull then I'd simply remove it but I don't want to remove Mongo annotations just because of Lombok. Thus my question:
Question 1: Can I avoid these checks? Or can I turn this feature off? So either that Lombok will consider only lombok.* annotations or just suppress generation of null checks in general.
Second issue is that Intellij Idea Lombok plugin apparently doesn't know about this feature yet so it considers that code to be valid. The build then fails as Lombok v1.18.24 generates constructor with all the #NonNull fields so it can't call new Car(). With #lombok.NonNull it works well in Intellij but with Mongo's NonNull it doesn't. I'm using IntelliJ IDEA 2022.1.3 (Community Edition)
Question 2: Is this a bug in Intellij Idea or its Lombok plugin? If yes is it known? I haven't found any info about it which leads me to the idea that the error is on my side
I am using Openapi generator(5.4.0), with spring (generator name) and gradle, I am trying to add an import to a generated model.
For the particular field in the api spec, I have added:
x-field-extra-annotation: "#com.fasterxml.jackson.annotation.JsonFormat ...."
This works, however I dont want to fully qualify it, and have the com.fasterxml.jackson.annotation.JsonFormat import added.
I tried adding typeMappings to genratedCode task, but that doesn't work.
importMappings = [
'JsonFormat' : 'com.fasterxml.jackson.annotation.JsonFormat'
]
Update:
I can add model.mustache template to project, and add the import. ie
{{#useBeanValidation}}
...
import com.fasterxml.jackson.annotation.JsonFormat;
...
{{/useBeanValidation}}
Any ideas? Better ways.
Thanks.
There is no production-ready solution (yet!)
If you are not starving for this feature, wait for acceptance of related issue and PR to one of the nearest releases.
https://github.com/OpenAPITools/openapi-generator/issues/13938
It will allow required customizations using
x-spring-constraint: #MyAnnotation(value = 1, message = "nice") (or x-java-constraint) extension with configOption
customValidationAnnotationsPackages="my.custom.package.MyAnnotaion;my.other.package.*"
Else, refer to https://bartko-mat.medium.com/openapi-generator-to-spring-boot-with-custom-java-validations-623381df9215 as tutorial for handmade solution
I'm currently updating the codebase for a project that I found on Github that uses a handy search feature.
I've updated most of the codebase however I keep getting issues similar to the post title, I have suppressed lint a number of times using the following code:
//noinspection RestrictedApi
It seems to work at suppressing code inside my methods however there's a piece of code where I must implement a MenuPresenter interface which can be found in the following library:
import androidx.appcompat.view.menu.MenuPresenter;
The implementation:
public class MenuPopupHelper implements AdapterView.OnItemClickListener, View.OnKeyListener,
ViewTreeObserver.OnGlobalLayoutListener, PopupWindow.OnDismissListener,
MenuPresenter {}
There doesn't seem to be any android documentation on androidx.appcompat.view.menu.MenuPresenter. Any ideas on how I can work around this issue?
Starting from jOOQ 3.14, when using jOOQ with code like this:
DSL.val(1);
I like to assign the above expression to a local variable, so I'm using the Eclipse IDE quick fix action "Assign statement to new local variable", which adds this import:
import org.jetbrains.annotations.NotNull;
And produces this code:
#NotNull
Param<Integer> val = DSL.val(1);
This doesn't happen with IntelliJ whose "Introduce local variable" quick fix produces the desired code:
Param<Integer> val = DSL.val(1);
How can the unwanted insertion of the #NotNull annotation be prevented?
There's a pending bug in Eclipse to fix this: https://bugs.eclipse.org/bugs/show_bug.cgi?id=565463. The rationale of the current behaviour (still present in 2020-12 (4.18.0)) can be seen in that issue.
A workaround is to turn on annotation-based null analysis in Preferences > Java Compiler > Errors/Warnings > Enable annotation-based null analysis
... and setting the jetbrains annotations as the primary and/or secondary annotations:
Eclipse may not find the annotations, in case of which a workaround for this may be to manually edit your project's .settings/org.eclipse.jdt.core.prefs file, adding these:
org.eclipse.jdt.core.compiler.annotation.nonnull=org.jetbrains.annotations.NotNull
org.eclipse.jdt.core.compiler.annotation.nullable=org.jetbrains.annotations.Nullable
org.eclipse.jdt.core.compiler.annotation.nullanalysis=enabled
The side effect of this workaround is of course that null analysis is now active on jOOQ code, which may or may not be what you want.
I have successfully created an Acceleo module for M2T purposes and am trying to execute it from a Java program.
This is what I tried :
String[] str = {"/home/hamza/workspace/HLRedundancy/model/System1.xmi", "/home/hamza/workspace/HLRedundancy/"};
Generate.main(str);
Generate being the name of the Acceleo module I created and thus, the name of the Java class containing the Acceleo generation methods.
Here is the error I'm always getting :
Exception in thread "main" org.eclipse.acceleo.engine.AcceleoEvaluationException: The type of the first parameter of the main template named 'generateElement' is a proxy.
at org.eclipse.acceleo.engine.service.AcceleoService.doGenerate(AcceleoService.java:566)
at org.eclipse.acceleo.engine.service.AbstractAcceleoGenerator.generate(AbstractAcceleoGenerator.java:193)
at org.eclipse.acceleo.engine.service.AbstractAcceleoGenerator.doGenerate(AbstractAcceleoGenerator.java:158)
at HighLevelGenerator.main.Generate.doGenerate(Generate.java:250)
at HighLevelGenerator.main.Generate.main(Generate.java:160)
at Execute.main(Execute.java:11)
I've been searching for a while about this error but I have no idea about its cause.
Any idea about a solution to my problem ?
Thanks
The most common cause of this issue is failure in properly registering the metamodel and factory corresponding to your inpu model (System1.xmi).
If you look at the comments in the generated class "Generate.java", you will notice a number of places where we indicate steps to follow if running in standalone. The most important begin registerPackages where you are required to register your metamodel.
If you debug the launch down to the point where the model is loaded (place a breakpoint right after the line model = ModelUtils.load(newModelURI, modelResourceSet);), you can look at the model.eResource().getErrors() list to see whether there were errors loading your model.
You might also be interested in looking at this video describing the process (registration required) .
Check out the first line of your acceleo module,
what is the URI of the metamodel? Does it start with 'http://' ?
Maybe this can help:
Acceleo stand alone - first parameter is proxy
This issue happen when your meta model contains sub-packages and the top package not contain any class.
to solve the problem, add a Dummy class the the top package and regenerate the meta-model code. It worked fine for me.