If I don't write a custom query the @Autowired
FirstnameRepository
object is null
, therefore I tried to write a custom query, but this produces the following error.
java.lang.IllegalArgumentException: Validation failed for query for method public abstract java.util.List FirstnameRepository.findByNation(Nation)!
Since the query looks correct to me, I think it has something to do with my classstructure or incorrect annotations.
FirstnameRepo
public interface FirstnameRepository extends JpaRepository<Firstname, String>{
@Query("SELECT fn FROM Firstname fn WHERE fn.nation = :nation")
List<Firstname> findByNation(@Param("nation")Nation nation);
}
Firstname Model
@Entity
@Table(name = "Firstnames")
public class Firstname extends Name implements Serializable {
private static final long serialVersionUID = 1L;
@Basic(optional = false)
@Column(name = "gender")
private short gender;
@JoinColumn(name = "nation", referencedColumnName = "id")
@ManyToOne(optional = false)
private Nation nation;
public Firstname() {}
}
Since there is also a Lastname
model class I extend a class named Name
to save Firstname
and Lastname
in the same Map
. Name
has no table in the database and both classes only inherit the ID property.
Name class
@MappedSuperclass
public abstract class Name {
@Id
@Basic(optional = false)
@Column(name = "name")
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
If I comment the findByNation()
method out, the server starts without a problem. I hope this is all you need, the server configuration is more or less copied from a working project, but if I should include something let me know. thanks
EDIT The Problem was a incorrect configuration. I changed alot of stuff before testing it again, but seems like the main issue was a wrong version of in the web.xml.