SQLException: xxxxx invalid identifier

293 views
Skip to first unread message

Gadille Lionel

unread,
Oct 24, 2012, 8:35:33 AM10/24/12
to eb...@googlegroups.com
hello,

I'am using ebean on play without problem on play 2.0.4 (ebean version 2.7.3)
But i don't understood that is happening with oracle

the sql build is not compatible with oracle

This is the Model class
package models.apogee;

import java.util.List;

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.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import play.db.ebean.Model.Finder;
import play.db.ebean.Model;

@Entity
@Table(name="INDIVIDU")
public class Individu extends Model {
   
    //Code Etudiant au sein de l"Etablissement
    @Id
    @Column(name="COD_IND")
    public long COD_IND;
    //Nom Patronymique Etudiant
    @Column(name="LIB_NOM_PAT_IND")
    public String LIB_NOM_PAT_IND;
    //prenom
    @Column(name="LIB_PR1_IND")
    public String LIB_PR1_IND;
   
    //code du pays 100=france liaisons vers  pays cod_pay
      public String COD_PAY_NAT;
       

    
    public static Finder<String, Individu> find = new Finder<>("apogee", String.class, Individu.class);   
}

The sql build is

select t0.COD_IND c0, t0.LIB_NOM_PAT_IND c1, t0.LIB_PR1_IND c2, t0.cod_pay_nat c3
from INDIVIDU t0
where INDIVIDU.LIB_NOM_PAT_IND = ?  and INDIVIDU.LIB_PR1_IND = ? 

exception: Caused by: javax.persistence.PersistenceException: Query threw SQLException:ORA-00904: "INDIVIDU"."LIB_PR1_IND": invalid identifier


note this requette build byhand is correct

select COD_IND c0, LIB_NOM_PAT_IND c1, LIB_PR1_IND c2, cod_pay_nat c3
from INDIVIDU 
where INDIVIDU.LIB_NOM_PAT_IND = 'ABBOUD' and INDIVIDU.LIB_PR1_IND like 'CL%'

here to see to cause db2 error
i don't have the hand on the db2 server
i don't know anything on it except how to connect by jdbc driver
i use a jar call ojdbc14.jar
...
I'am lost i see that sql build by ebean is not compatible with my oracle but i don't know that paraméter i can use

thanks for help , lionel




Daryl Stultz

unread,
Oct 24, 2012, 8:44:39 AM10/24/12
to eb...@googlegroups.com

On Wednesday, October 24, 2012, Gadille Lionel wrote:
This is the Model class

 
The sql build is

select t0.COD_IND c0, t0.LIB_NOM_PAT_IND c1, t0.LIB_PR1_IND c2, t0.cod_pay_nat c3
from INDIVIDU t0
where INDIVIDU.LIB_NOM_PAT_IND = ?  and INDIVIDU.LIB_PR1_IND = ? 

exception: Caused by: javax.persistence.PersistenceException: Query threw SQLException:ORA-00904: "INDIVIDU"."LIB_PR1_IND": invalid identifier


Please provide the Java code that resulted in the above query.

/Daryl 

Gadille Lionel

unread,
Oct 24, 2012, 8:48:25 AM10/24/12
to eb...@googlegroups.com

sorry i forgot this part

Individu ind=Individu.find.where()
                .eq("INDIVIDU.LIB_NOM_PAT_IND",user.lastname)
                .eq("INDIVIDU.LIB_PR1_IND",user.firstname)
                .findUnique();

lionel

Daryl Stultz

unread,
Oct 24, 2012, 8:55:09 AM10/24/12
to eb...@googlegroups.com
Drop the table name from the query:

Individu ind=Individu.find.where()
                .eq("LIB_NOM_PAT_IND",user.lastname)
                .eq("LIB_PR1_IND",user.firstname)
                .findUnique();

Anything Ebean can't match to the model gets passed through as-is. Which is a feature or a bug depending on your level of understanding of Ebean.

Also, there's no reason your Java field names need to match the database column names. You could call LIB_NOM_PAT_IND "lastName" for example. This might make your code more readable.

/Daryl

Gadille Lionel

unread,
Oct 24, 2012, 9:25:33 AM10/24/12
to eb...@googlegroups.com
thanks a lot

i was turning around since 2hours

i have a question on hybernate to use  multi @id
i use something like  @IdClass(models.compositeKeys.VDIFVET.class)

it is the same way for ebean?
i will look for that i some minute ...

you are very good
and  help me a lot
(excuse my English level)

Daryl Stultz

unread,
Oct 24, 2012, 9:33:00 AM10/24/12
to eb...@googlegroups.com

On Wednesday, October 24, 2012, Gadille Lionel wrote:
i have a question on hybernate to use  multi @id
i use something like  @IdClass(models.compositeKeys.VDIFVET.class)

Sorry, I'm afraid I know little about Hibernate and I have not used composite keys at all.

/Daryl 

edge

unread,
Oct 24, 2012, 9:56:02 AM10/24/12
to eb...@googlegroups.com
create a bean with your primary keys and annotate with embeddable e.g

@Embeddable
public class MyPK{
    private Long key1;
    private String key 2;

    // Getter and setters
   .....
}


then you can use is as an Id your entity

@Entity
public class MyEntity{

    @EmbeddedId
    private MyPK

Gadille Lionel

unread,
Oct 24, 2012, 11:56:14 AM10/24/12
to eb...@googlegroups.com
it's ok no problem with ebean on composite keys
not very surprising in fact because  composite keys don't deal with dtb access  implement that provide only object comparison purpose

here an example if you need it one day

@Entity
@Table(name="IND_BAC")
@IdClass(models.apogee.compositeKeys.IndBac.class)
public class IndBac {

    @Id
    @Column(name="COD_IND")
    public long COD_IND;
   
    @Id
    @Column(name="COD_BAC")
    public String COD_BAC;
}

and the implementation of the composite keys

public class IndBac implements Serializable {   
    public long COD_IND;
    public String COD_BAC;
   
    @Override
    public boolean equals(Object o) {
        if (o == null || !(o instanceof IndBac)) {
            return false;
        }
        IndBac indBac = (IndBac) o;
        if (COD_BAC != null && indBac.COD_BAC != null )
            return COD_IND == indBac.COD_IND  && COD_BAC.equals(indBac.COD_BAC);
         else
            return super.equals(o);       
    }

    @Override
    public int hashCode() {
         return (COD_BAC != null ? COD_BAC.hashCode() : 0) +
                 + (int)COD_IND;
    }
}

The purpose is to provide good equals and comparaison object




Reply all
Reply to author
Forward
0 new messages