Native Query Jpa存储库在没有列规范

时间:2016-04-08 11:32:34

标签: hibernate postgresql spring-boot spring-data-jpa

嘿大家我有一个关系太多的类我使用springboot当我想通过Hql从@Query中检索数据时我得到了数组数组的结果,当我使用NativeQuery时我不能选择1个元素它总是选择*

这是我的班级

import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

@Entity
@Table(name="\"DEV\"")
public class Dev {

@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="\"IdDev\"")
private int id ;
@Column(name="\"NomDev\"")
private String nomdev;
@Column(name="\"NomDLL\"")
private String dll ;
@ManyToOne(fetch=FetchType.LAZY, cascade = CascadeType.ALL)
@JoinColumn(name="\"IdEtatDev\"")
private EtatDev etatdev ;
@ManyToOne(fetch=FetchType.LAZY, cascade = CascadeType.ALL)
@JoinColumn(name="\"IdEcu\"")
private Ecu ecu ; 


@ManyToMany(fetch=FetchType.LAZY)
@JoinTable(name="\"VEH_BY_DEV\""
        ,joinColumns={@JoinColumn(name="\"IdDev\"")}, 
        inverseJoinColumns={@JoinColumn(name="\"GRPMOD\"")})

private Set<Vehid> vehid = new HashSet<>();
@ManyToOne(fetch=FetchType.LAZY)
private Maj maj ; 



public Set<Vehid> getVehid() {
    return vehid;
}
public void setVehid(Set<Vehid> vehid) {
    this.vehid = vehid;
}
public Ecu getEcu() {
    return ecu;
}
public void setEcu(Ecu ecu) {
    this.ecu = ecu;
}
public int getId() {
    return id;
}
public void setId(int id) {
    this.id = id;
}
public String getNomdev() {
    return nomdev;
}
public void setNomdev(String nomdev) {
    this.nomdev = nomdev;
}
public String getDll() {
    return dll;
}
public void setDll(String dll) {
    this.dll = dll;
}
public EtatDev getEtatdev() {
    return etatdev;
}
public void setEtatdev(EtatDev etatdev) {
    this.etatdev = etatdev;
}

public Dev() {
    super();
}
public Dev(int id, String nomdev, String dll, EtatDev etatdev, Ecu ecu, Set<Vehid> vehid) {
    super();
    this.id = id;
    this.nomdev = nomdev;
    this.dll = dll;
    this.etatdev = etatdev;
    this.ecu = ecu;
    this.vehid = vehid;
} 



}

这是我的存储库类

import java.util.List;

import javax.transaction.Transactional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;



@Transactional 
public interface DevRepository extends JpaRepository<Dev, Integer> {


@Query(value="SELECT \"IdDev\"  "\NomDev\" FROM \"DEV\"  ",nativeQuery=true)
    List<Dev> getDevwithEtat() ; 
}

当我执行它时,它说错误SQL&#34; NomDLL&#34;列未找到

它只是允许选择全部或不是,可能是结果列表所以它不能返回一个字段,所以如果有人知道改变结果类型,那么它可以得到2个字段的结果或三个不是所有的想法...随意回答(ps \&#34;是逃避,当我添加&#34; \ NomDev \&#34;我得到了<的错误/ p>

ERROR SQL&#34; IdEtatDev&#34;没找到)

任何帮助将不胜感激

0 个答案:

没有答案