Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Jun 26 2017 20:07
    @remmeier banned @hibaymj
Remo
@remmeier
transaction runner has different use cases. if the create/update/delete is more complex spanning multiple queries. operationsmodule supporting bulk mutation. and if desired database isolation when doing multiple reads/graph loading. for the later read committed is a frequent default, so not much impacf here.
Roy
@depzor
Thanks for pointing me into the right direction. I found a major problem in my code... well due Lombok..
using @data notation on my entity's

this creates a hashCode method for all properties and this triggers many lazy load queries when it creates a TupleElement at a certain point:

TupleElement(Object[] data) {
this.data = data;
this.hashCode = Arrays.hashCode(data);
}

Steve Brush
@brushs
thanks @remmeier -- is there an example available of a scenario with create/update/delete with multiple queries?
Roy
@depzor
Remo, I understand I dont need to populate relationships to the DTO to prevent new queries. However when I try to PATCH a relation it fails, because the relation isn't mapped into the dto.. why isnt the entity used here
Roy
@depzor
ah the entity is fetched through the JPA mapper. There I shouldn't override the dto relationships to the entity right because the dto relationships are null?
Roy
@depzor
hence the same properties (relationships) I set to ignore with mapstruct like @Mapping(target = "someRelation", ignore = true)
applies to both methods: map (entity to dto) and unmap (dto to entity)? Seems to work for a patch, not sure if I am missing any other cases..
Roy
@depzor
mmm you can immediately update relationships as well, that wont work with this solution
Remo
@remmeier
cannot quite follow.
sometimes it is simpler to use entities and db views rather than DTOs
to simplify relationshift handling in JPA I often make use of JsonApiRelationId to avoid all the relationship loading stuff and be closer to the relational model. so each relationship has a primitive and a entity-based atteibute mapped to the same column.
the docs/demo should have an example
updates will then use the primitve field
Remo
@remmeier
if a PATCH does not transmit a field, it will be ignored
Roy
@depzor
In my implementation of JpaMapper
E unmap(D dto)
I fetch the entity with entity manager and map all dto properties to the entity and for relations I only map it from dto if it's there otherwise I rely on existing entity data
that is my strategy at the moment
Roy
@depzor
Hi goodmorning, earlier you told me I shouldn't map relationships with mapstruct to the corresponding dto.
This is working very efficient when performing a GET. No wasted queries.
However in my JsonApiResource dto I have a json api relation property marked with @NotNull hence required when creating a new entity.
This is working fine for a POST. However when I try to do a PATCH and I omit the specific relation data from my request body
I receive a 422 error because the relationship is null. I can fix this by mapping this relationship in my JpaMapper.map(Tuple tuple) implementation.
But this solution has a side effect. When I perform another GET to fetch a list of my entity this triggers extra unwanted queries for this relationship, because I had to map this relationship in MapStruct.
Any better ideas for this particular problem?
Remo
@remmeier
I almost always make use of @JsonApiRelationId to complement @JsonApiRelation. It simplifies the handling. In particular for JPA with those lazy proxies that are prone to lazy loading issues. Or DB Views rather than DTOs as other simplification depending on the scenario (not always desired though).
Steve Brush
@brushs
@remmeier in the JPA Module docs (11.2) the docs describe one feature as "automatic transaction handling spanning requests" -- could you elaborate on that one a bit, in particular what is meant by "request" in this context?
Remo
@remmeier
that should rather be "spanning across a request" to be precise. No multi-request transaction things, except when batching them with the operations module.
Steve Brush
@brushs
I have a ResourceRepository for a DTO, and presumably would like to inject a reference to repository for an actual Entity tied to my DB to perform the actual work for creating records. I can autowire the Entity's repository if I actually create a class for that repository. However, I would prefer not to -- currently spring boot auto-configures all the repositories. Is there to inject or get a reference into my DTO's repository without creating the Entity repository manually? I tried through the ResourceRegistry but that doesn't seem to work.
Remo
@remmeier
if the Entity repository is managed by Spring, an the DTO manually defined and also managed in Spring, should work? There is no mechanism as of yet that would expose all the Crnk internals to Spring, like all the contents of the ResourceRegistry. It is rather the other way around. It will discover everything from Spring and put it into the ResourceRegistry.
3 replies
duncanportelli
@duncanportelli
I have a generic question please. Is the CrnkClient capable of handling concurrent requests at the same time? i.e. should I create it as a singleton object or create multiple clients?
Joshua Bourquin
@jbourquin
I have a high level question, I have a POSTGRES database plugged into CRNK with some JSONB columns. How can I add a custom URL query filter to CRNK that would then execute some custom SQL against said JSONB columns?
heidiperaltacasebook
@heidiperaltacasebook

Hi @remmeier ! I'm using postman to query my java endpoint using nested filters like so:

{baseUrl}/entity?filter={"resourceType": "value"}

