1

I am getting below mentioned error when trying to access records from DB using a spring-data-jpa and spring-data-rest.

Cannot create self link for class [Ljava.lang.Object;! No persistent entity found!

Tables Relation Diagram

I am using below query to retrieve information and my Class structure is somewhat as below

Agency
@OneToMany(mappedBy="agencyCode",cascade=CascadeType.ALL)
@JsonIgnore
List<Location> locations;


Location:
@ManyToMany
@JoinColumn(name = "zipCode")
Set<Zip> zips;

Zip:
@Id
@Column(name="zipCode")
String zipCode;

Query used to retrieve information is as below:

@Query("SELECT DISTINCT a, l.contactInfo.address.city, l.contactInfo.address.street,    l.contactInfo.phone from Agency a, Location l INNER JOIN  l.zips z where a.ceID = l.agencyCode and z.zipCode = :zip")
public List<Agency> findAgencyByZip(@Param("zip") String zip);      

Any Help on this would be greatly appreciated.

Regards Chetan

chetank
  • 392
  • 3
  • 17
  • Can you provide the full stack trace? Looks like a version compatibility problem between different jars/libs. – mp911de Dec 11 '14 at 18:29
  • @mp911de : I am not sure how do i post the stack trace since its not allowing me to put it in the comments section – chetank Dec 12 '14 at 19:13

1 Answers1

1

Don't know if this is the cause, but in Location, for @ManyToMany you need a @JoinTable instead of @JoinColumn. Fix that, and maybe this error will also be fixed. Try this:

@ManyToMany
@JoinTable(name = "LOCATION_ZIP", joinColumns = @JoinColumn(name = "LOCATION_LOC_CODE"),
           inverseJoinColumns = @JoinColumn(name = "ZIPS_ZIP_CODE")
Set<Zip> zips;
Predrag Maric
  • 23,938
  • 5
  • 52
  • 68
  • Thanks for the help but this doesn't works may be some issue with the SDR or SDP itself, raised a ticket with spring lets see what they come up with https://jira.spring.io/browse/DATAREST-425 – chetank Dec 12 '14 at 21:35