2014-09-16 6 views
6

come nel titolo - my @RestResource (exported = false) viene ignorato sul campo. resto dei dati Primavera ancora voglia di fare JSON da esso, vorrei ignorare semplicemente tutto per ora, come cambiare rel in WorkflowEvent mi ha dato nulla ..@RestResource (exported = false) ignorato

@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "submission") 
@OrderBy("date desc") 
@RestResource(exported = false) 
private List<WorkflowEvent> events = new ArrayList<WorkflowEvent>(); 

ottengo:

{"timestamp":1410850806347,"status":500,"error":"Internal Server Error","exception":"org.springframework.http.converter.HttpMessageNotWritableException","message":"Could not write JSON: Detected multiple association links with same relation type! Disambiguate association @javax.persistence.JoinColumn(insertable=true, unique=false, referencedColumnName=, columnDefinition=, name=submission_id, updatable=true, nullable=true, table=, [email protected](name=, value=CONSTRAINT, foreignKeyDefinition=)) @javax.persistence.ManyToOne(fetch=EAGER, cascade=[], optional=true, targetEntity=void) @org.springframework.data.rest.core.annotation.RestResource([email protected]iption(value=), path=, exported=false, rel=) private mypackage.MyClass mypackage.WorkflowEvent.myclass using @RestResource!; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Detected multiple association links with same relation* 

ofcourse funziona quando commento questo campo.

mie versioni:

\- org.springframework.data:spring-data-rest-webmvc:jar:2.1.4.RELEASE:compile 
[INFO] |  \- org.springframework.data:spring-data-rest-core:jar:2.1.4.RELEASE:compile 
[INFO] |  +- org.springframework.hateoas:spring-hateoas:jar:0.16.0.RELEASE:compile 

risposta

11

@RestResources è supportata solo sulle proprietà di dominio che puntano a risorse gestite. Pertanto, se non si espone WorkflowEvent da un repository gestito REST di Spring Data, l'annotazione non ha alcun effetto. In questo caso, usa semplicemente un @JsonIgnore per consentire a Jackson di non rendere la proprietà.

+0

Anche se ha un repository, @RestResource (exported = false) sulla proprietà WorkflowEvent in qualche altra entità non ha alcun effetto. Se rimuovo il repository, tenta comunque di creare un collegamento all'entità WorkflowEvent. Si blocca con "Rilevato più collegamenti di associazione" su mypackage.WorkflowEvent.submission – freakman

+0

Questo sembra essere abbastanza coinvolto. Qualche possibilità che fornisci un esempio di progetto da guardare? –

+0

sembra che non abbia repository per nessuna delle proprietà causa questo (ne ho rimosso uno per WorkflowEvent ora per riprodurlo). Se è lì - tutto è ok - i link sono generati e funzionano bene. Oliver - se non c'è una ragione razionale per questo cercherò di creare qualche piccolo progetto con questo problema. – freakman