-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Strange SQL-Statement when using DB2-Dialect!!!
PostPosted: Thu May 28, 2009 7:08 am 
Newbie

Joined: Tue May 26, 2009 6:01 am
Posts: 3
Location: Hannover, Germany
Hi everyone!

I'm facing a problem with the DB2-Dialect. Has anyone an idea where the problem is and how to fix it?!?

I'm using a DB2-Database on a z/OS-HOST and in my persistence.xml I set the dialect to "org.hibernate.dialect.DB2Dialect".

In my example I try to exequte a Named Query which is quite simple: "SELECT MAX(vtr.vtrId) FROM Vertrag AS vtr".

During deployment I get the following two log-messages:
2009-05-28 12:50:30,183 DEBUG - org.hibernate.hql.ast.QueryTranslatorImpl - HQL: SELECT MAX(vtr.vtrId) FROM de.ivv.aa.ejb3test.business.Vertrag AS vtr
2009-05-28 12:50:30,183 DEBUG - org.hibernate.hql.ast.QueryTranslatorImpl - SQL: select MAX(vertrag0_.vtrId) as col_0_0_ from EJB3_VTR vertrag0_

I would say these look fine!

But the app-server-log-output tells me that hibernate is trying to sent the following SQL statement:
"select * from ( select rownumber() over() as rownumber_, MAX(vertrag0_.vtrId) as col_0_0_ from EJB3_VTR vertrag0_ ) as temp_ where rownumber_ <= 2)"

The exception fron the DB2-Driver is the following:
"com.ibm.db2.jcc.a.nn: DB2 SQL Error: SQLCODE=-104, SQLSTATE=42601, SQLERRMC=(;, FROM INTO, DRIVER=3.52.95"

Here is the code of my example:
Vertrag.java
Code:
package de.ivv.aa.ejb3test.business;
import javax.persistence.*;
import java.io.Serializable;

@Entity
@Table(name="EJB3_VTR")
@IdClass(VertragPK.class)
@NamedQueries({
    @NamedQuery(
        name="Vertrag.getMaxId",
        query="SELECT MAX(vtr.vtrId) FROM Vertrag AS vtr"),
    @NamedQuery(
        name="Vertrag.getMinId",
        query="SELECT MIN(vtr.vtrId) FROM Vertrag AS vtr")
})
public class Vertrag implements Serializable {   
   
    private static final long serialVersionUID = -1456605707899218208L;
    private Integer vtrId;

    @Id @Column(name="vtrId")
    public Integer getVtrId() {return this.vtrId;}
    public void setVtrId(Integer aVtrId) {this.vtrId = aVtrId;}

    private String vsnr;

    @Column(name="VSNR")
    public String getVsnr() {return this.vsnr;}
    public void setVsnr(String aVsnr) {this.vsnr = aVsnr;}
}


SvcPersistierungBean.java
Code:
package de.ivv.aa.ejb3test.business;

import ...;

@Local(SvcPersistierung.class)
@LocalHome(SvcPersistierungHome.class)
@Stateless(name="SvcPersistierung", mappedName="ejb/de.ivv.aa.ejb3test.business.SvcPersistierung")
public class SvcPersistierungBean {
   
    private static Log log = LogFactory.getLog(SvcPersistierungBean.class);
   
    @PersistenceContext(unitName="aa_ejb3test_business")
    private EntityManager em;

    public void doTheExample(Vertrag beVertrag) {
        log.entering(this.getClass(), "anlegenSchwebeVertrag(...)", "beVertrag=" + beVertrag);
       
        int maxVtrId = new Integer(0);
        int minVtrId = new Integer(0);
       
        Object resultMax = null;
        Object resultMin = null;
       
        Query queryMax = this.em.createNamedQuery("Vertrag.getMaxId");
        resultMax = queryMax.getSingleResult();
        if (resultMax != null) {
            maxVtrId = ((Integer)resultMax).intValue();
        }
       
        Query queryMin = this.em.createNamedQuery("Vertrag.getMinId");
        resultMin = queryMin.getSingleResult();
        if (resultMin != null) {
            minVtrId = ((Integer)resultMin).intValue();
        }
       
        if (minVtrId * (-1) > maxVtrId) {
            maxVtrId = minVtrId * (-1);
        }
        int vtrId = (maxVtrId + 1) * (-1);
       
        beVertrag.setVtrId(new Integer(vtrId));
        this.em.persist(beVertrag);
       
        log.exiting(this.getClass(), "anlegenSchwebeVertrag(...)");
    }

}


And the Test-Class for the JUnit-Test:
TestSvcPersistierung.java

Code:
package de.ivv.aa.ejb3test.business;
import ...;

public class TestSvcPersistierung extends ServletTestCase {

    private static Log log = LogFactory.getLog(TestSvcPersistierung.class);
    private SvcPersistierung svcPers;
   
    public void setUp() throws Exception {
        log.entering(this.getClass(), "setUp()");
        Hashtable<Object,Object> ht = new Hashtable<Object,Object>();
        ht.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
        ht.put(Context.PROVIDER_URL, "t3://localhost:7001");
        InitialContext ctx = new javax.naming.InitialContext(ht);
        SvcPersistierungHome svcPersHome = (SvcPersistierungHome) ctx.lookup("ejb/de.ivv.aa.ejb3test.business.SvcPersistierung#de.ivv.aa.ejb3test.business.SvcPersistierungHome");
        this.svcPers = svcPersHome.create();
        log.exiting(this.getClass(), "setUp()");
    }

    public void testAnlegenSchwebeVertrag() throws Exception {
        log.entering(this.getClass(), "testAnlegenSchwebeVertrag()");
        Vertrag beVtr = new Vertrag();
       
        beVtr.setVsnr("1234.56.7890");
       
        log.debug(this.getClass(), "testAnlegenSchwebeVertrag()", "Geflecht erzeugt!");
        try {
            this.svcPers.doTheExample(beVtr);
            log.debug(this.getClass(), "testAnlegenSchwebeVertrag()", "Schwebe-Vertrag erzeugt.");
        } catch (Exception ex) {
            log.error(this.getClass(), "testAnlegenSchwebeVertrag()", "Exception=" + ex.getMessage(), ex);
            throw ex;
        } finally {
            log.exiting(this.getClass(), "testAnlegenSchwebeVertrag()");
        }
    }
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.