IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Java Discussion :

transformer une requete sql en hql


Sujet :

Java

  1. #1
    Futur Membre du Club
    Femme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2016
    Messages
    11
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Avril 2016
    Messages : 11
    Points : 9
    Points
    9
    Par défaut transformer une requete sql en hql
    Bonjour,
    j' ai la requete suivante en sql , j vais afficher dans le console une partie de la table boncarburant et une partie de la table carburant avec une jointure mais ma requete hql est toujours fausse, voila la requete en sql :
    SELECT `boncarburantReference`, `personnelReference`, `boncarburantMontant`, `boncarburantValeurLitre`, `typeId`,carburantLibelle
    FROM Boncarburant
    JOIN Carburant ON
    Boncarburant.carburantId=Carburant.carburantId

  2. #2
    Expert confirmé
    Profil pro
    Inscrit en
    Août 2006
    Messages
    3 274
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 3 274
    Points : 4 166
    Points
    4 166
    Par défaut
    Montre nous tes entités JPA pour qu'on voit la relation entre tes deux classes.

  3. #3
    Futur Membre du Club
    Femme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2016
    Messages
    11
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Avril 2016
    Messages : 11
    Points : 9
    Points
    9
    Par défaut trasformer une requete sql en hql
    voila les deux entité,malgre je pense que j'ai mal indexé le carburantId dans la table boncarburant:
    entité carburant
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    public class Carburant extends Entite implements java.io.Serializable {
     
    	/**
             * 
             */
    	private static final long serialVersionUID = -5196076758286887105L;
    	private Integer carburantId;
    	private String carburantLibelle;
    	private Float carburantPrixLitre;
    	private Integer carburantNum;
     
     
    	public Carburant() {
    	}
     
    	public Carburant(String carburantLibelle, Float carburantPrixLitre, Integer carburantNum) {
    		this.carburantLibelle = carburantLibelle;
    		this.carburantPrixLitre = carburantPrixLitre;
    		this.carburantNum = carburantNum;
    	}
     
    	@Id
    	@GeneratedValue(strategy = GenerationType.IDENTITY)
    	@Column(name = "carburantId", unique = true, nullable = false)
    	public Integer getCarburantId() {
    		return this.carburantId;
    	}
     
    	public void setCarburantId(Integer carburantId) {
    		this.carburantId = carburantId;
    	}
     
    	@Column(name = "carburantLibelle", length = 254)
    	public String getCarburantLibelle() {
    		return this.carburantLibelle;
    	}
     
    	public void setCarburantLibelle(String carburantLibelle) {
    		this.carburantLibelle = carburantLibelle;
    	}
    entite boncarburant
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    public class Boncarburant extends Entite implements java.io.Serializable {
     
    	private static final long serialVersionUID = -5196076758286887105L;
    	private Integer boncarburantReference;
    	private Integer personnelReference;
    	private Carburant carburantId;
    	private Integer boncarburantMontant;
    	private Float boncarburantValeurLitre;
    	private Integer typeId;
     
     
     
    	public Boncarburant ()
    	{
     
    	}
     
    	public Boncarburant(Integer boncarburantReference, Integer personnelReference, Carburant carburantId, Integer boncarburantMontant
    			,Float boncarburantValeurLitre, Integer typeId
    			) {
    		super();
    		this.boncarburantReference = boncarburantReference;
    		this.personnelReference = personnelReference;
    		this.carburantId = carburantId;
    		this.boncarburantMontant = boncarburantMontant;
    		this.boncarburantValeurLitre= boncarburantValeurLitre;
    		this.typeId = typeId;
     
     
    	}
     
    	@Id
    	@GeneratedValue (strategy = GenerationType.IDENTITY)
    	@Column(name = "boncarburantReference", unique = true, nullable = false)
    	public Integer getBoncarburantReference() {
    		return boncarburantReference ;
    	}
     
     
    	public void setBoncarburantReference(Integer boncarburantReference) {
    		this.boncarburantReference = boncarburantReference;
    	}
     
    	@Column(name = "personnelReference")
    	public Integer getPersonnelReference() {
    		return personnelReference;
    	}
     
     
    	public void setPersonnelReference(Integer personnelReference) {
    		this.personnelReference = personnelReference;
    	}
     
    	@ManyToOne
    	@JoinColumn(name="carburantId")
    	public Carburant getCarburantId() {
    		return carburantId;
    	}
     
     
    	public void setCarburantId(Carburant carburantId) {
    		this.carburantId = carburantId;
    	}
     
    	@Column(name = "boncarburantMontant")
    	public Integer getBoncarburantMontant() {
    		return boncarburantMontant;
    	}
     
     
    	public void setBoncarburantMontant(Integer boncarburantMontant) {
    		this.boncarburantMontant = boncarburantMontant;
    	}
     
    	@Column(name = "boncarburantValeurLitre")
    	public Float getBoncarburantValeurLitre() {
    		return boncarburantValeurLitre;
    	}
     
     
    	public void setBoncarburantValeurLitre(Float boncarburantValeurLitre) {
    		this.boncarburantValeurLitre = boncarburantValeurLitre;
    	}

  4. #4
    Expert confirmé
    Profil pro
    Inscrit en
    Août 2006
    Messages
    3 274
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 3 274
    Points : 4 166
    Points
    4 166
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    From Boncarburant bc inner join fetch bc.carburantId
    Ca te renverra une liste d'objets Boncarburant.
    Le carburant de chaque objet sera initialisé et tu pourras récupérer ses données.

  5. #5
    Futur Membre du Club
    Femme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2016
    Messages
    11
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Avril 2016
    Messages : 11
    Points : 9
    Points
    9
    Par défaut
    merci pour ton requete, si je cherche la reference,elle m'a donné mais je veux dans la console qu'elle m'affiche par exemple la reference de boncarburant et le libelle du carburant : l'appel dans le bean est comme ça mais j'ai eu erreur
    :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
     
    @PostConstruct
    	public void Initialize() {
    		titre = "Ajouter Boncarburant";
     
    		listboncarburant = new ArrayList<Boncarburant>();
    		try {
    			listboncarburant = appMgr.getList(Boncarburant.class);
    			Collections.reverse(listboncarburant);
    			listboncarburantDM.setWrappedData(listboncarburant);
     
    		Carburant c =(Carburant)appMgr.listBoncarburantByID(2).get(0);
    		   Boncarburant b = (Boncarburant) appMgr.listBoncarburantByID(1).get(0);
    			System.out.println("num de bon et nom : "+b.getBoncarburantReference()+c.getCarburantLibelle());	
     
    		} catch (Exception e) {
    			e.printStackTrace();
    			System.out.println("erreur");
    		}
     
     
    	}

  6. #6
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 481
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 481
    Points : 48 806
    Points
    48 806
    Par défaut
    et on sort une boule de cristal pour deviner l'erreur?

  7. #7
    Futur Membre du Club
    Femme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2016
    Messages
    11
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Avril 2016
    Messages : 11
    Points : 9
    Points
    9
    Par défaut
    Dans mon catch,j'ai system.out.println("erreur");
    donc il n va pas traité le try ou je veux qu'il ecrit les bons ,il traite le catch

  8. #8
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 481
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 481
    Points : 48 806
    Points
    48 806
    Par défaut
    cool et la stacktrace qui contient les informations utiles?

  9. #9
    Futur Membre du Club
    Femme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2016
    Messages
    11
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Avril 2016
    Messages : 11
    Points : 9
    Points
    9
    Par défaut
    j'ai mis les deux entité concerné,le post contruct qui va me faire l'affichage, voila la list defini dans l'appMgr,il me reste just le query,et concernant le postconstruct,je pense qu'il a un erreur et j'ai mal fait l'appel :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    private static final String LIST_BONCARBURANT_BY_ID = "getboncarburantbyid";
     
    	@SuppressWarnings("unchecked")
     
    	       public List<?> listBoncarburantByID(int boncarburantReference) {
     
    	             return  (List<?>) dao.getListWithNamedQuery(LIST_BONCARBURANT_BY_ID, with("id", boncarburantReference).parameters());
     
    	       }
    voila le stachtrace :

Discussions similaires

  1. transformer une requete sql en expresion sous qlikview
    Par elkhansa dans le forum QlikView
    Réponses: 2
    Dernier message: 26/07/2011, 15h31
  2. Equivalence d'une requete SQL En HQL
    Par baichoch dans le forum Hibernate
    Réponses: 1
    Dernier message: 26/05/2010, 17h32
  3. Convertir une requete SQL en HQL
    Par moutambo dans le forum Hibernate
    Réponses: 7
    Dernier message: 04/05/2010, 17h22
  4. Convertir une requete SQL en HQL d'Hibernate
    Par Incinerator dans le forum Hibernate
    Réponses: 2
    Dernier message: 11/11/2008, 13h15
  5. Convertir une requete SQL en HQL d'Hibernate
    Par Incinerator dans le forum Hibernate
    Réponses: 1
    Dernier message: 10/11/2008, 19h00

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo