I'm working in a spring mvc project using spring data jpa and hibernate, I am using native queries that I declare in a interface that extends JpaRepository like this:
public interface I_Table_one extends JpaRepository<table_id, Long>{
@Query(value ="select name_att, .... .... various att"
+ "from Table_one "
+ "where id_table = 4 ",
nativeQuery = true)
public List<Table_one_Mapped_Class>serachInTable();
This method doesn't have to much sense is just a example, I have one that have like 80 attributes in the select I just one to know is there is a way to know what column name I have wrong.
My mapped class:
@Entity
@Table(name="Table_one")
public class Table_one_Mapped_Class implements Serializable {
private static final long serialVersionUID = 1L;
////ID///////
@Id
@Column (name="ID_TABLE", nullable=false)
private Long idInMyTable;
////ID///////
.....other columns
This is my hibernate properties configuration:
jpaProperties.put("hibernate.dialect", "org.hibernate.dialect.Oracle10gDialect");
jpaProperties.put("hibernate.format_sql", true);
jpaProperties.put("hibernate.ejb.naming_strategy", "org.hibernate.cfg.ImprovedNamingStrategy");
jpaProperties.put("hibernate.show_sql", true);
and I get the following error when i try to print a value from my controller class in a html page like this ${value}
I get this error in the console :
WARN : org.hibernate.engine.jdbc.spi.SqlExceptionHelper - SQL Error: 17006, SQLState: 99999
ERROR: org.hibernate.engine.jdbc.spi.SqlExceptionHelper - Invalid Column Name
and this error when I try to open the page
Request processing failed; nested exception is org.springframework.orm.jpa.JpaSystemException: org.hibernate.exception.GenericJDBCException: could not execute query; nested exception is javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not execute query
In the console says:
invalid column name
but how can I know what column have a invalid name, is in the query that I put in the interface method, or is a invalid name of an attribute in my mapped class
I have seen similar problems and what person posted that I need to select ALL the columns in the select in order to work, but why I only need a few column in my select do I need to select all of the column even if don't need them?
If you're using Spring Data JPA >1.4, you could create a DTO-Class containing exactly the attributes you need from your table(s).
A sample-DTO and -Query would look like this, then:
The Query:
@Query("select new de.mypackage.mymodel.dto.myDTO(name_Att, att2,, att3)" +
" from Table_One " +
"where ...")
List<myDTO> getAttributesFromBigTable(String name_Attribute,
String attribute2, String attribute3);
The DTO:
public class myDTO {
private String name_attr;
private String attr2;
private String attr3;
public myDTO(String name_attr, String attr2, String attr3) {
this.name_attr = name_attr;
this.attr2 = attr2;
this.attr3 = attr3;
}
public String getName_Attr() {
return name_attr;
}
...
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.