These are the properties on the model:

  @JsonProperty(value = "resource_type")
  @Column(name = "resource_type")
  private String resourceType;

  private String name;

I get Failed to resolve path to field 'resourceType' if I try snake case I get attribute resource_type not found in Entity

If I use the name property to filter by it works just fine, this happens across the entire API where it seems to only work when filtering on single-name properties that are not in camel/snake case. Is there anything we need to configure/fix on our end? Thank you!

Remo
@remmeier
@duncanportelli yes, it is thread-safe. In general there are no internal data structured shared between requests that could cause problem.s
@jbourquin a non-JSONAPI parameter? if you want to submit a generic sql query, maybe the "empty" ?filter=... will do
@heidiperaltacasebook with a current version? the json property should work, meaning resource_type. If not, there is an issue somewhere and the complete exception would be good.
Rehab Reda
@rehab-reda0
Hi Remo I want to change the serialize type to lazy for the relationships if the returned number of items of the main entity is more than 2 for example is there any way to do so ?
Weihua Hu
@jameshwh
@remmeier Hi Remo, is there any easy way to construct a request body for create request? can we generate it from a @JsonApiResource object? i want to do integration test and wondering if there is any existing tool for it, otherwise i need to construct the request body by myself
Weihua Hu
@jameshwh
it is found that we could use crnkBoot.getDocumentMapper().getResourceMapper() to do the conversion
Weihua Hu
@jameshwh
but didn't know if there is any way to convert a json string to JsonApiResource entity
Steve Brush
@brushs
@remmeier Are ResourceRepositories automatically scanned and created by Spring available to other Spring beans? I assume so -- but they do not seem to be available for injection and do not seem to show in Actuator?
Remo
@remmeier
@rehab-reda0 if you need custom logic, you could implement it in your repository (keep it lazy but to eager if fewer than 3 results available). But generally I would recommend against change ob behavior depending on the the number of results for the sake of consistency.
@brushs if they are setup like any other bean (by the application, not crnk). In doing so, it has all the usual Spring things like autowiring. Unlike the Spring Data repository, there is no magical and hard to customize default logic (except the JPA legacy expose-all code paths maybe). what would you like to see from the actuator? (personally I dont use them in favor of something else).
Remo
@remmeier
@jameshwh yes, exactly DocumentMapper. From that you get Document/Resource objects. Those you can (de)serialize) with Jackson's ObjectMapper.
Steve Brush
@brushs
@remmeier is there any way to mix the "exposeAll" behaviour and a manually created Repository? I have 300+ entities and need a handful of manually created Repositories?
Remo
@remmeier
Maybe with a look at JpaModule and its config. the expose all is just a loop and if there is a limitation, ciuld be customized. A bit harder would be if you make use of spring depency injection. in this case two unrelated codepaths would contribute the same thing. that will cause trouble. in this case probably best to not use exposeall and look for a spring-based solution
Atreyu79
@Atreyu79
Is there a way I can default Crnk-Compact to true in a resource repository? In my API I'm not persisting a particular resource, so it's never retrievable via GET... making self links misleading. I know we can intercept and force the header on a customer's behalf, but a more elegant solution is preferred if one exists. I'm unclear from the documentation what my options are here.
Rehab Reda
@rehab-reda0

Hi @remmeier any way to modify the related link here ?
"self": "http://example.com/articles/1/relationships/author"

"related": "http://example.com/articles/1/author"

Remo
@remmeier
it is possible to omit one or the other
@Atreyu79 no, not as of yet. was not deemed useful because it breaks discoverability in the broswer for developers/operators
should be more an optimization where needed
Rehab Reda
@rehab-reda0

I want for example to modify the url to be authors not author
"self": "http://example.com/articles/1/relationships/author"

"related": "http://example.com/articles/1/author"

@remmeier

Remo
@remmeier
@JsonProperty allows renaming
Rehab Reda
@rehab-reda0

I am having a problem we have a standarization that the url should be in kebab case
so If have account model which has a list of emailAddresses
I want the url to be like accounts/id/email-addresses

but the relationship in the response body should be in camelCase

I solved the first part by modifying the url in spring boot filter so if the user request accounts/id/email-addresses it is then converted to accounts/id/emailAddresses
but the links in the response how can i modify relationship links ?
Matt12432
@Matt12432
Hi all, I'm trying to get a url like this to work: /authors/{authorId}/books/{id} to return a specific book out of the list of books that belong to the author however I get an error saying "cannot add further url fragements after field". Should the above url be possible? I've also tried using a filter like /authors/{authorId}/books?filter["id"]={bookId} however that returns an error saying that the property id doesn't exist even though the call to beanInformationBase.findFieldByJsonName() appears to have an id property in the hashmap. Appreciate any help on this.
Rehab Reda
@rehab-reda0
@Matt12432 yes it is possible by applying the nested resources check here https://www.crnk.io/releases/stable/documentation/#_nested_resources