anyone know why grails 3 controllers have issues rendering spring data 'Pages' as JSON ?
Class org.grails.web.converters.marshaller.json.GenericJavaBeanMarshaller can not access a member of class org.springframework.data.domain.Chunk with modifiers "public
Related
As a yet "newbie" of JavaEE, say I try to implement a rather big RESTful API with Spring 4 and Hibernate and, the final JSON objects should be transformed to flattened Objects other than the original Java bean entities annotated with #Entity.
Due to the "out-of-the-box" feature of Spring and Hibernate, I am sure most programmers can easily get the work done. But as an experienced programmer, we would focus more on the code structure, design architecture so that the whole project is more maintainable and code is easy to read.
So my first question is the package structure:
where to place the Java bean entities annotated with #Entity? I have seen some people place them in the package called model, I am not exactly clear about their purpose anyway
Where to place the final flattened objects transformed from the Java bean entities? I placed it in the package called dto as this is data transfer object between the service layer and the controller layer
so I have the following package structure:
sample.model //place the #Entity Java beans
sample.dto //place the aforementioned DTO
sample.controller //place the controller class
Anyone can give some comments on it? Thanks in advance
There's two different ways to organize packages in Java project.
package-per-feature
package-per-layer
Comparison
But how to name your package it's really up to you.
In different projects, I faced with names like:
for entity: model, domain, entity
for DTO: dto, transport, response or request (depending on direction)
I like Spring Data REST but I need to explore the possibility to use it without exposing directly our JPA Entities. Furthermore, our access layer is currently build using GenericDAO instead of repository (or Spring Data JPA).
So the idea is to build a custom spring data module that implementing the Repository interfaces allow me to benefit of all the other functionalities of Spring Data REST. The entities managed by our custom spring data module will be at the end DTOs of the original JPA entities.
I'm currently looking to spring-data-ldap as implementation to mimic as it looks as the most simple data module available but I'm facing with the following issue
we get an exception at the application startup saying
Parameter 0 of constructor in org.springframework.data.dspace.repository.support.DSpaceRepositoryFactoryBean required a bean of type 'java.lang.Class' that could not be found.
Action:
Consider defining a bean of type 'java.lang.Class' in your configuration.
DSpaceRepositoryFactoryBean is our implementation that just return a very simple DSpaceFactoryBean that always return a banal implementation of the CrudRepository (all methods return null)
#Override
protected Class<?> getRepositoryBaseClass(RepositoryMetadata metadata) {
return SimpleDSpaceRepository.class;
}
have sense this approach? or will be better to give up with Spring Data REST and just use Spring MVC + HATEOS?
I'm attempting to add Crate.IO capability to an existing Spring Data/Eclipselink/MySql web application. For this specific use case, we want to persist data to both MySql AND Crate (for evaluation purposes) in the most painless way possible. I'm using the Spring-Data-Crate project in order to be able to use Spring Data Repositories with Crate.
I've been able to setup a separate Crate specific entity manager with a filter to only utilize repos that implement CrateRepository. The problem I'm having is determining how to use the existing Spring Data/MySql entity classes with Crate. (or derive from them)
1) If I annotate an existing Spring Data #Entity class with the Spring-Data-Crate
#Table annotation, the mapping to the crate DB will fail because EclipseLink/JPA adds hidden persistence fields to entities objects that start with an underscore, which is apparently not allowed by the spring-data-crate adapter
2) I tried to use entity inheritance, with a base class that both the MySql and Crate entity can extend, with only the MySql entity having the spring data #Entity annotation. Unfortunately, this causes Spring Data to lose visibility of the base class fields unless the base class is annotated with #MappedSuperClass. But adding this annotation introduces the hidden "_"-prefixed persistence properties to the derived crate entity.
3) I could use separate entities entirely and have them implement a common interface, but I can't assign the interface as the type of the spring data crate repository.
... Not sure where to go from here
Spring Data Crate adapter project - https://github.com/KPTechnologyLab/spring-data-crate
Spring Data Crate Tutorial - https://crate.io/a/using-sprint-data-crate-with-your-java-rest-application/
i'm johannes from crate.
we didn't test the use of spring data crate in that manner so we can't state any information if this should or shouldn't work.
sorry, johannes
I'm developing a new Spring MVC application using RESTful requests. The application does the standard database load object, bind values and save. In order to not lose object values which are not available on the form, I'm using a #ModelAttribute method to preload the object prior to binding.
When loading an agency using the URL
/agency/418
my #ModelAttribute method has now way of learning of the '418' ID. My understanding is that only regular request attributes can be processed, so my URL would need to be
/agency/418?id=418
which kinda breaks the RESTful pattern. Same thing when POSTing data.
Could someone comment on this observation ... am I missing something?
Thanks
Simon
You can very well use a pathvariable to initialze a modelattribute:
#controller
public controller {
#modelattribute("model")
public Entity initentity(#pathvariable integer id) {
return dao.getentity(id);
}
#requestmapping("/{id}")
public String somerequest(#modelattribute("model") Entity entity) {
....
}
}
We gave up on the idea of using #ModelAttribute to replace what used to be "formBackingObject" in Spring 2. Instead, we're using plain form object classes for form binding, and then copying over the values to the persistent entity. The form object can be created on-the-fly by Spring, thus we don't require a #ModelAttribute with database load anymore. The topic is covered in Does Spring MVC require copy/paste of Entity to FormObject?.
i have a Class A that is used as a result for a JAX-RS method. I want to marshal A into xml in two different ways.
Is there a way to give resteasy two different mappings to use on my class?
Greetings,
Laures
Note: I'm the EclipseLink JAXB (MOXy) lead and a member of the JAXB 2 (JSR-222) expert group.
You could use MOXy for this. Check out my blog post where I map the same object model to two different weather services (Google and Yahoo) by leveraging annotations for one mapping and MOXy's XML metadata for the second mapping:
http://blog.bdoughan.com/2011/09/mapping-objects-to-multiple-xml-schemas.html
Below is an example of using MOXy's XML metadata in a JAX-RS environment:
http://blog.bdoughan.com/2011/04/moxys-xml-metadata-in-jax-rs-service.html
For More Information
http://blog.bdoughan.com/2011/05/specifying-eclipselink-moxy-as-your.html
http://blog.bdoughan.com/2010/12/extending-jaxb-representing-annotations.html
http://blog.bdoughan.com/2010/08/creating-restful-web-service-part-35.html
Here is a solution for JAXB RI.
The same idea: define JAXB annotations in XML resources.