Hibernate query (HQL) in Java with foreign key ... ERROR!

1

I need help with my code, I have two tables: -CDF (Employee Registry)

CREATE TABLE public.cdf(
    ativo character varying(1) COLLATE pg_catalog."default",
    reg integer NOT NULL,
    nome character varying(30) COLLATE pg_catalog."default" NOT NULL,
    senha character varying(33) COLLATE pg_catalog."default" NOT NULL,
    CONSTRAINT cdf_pkey PRIMARY KEY (reg)
)

-RGPT (Record of Point) with 2 Foreign Keys of CDF: reg - > registry number and nome

CREATE TABLE public.rgpt(
    id_rgpt integer NOT NULL DEFAULT nextval('rgpt_id_rgpt_seq'::regclass),
    reg integer NOT NULL,
    nome character varying(30) COLLATE pg_catalog."default" NOT NULL,
    entrada character varying(5) COLLATE pg_catalog."default",
    saida character varying(5) COLLATE pg_catalog."default",
    CONSTRAINT rgpt03_pkey1 PRIMARY KEY (id_rgpt),
        CONSTRAINT rgpt_fk FOREIGN KEY (reg)
        REFERENCES public.cdf (reg) MATCH SIMPLE
        ON UPDATE CASCADE
        ON DELETE NO ACTION,
    CONSTRAINT rgpt_fk1 FOREIGN KEY (nome)
        REFERENCES public.cdf (nome) MATCH SIMPLE
        ON UPDATE CASCADE
        ON DELETE NO ACTION
)

In my Hibernate-generated entities my RGPT foreign keys look like this: Java:

public class Rgpt:

     private int idRgpt;
     private Cdf cdfByReg;
     private Cdf cdfByNome;
     private String entrada;
     private String saida;

    public Cdf getCdfByReg() {
        return this.cdfByReg;
    }

    public void setCdfByReg(Cdf cdfByReg) {
        this.cdfByReg = cdfByReg;
    }
    public Cdf getCdfByNome() {
        return this.cdfByNome;
    }

    public void setCdfByNome(Cdf cdfByNome) {
        this.cdfByNome = cdfByNome;
    }

And the XML:

<class name="DAO.entity.Rgpt" table="rgpt" schema="public" optimistic-    lock="version">
    <id name="idRgpt" type="int">
        <column name="id_rgpt" />
        <generator class="assigned" />
    </id>
    <many-to-one name="cdfByReg" class="DAO.entity.Cdf" fetch="select">
        <column name="reg" not-null="true" />
    </many-to-one>
    <many-to-one name="cdfByNome" class="DAO.entity.Cdf" fetch="select">
        <column name="nome" not-null="true" />
    </many-to-one>

The problem is when I'm going to do the HQL query and it gives a very strange error: Inquiry:

final Session session = HibernateUtil.getSessionFactory().openSession();
String query = "from Rgpt as r where r.cdfByReg.reg= 54 and DATE(r.data) = '" + d.getDiaMesAno(data) + "'";
Query q = session.createQuery(query);
Rgpt rgpt = (Rgpt) q.uniqueResult();

ERROR:

  

Hibernate: select rgpt0_.id_rgpt as id_rgpt1_1_, rgpt0_.reg as   reg2_1_, rgpt0_.name the name3_1_, rgpt0_.on the em4_1_, rgpt0_.ema as   ema5_1_, rgpt0_.sm as sm6_1_, rgpt0_.sma as sma7_1_, rgpt0_.et as   The compositions of the present invention may be prepared by the following methods:   sta11_1_, rgpt0_.eadd as eadd12_1_, rgpt0_.sadd as sadd13_1_,   rgpt0_.just as just14_1_, rgpt0_.data as data15_1_, rgpt0_.sem as   sem16_1_, rgpt0_.tdia asdia17_1_, rgpt0_.ttaj as ttaj18_1_,   rgpt0_.dif the dif19_1_, rgpt0_.vt as vt20_1_, rgpt0_.bn as bn21_1_,   rgpt0_.grat_integral as grat_in22_1_, rgpt0_.grat_metade as   grat_me23_1_, rgpt0_.vr as vr24_1_, rgpt0_.va_integral as   va_inte25_1_, rgpt0_.va_metade as va_meta26_1_ from public.rgpt rgpt0_   where (rgpt0_.reg =?) and (DATE (rgpt0_.data) = '23/03/2017') Mar 23, 2017   4:54:44 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper   logExceptions WARN: SQL Error: 0, SQLState: 22003 Mar 23, 2017 4:54:44   PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions   ERROR: Invalid value for int type: ESTER

Somehow it is catching nome (varchar) instead of reg (int), but references at first seem correct.

Does anyone know if I have something wrong with my query or code? Thanks!

    
asked by anonymous 23.03.2017 / 22:12

0 answers