42bv / jarb Goto Github PK
View Code? Open in Web Editor NEWJARB - JAva Repository Bridge
JARB - JAva Repository Bridge
Create SQL database populator that runs all files in a directory alphabetically:
/mydir
001.sql
002.sql
return new PopulateApplicationListenerBuilder()
.initializer()
.add(new DirectorySqDatabasePopulator(ClassPathResource("mydir")))
The link in the README.md
and pom.xml
is incorrect, or not working correctly: http://www.jarbframework.org/
Currently you are restricted to create one class for one named constraint. But in most cases you can group constraints for a single purpose error.
For one of our projects, I had the following structure inside one of the persistable entities:
@Transient
private final Map<UUID, List<String>> entityIdsWithSomething = new ConcurrentHashMap<>(); // Only for CSV import of XXX
When accessing the /constraints
endpoint, which is provided by BeanConstraintController
, the following error is thrown:
10-09-2020 11:14:21.282 ERROR [080-exec-1] l._42.xxx.config.web.errorhandling.ControllerExceptionAdvice:122 Handling request, for [nl._42.jarb.constraint.metadata.BeanConstraintController#describeAll()], resulted in the following exception.
java.lang.ClassCastException: class sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl cannot be cast to class java.lang.Class (sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl and java.lang.Class are in module java.base of loader 'bootstrap')
at nl._42.jarb.constraint.metadata.BeanConstraintDescriptor.describeBean(BeanConstraintDescriptor.java:85)
at nl._42.jarb.constraint.metadata.BeanConstraintService.describe(BeanConstraintService.java:56)
at nl._42.jarb.constraint.metadata.BeanConstraintService.describeAll(BeanConstraintService.java:30)
at nl._42.jarb.constraint.metadata.BeanConstraintController.describeAll(BeanConstraintController.java:25)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:105)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:878)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:792)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:626)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:733)
This seems to be caused by
Which assumes that parameterizedType.getActualTypeArguments()
always returns a Class
, but this is not the case if another generic type is present (in this case: List<String>
).
See https://stackoverflow.com/questions/24829146/classcastexceptionjava-lang-class-cannot-be-cast-to-java-lang-reflect-parameter in which this is explained.
Something should be changed in the BeanConstraintsDescriptor
to handle cases like this (or as a quick fix: if the field is annotated with @Transient
, then simply skip processing it)
Provide support to load data into the database by CSV, as variation to excel. Might also rename the populator-excel to populator-workbook.
Optional check on startup to see if all named constraints on the database have a concrete exception.
To enable usage for projects where java 7 is not yet possible
I had to make some changes to the poms in order to get jarb working in my environment. Some is specific to how I have things setup but I think there is opportunity to enhance the ease of bootstrapping Jarb. Some of these issues are only seen when bootstrapping in a pristine env like CI. The changes can be seen at https://github.com/gabe97330/jarb/commits/gabe97330.
One is commons-io: gabe97330@cf85469 which I'm not sure what is going on there as it seems to be using a 1.x groupId for the 2.x artifact.
Another is for groovy-liquibase at gabe97330@a6f7a4c. This is a larger issue related to how to incorporate groovy-liquibase since its not staged anywhere. Jarb seems to be using a different set of coordinates for groovy-liquibase than what it specifies in its Gradle build script. I'm not Gradle savvy so I did a very minimal change to its build script to at least do an install to the local maven cache so I could then refer to it from the modified Jarb script. This then required also including a reference to groovy since Gradle will not output transitive dependencies to the maven POM for groovy using a simple ref to the maven plugin.
Finally, the version of hsqldb that Jarb is referring to wasn't being discovered on the repos that I have configured so I changed it: gabe97330@975a766. You may want to include the list of repos you pull from for reference purposes.
When using JaRB with Hibernate 5, the getDataSource method throws the following Exception:
Caused by: java.lang.NoSuchMethodError: org.hibernate.jpa.HibernateEntityManagerFactory.getSessionFactory()Lorg/hibernate/SessionFactory;
at org.jarbframework.utils.orm.hibernate.HibernateUtils.getDataSource(HibernateUtils.java:19)
at org.jarbframework.constraint.DatabaseConstraintsConfiguration.afterPropertiesSet(DatabaseConstraintsConfiguration.java:152)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
I want to know if it is compatible with MongoDB. If not, then can anyone suggest me one?
To make the configuration of JaRB as easy as possible, we should provide (at least) XML namespace support. My proposal looks as follows, but feedback is always welcome.
Populator:
<jarb:populator>
<jarb:sql resource="classpath:import.sql" ignoreIfMissing=true dataSource-ref="dataSource"/>
<jarb:excel resource="classpath:import.xlsx" ignoreIfMissing=true entityManagerFactory-ref="entityManagerFactory/>
</jarb:populator>
Where "ignoreIfMissing" has a default value of false and the reference beans, data source and entity manager factory, are smartly looked up from our application context if left unspecified. First we attempt to autowire the beans from the application context, and if multiple beans are found use their convention bean identifier "dataSource" and "entityManagerFactory". Whenever no matching bean could be found, we throw a runtime exception.
Violation translator:
<jarb:violation-translator defaultExceptionFactory-ref="x">
<jarb:violation-resolver>
<jarb:jpa-violation-resolver entityManagerFactory-ref="x"/>
</jarb:violation-resolver>
<jarb:custom-exceptions matching="exact|regex">
<jarb:custom-exception-class constraintName="uk-persons-name" exceptionClass="com.myproject.PersonNameAlreadyExistsException"/>
<jarb:custom-exception-factory constraintName="fk-persons-*">
<bean class="com.myproject.PersonsForeignKeyExceptionFactory"/>
</jarb:custom-exception-factory>
</jarb:custom-exceptions>
</jarb:violation-translator>
Database metadata repository:
<jarb:db-metadata-repository id="dbMetadataRepo" caching="true" dataSource-ref="true">
<jarb:schema-mapper>
<jarb:jpa-schema-mapper entityManagerFactory-ref="x"/>
</jarb:schema-mapper>
</jarb:db-metadata-repository>
Metadata provider:
<jarb:metadata-provider id="metadataProvider">
<jarb:metadata-enhancers>
<jarb:db-metadata metadataRepository-ref="dbMetadataRepo"/>
<jarb:jsr303-metadata/>
<bean class="com.myproject.CustomMetadataEnhancer"/>
</jarb:metadata-enhancers>
</jarb:metadata-provder>
<test-data emf="entityManagerFactory" or ds="dataSource">
<init>data.sql, data.xsl, myproject.LoadData</init>
<destroy>clean.sql, ...</destroy>
</test-data>
There are 2 issues actually:
<repositories>
<repository>
<id>codelds</id>
<url>https://code.lds.org/nexus/content/groups/main-repo</url>
</repository>
</repositories>
Also, it would be nice if the jar for constraint validation can be separated from other jars in your framework, because I believe not everyone is interested in every part of your framework.
Jarb-init tries to import SQL from files for which it is known they never contain it.
An example is the .DS_Store file generated by Finder on Mac.
If such file is executed, an epic error message is generated by the Spring framework.
See the screenshot for more details.
To me, solution seems to place certain temporary files (.DS_Store, thumbs.db etc.) on a blacklist.
Enable view models to be validated automatically on their corresponding entity properties.
@DatabaseConstrained(entity = User.class)
public UserViewModel {
private String name;
@IgnoreDatabaseConstraints
private String bla;
}
public UserViewModel {
@DatabaseConstrained(entity = User.class, property = "namez")
private String name;
private String bla;
}
@DatabaseConstrained(entity = User.class, embedded = "info.address")
public AdressViewModel {
private String street;
}
As optional replacement for basePackage(s), making it type safe.
How to inject JaRB configurable-exception-factory in CDI Container without Spring
Thanks in advance.
Cleanup the database constraint repository interface / implementation. Also create a caching database repository factory bean, removing the factory method from the class itself.
I have discovered a bug in the way that JaRB validates maximum length for numeric values with fixed-point precision (used for monetary values for instance).
Consider a column amount
in a Postgres database with a datatype of numeric(12,5)
this means that the maximum precision is 12 and the maximum scale is 5 (see https://www.postgresql.org/docs/13/datatype-numeric.html).
I used JaRB validation on this field for the backend JSR303 validations as well as the frontend validations. I entered the amount 123456789 in the field. This passed two JaRB validations:
LengthConstraintValidationStep
This validation checked that the length of the field is smaller than 12. The input value is 9 digits long so it passed.
FractionLengthConstraintValidationStep
This validation checked that fraction length is smaller than 5. The input value did not have any digits after the decimal point so this also passed.
Then, when the backend tries to insert the value the database gives an error:
Caused by: org.postgresql.util.PSQLException: ERROR: numeric field overflow
Detail: A field with precision 12, scale 5 must round to an absolute value less than 10^7.
It is correct that 123456789 cannot be inserted into the database, as the maximum length of the part before the decimal point is not 12 digits, it is 12 - 5 = 7 digits. Hence the error message that Postgres is throwing.
So I think the LengthConstraintValidationStep is performing an incorrect check for these fixed-point numeric fields.
It checks:
length of input before decimal point < precision
When it should check:
length of input before decimal point < (precision - scale)
I have a problem to catch exceptions from the database when the computer's default language is not English, I assume that you capture the text string message that throws the exception
It should be possible to add the @nullable annotation on fields, making them required=false. Overriding the database constraint.
@Nullable
@ElementCollection
@CollectionTable(name = "cars_inspections", joinColumns = @JoinColumn(name = "cars_id"))
private List<Inspection> inspections = new ArrayList<>();
Refactor the validator class, seperating validation steps from the validator
Make vendor specific resolvers easier to make by simplifying the message violation resolver API. Provide a simple "register message" method to describe an exception message.
For example:
public class PostgresViolationResolver extends RegexMessageResolver {
public PostgresViolationResolver() {
registerMessage("not null column: (\w+)", new Mapper() {
public ConstraintViolation buildViolation(Matcher) {
return new ConstraintViolation(matcher.group(1));
}
});
}
}
This could be optimized further, using a fluent API.
message(NotNull).text("not null column: ").columnName().register();
message(Unique).text("violation ").constraintName().text(" in column ").columnName().register();
etc..
As of Oracle11 we get a column size of '0' and fraction length of '-127'. Investigate how to fix this. Ideally we get a column size of NULL and fraction length of '0'.
and I got exception
`
2016-09-20-20:57:10.288||R|c.u.s.r.web.rest.SocialResource|Exception creating social user: javax.validation.ValidationException: HV000028: Unexpected exception during isValid call.
at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.validateSingleConstraint(ConstraintTree.java:451)
at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.validateConstraints(ConstraintTree.java:127)
at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.validateConstraints(ConstraintTree.java:87)
at org.hibernate.validator.internal.metadata.core.MetaConstraint.validateConstraint(MetaConstraint.java:73)
at org.hibernate.validator.internal.engine.ValidatorImpl.validateMetaConstraint(ValidatorImpl.java:617)
at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraint(ValidatorImpl.java:580)
at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraintsForSingleDefaultGroupElement(ValidatorImpl.java:524)
at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraintsForDefaultGroup(ValidatorImpl.java:492)
at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraintsForCurrentGroup(ValidatorImpl.java:457)
at org.hibernate.validator.internal.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:407)
at org.hibernate.validator.internal.engine.ValidatorImpl.validate(ValidatorImpl.java:205)
at org.hibernate.cfg.beanvalidation.BeanValidationEventListener.validate(BeanValidationEventListener.java:137)
at org.hibernate.cfg.beanvalidation.BeanValidationEventListener.onPreInsert(BeanValidationEventListener.java:95)
at org.hibernate.action.internal.EntityIdentityInsertAction.preInsert(EntityIdentityInsertAction.java:214)
at org.hibernate.action.internal.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:92)
at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:492)
at org.hibernate.engine.spi.ActionQueue.addResolvedEntityInsertAction(ActionQueue.java:197)
at org.hibernate.engine.spi.ActionQueue.addInsertAction(ActionQueue.java:181)
at org.hibernate.engine.spi.ActionQueue.addAction(ActionQueue.java:216)
at org.hibernate.event.internal.AbstractSaveEventListener.addInsertAction(AbstractSaveEventListener.java:334)
at org.hibernate.event.internal.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:289)
at org.hibernate.event.internal.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:195)
at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:126)
at org.hibernate.jpa.event.internal.core.JpaPersistEventListener.saveWithGeneratedId(JpaPersistEventListener.java:84)
at org.hibernate.event.internal.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:206)
at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:149)
at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:75)
at org.hibernate.internal.SessionImpl.firePersist(SessionImpl.java:811)
at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:784)
at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:789)
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:1181)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:344)
at com.sun.proxy.$Proxy128.persist(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:294)
at com.sun.proxy.$Proxy128.persist(Unknown Source)
at org.springframework.data.jpa.repository.support.SimpleJpaRepository.save(SimpleJpaRepository.java:439)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.executeMethodOn(RepositoryFactorySupport.java:483)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:468)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:440)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:61)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:131)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.jarbframework.constraint.violation.TranslateAdviceAddingBeanPostProcessor$ExceptionTranslatingAdvisor$1.invoke(TranslateAdviceAddingBeanPostProcessor.java:102)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:208)
at com.sun.proxy.$Proxy131.save(Unknown Source)
at com.unite.software.repengine.service.db.UserService.create(UserService.java:79)
at com.unite.software.repengine.service.db.UserService$$FastClassBySpringCGLIB$$2f51278f.invoke()
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:720)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:655)
at com.unite.software.repengine.service.db.UserService$$EnhancerBySpringCGLIB$$b9384c4.create()
at com.unite.software.repengine.service.SocialService.createUserIfNotExist(SocialService.java:103)
at com.unite.software.repengine.service.SocialService.createSocialUser(SocialService.java:68)
at com.unite.software.repengine.web.rest.SocialResource.signUp(SocialResource.java:34)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:817)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:731)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:968)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:859)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:844)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.springframework.web.servlet.resource.ResourceUrlEncodingFilter.doFilterInternal(ResourceUrlEncodingFilter.java:52)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at com.unite.software.repengine.filters.CorsFilter.doFilter(CorsFilter.java:43)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:316)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:126)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:90)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:114)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:122)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:111)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
at org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter.doFilter(RememberMeAuthenticationFilter.java:149)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:169)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:48)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilterInternal(BasicAuthenticationFilter.java:158)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
at org.springframework.security.web.session.ConcurrentSessionFilter.doFilter(ConcurrentSessionFilter.java:133)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:205)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:120)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:64)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:91)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:53)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:213)
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:176)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:262)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:87)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:121)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:522)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1095)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:672)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException: null
at org.jarbframework.utils.jdbc.JdbcUtils.doWithConnection(JdbcUtils.java:51)
at org.jarbframework.constraint.metadata.database.JdbcColumnMetadataRepository.getMetadata(JdbcColumnMetadataRepository.java:41)
at org.jarbframework.constraint.metadata.database.SimpleBeanMetadataRepository.getColumnMetadata(SimpleBeanMetadataRepository.java:29)
at org.jarbframework.constraint.metadata.database.CachingBeanMetadataRepository.getColumnMetadata(CachingBeanMetadataRepository.java:31)
at org.jarbframework.constraint.validation.DatabaseConstraintValidator.validateSimpleProperty(DatabaseConstraintValidator.java:108)
at org.jarbframework.constraint.validation.DatabaseConstraintValidator.validateProperty(DatabaseConstraintValidator.java:97)
at org.jarbframework.constraint.validation.DatabaseConstraintValidator.validateBean(DatabaseConstraintValidator.java:84)
at org.jarbframework.constraint.validation.DatabaseConstraintValidator.isValid(DatabaseConstraintValidator.java:77)
at org.jarbframework.constraint.validation.DatabaseConstrainedAdapter.isValid(DatabaseConstrainedAdapter.java:36)
at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.validateSingleConstraint(ConstraintTree.java:448)
... 180 common frames omitted
`
I used spring-boot and my configuration
`
@configuration
public class HibernateValidationConfiguration extends HibernateJpaAutoConfiguration {
@Autowired
private MessageSource messageSource;
@Bean
public Validator validator() {
LocalValidatorFactoryBean validatorFactory = new LocalValidatorFactoryBean();
validatorFactory.setValidationMessageSource(messageSource);
return validatorFactory;
}
@Bean
public MethodValidationPostProcessor methodValidationPostProcessor() {
MethodValidationPostProcessor methodValidationPostProcessor = new MethodValidationPostProcessor();
methodValidationPostProcessor.setValidator(validator());
return methodValidationPostProcessor;
}
@Override
protected void customizeVendorProperties(Map<String, Object> vendorProperties) {
super.customizeVendorProperties(vendorProperties);
vendorProperties.put("javax.persistence.validation.factory", validator());
}
}
`
`
@configuration
@EnableDatabaseConstraints(basePackages = {"com.unite.software.repengine"})
public class DatabaseConstraintsConfiguration extends DatabaseConstraintsConfigurer {
@Autowired
private BeanConstraintDescriptor beanConstraintDescriptor;
@Bean
public BeanConstraintDescriptorController beanConstraintDescriptorController() {
return new BeanConstraintDescriptorController(beanConstraintDescriptor);
}
}
`
beanConstraintDescriptor.describeBean should also give back embedded properties
Publish JaRB maven repository
Thanks.
@SpringBootApplication
@EnableDatabaseConstraints(basePackages = "com.example")
public class SpringBootApplication {
public static void main(String[] args) {
SpringApplication.run(SpringBootApplication.class, args);
}
}
First tried with version 2.3.0:
<dependency>
<groupId>org.jarbframework</groupId>
<artifactId>jarb-constraints</artifactId>
<version>2.3.0</version>
</dependency>
Got the following error:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.jarbframework.constraint.DatabaseConstraintsConfiguration': Invocation of init method failed; nested exception is java.lang.ClassCastException: com.sun.proxy.$Proxy108 cannot be cast to org.hibernate.ejb.HibernateEntityManagerFactory
Then tried with latest version 2.4.3:
@EnableDatabaseConstraints and @DatabaseConstrained are not available with 2.4.3 version
On Ubuntu 16.04 LTS, the database SQL import scripts get executed randomly.
This causes integrity constraint errors, such as "Foreign key no parent".
See also this section of logging output.
2016-07-12 16:50:55,993 INFO [org.springframework.jdbc.datasource.init.ScriptUtils] - <Executing SQL script from file [/home/xxx/development/xx/xxxx/java/src/main/db/data/007_xxx.sql]> 2016-07-12 16:50:56,668 INFO [org.springframework.jdbc.datasource.init.ScriptUtils] - <Executed SQL script from file [/home/xxx/development/xx/xxxx/java/src/main/db/data/007_xxx.sql] in 674 ms.> 2016-07-12 16:50:56,668 INFO [org.springframework.jdbc.datasource.init.ScriptUtils] - <Executing SQL script from file [/home/xxx/development/xx/xxxx/java/src/main/db/data/001_xxx.sql]> 2016-07-12 16:50:56,717 INFO [org.springframework.jdbc.datasource.init.ScriptUtils] - <Executed SQL script from file [/home/xxx/development/xx/xxxx/java/src/main/db/data/001_xxx.sql] in 49 ms.> 2016-07-12 16:50:56,718 INFO [org.springframework.jdbc.datasource.init.ScriptUtils] - <Executing SQL script from file [/home/xxx/development/xx/xxxx/java/src/main/db/data/004_xxx.sql]> 2016-07-12 16:50:57,422 INFO [org.springframework.jdbc.datasource.init.ScriptUtils] - <Executed SQL script from file [/home/xxx/development/xx/xxxx/java/src/main/db/data/004_xxx.sql] in 704 ms.> 2016-07-12 16:50:57,424 INFO [org.springframework.jdbc.datasource.init.ScriptUtils] - <Executing SQL script from file [/home/xxx/development/xx/xx/java/src/main/db/data/006_xx.sql]> Exception in thread "Thread-5" org.springframework.jdbc.datasource.init.ScriptStatementFailedException: Failed to execute SQL script statement #1 of file [/home/xxx/development/xx/xx/java/src/main/db/data/006_xxx.sql]: insert into xxx(xx, <etc...>); nested exception is java.sql.SQLIntegrityConstraintViolationException: integrity constraint violation: foreign key no parent; FK_XXX
The LiquibaseMigrator does not work when output sql is written. The sql is written to the given file, but the changes are not executed on the database.
In the logs it becomes clear that there is an issue with the use of the Liquibase api and resources: a line with: "successfully released change log lock" is never printed...
Database used: hsqldb standalone (local file)
Use mockito instead, simpler and cleaner API
Create a H2 specific database constraint violation resolver.
Allow translate constraint namespace to specify custom default exception factory.
<translate-exceptions .... default-factory="x"/>
Hi, I clone repo and maven throws:
"Missing artifact org.liquibase:liquibase-ext-groovy:jar:1.0:compile"
The default implementation of migrations uses file system migrations with ${user.dir}/src/main/db/changelog.groovy as the default. To use classpath migrations, you need to explicitly specify the LiquibaseMigrator which you would in any case in order to specify the changeLogPath as well as the LiquibaseFactory property of LiquibaseMigrator which in turn has the property for specifying the ResourceAccessor. It might be nice to push the accessor property to the LiquibaseMigrator where the changeLogPath is specified.
The following nested exception is retrieved from Spring:
org.xml.sax.SAXParseException: s4s-elt-character: Non-whitespace characters are not allowed in schema elements other than 'xs:appinfo' and 'xs:documentation'. Saw '42BV/jarb · GitHub'.
Use the latest versions
this is my entity:
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import org.jarbframework.constraint.validation.DatabaseConstrained;
import com.fasterxml.jackson.annotation.JsonProperty;
@DatabaseConstrained
@entity
@table(name = "role")
public class Role implements Serializable {
private static final long serialVersionUID = 8481707032813450851L;
@Id
@GeneratedValue
@Column(name = "id")
private int id;
@Column(name = "role_name")
@JsonProperty(value = "role_name")
private String roleName;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getRoleName() {
return roleName;
}
public void setRoleName(String roleName) {
this.roleName = roleName;
}
}
and the spring configuration file:
<context:annotation-config />
<context:component-scan base-package="com.demo" />
<mvc:annotation-driven />
<jarb:enable-constraints entity-manager-factory="entityManagerFactory" base-package="com.edurelate.eschool" />
....
I'm using sping-data-jpa:
Role r = new Role();
r.setRoleName('USER'); // 'USER' already exists in role table
when i run:
try {
roleRepository.save(r); // 1
}
catch(UniqueKeyViolationException e) {
System.out.println('Unique Violation: " +e); // 2
}
catch(Exception e) {
System.out.println(e); // 3
}
Im getting an error message "javax.validation.ValidationException: HV000032: Unable to initialize org.jarbframework.constraint.validation.DatabaseConstrainedAdapter." at // 3
Please help me out
Allow constraint names to be matched based on a pattern, and not just the exact name, allowing us to do the following:
uk_*_code => CodeAlreadyExistsException
Matching all code based unique constraint violations.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.