So I am working on my Repositories on the slightly more complex queries beyond query by property. And I am can't seem to find in the documentation anything beyond the basic trivial queries. Which is fine, we need Spring Data to cover those trivial queries automatically for us. which is what makes it great.
But when you start to get to those just beyond the simple, it is difficult to figure out if Spring Data can automatically help you out, or what is it that you need to do to just go beyond.
So, I don't think what I am doing is complex strange corner case.
I have an Event node and I have an Item Node with a RelationshipEntity called ItemBringingToEvent. I want to write a query that returns a List of Items and the value from the quantityNeeded in the relationship. So I started with
OK, now of all my possible examples this is the oddest relationship I have. Which is weird since this is one of the only ones with direct relationships and not vertexes.Code:public interface ItemRepository extends GraphRepository<Item> { Page<Item> findByDescriptionLike(String description, Pageable page); Item findByDescription(String description); Item findByBarcode(String barcode); //ITEM_NEEDED_FOR_EVENT @Query("start event=node({0}) " + " match event-[i:"+ Event.ITEMS_NEEDED_FOR_EVENT + "]->item" + " return item, i.quantityNeeded") Page<Item> findByEvent(Long eventId, Pageable page);
But while I am still debating how to do this relationship, I still think it can be used to see if I am on the correct thinking.
I think I cannot used a derived query by method name because the Item domain object does not hold a reference to any Event, it is only the Event with a List of ItemsNeededForEvent with @RelatedToVia.
Anyway, the question I have is not about the query itself (It is wrong), but how Spring Data derives stuff. So in the query, because I have Pageable as a parameter, then the query will get a limit added to it? Can Pageable be any position parameter in that method, meaning if I have another like it with a "Where", where there are parameters to be filled in by the values passed in the method parameters I can put those anywhere, or I think I saw an @Param annotation to add them in the method signature.
Q2) Because Item does not have a reference to any events, then I can't use a derived query by methodName that would return a List of Items? Or would that have to be a query in the EventRepository<Event>
Q3) The query above is returning a Page<Item> but my Relationship object has a property that I also need called quantityNeeded. How do I get that returned with the query, I can't see the ItemRepository method returning a List of the RelationshipEntity type, it would have to be a node type of Item. Does this mean I need a Repository for the RelationshipEntity?
Thanks
some more code if needed
Item class
And the EntityRelationshipCode:@NodeEntity public class Item implements Serializable { private static final String BARCODE_INDEX = "barcode"; private static final String DESCRIPTION_INDEX = "description"; @GraphId private Long id; @Indexed(indexName = BARCODE_INDEX) private String barcode; @Indexed(indexName = DESCRIPTION_INDEX, indexType = IndexType.FULLTEXT) private String description; }
MarkCode:@RelationshipEntity(type = Event.ITEMS_NEEDED_FOR_EVENT) public class ItemNeededForEvent implements Serializable { private BigDecimal quantityNeeded; @StartNode private Event event; @EndNode private Item item; }


Reply With Quote