-->
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.  [ 11 posts ] 
Author Message
 Post subject: Problem w/ quoted fields in generated SQL
PostPosted: Fri Dec 08, 2006 1:30 pm 
Regular
Regular

Joined: Mon Nov 14, 2005 7:33 pm
Posts: 73
I asked this question more than two weeks ago in the EJB 3.0 user forum for JBoss but haven't gotten a reply yet. I hope this isn't considered a "double post" but I'm getting rather desparate and thought maybe this was a more appropriate forum for this question?

I'm using a Progress 10.1 database that requires all queries to have quoted field names, e.g. select "name", "age" from customer.

In my entities, I'm using the back-tick (`) character to make sure field names are quoted. It works fine until I have parent-child relationship in a @OneToMany (bi-directional) setup.

Here are the entities:

Code:
@Entity
@Table(name="pub.customer")
public class Customer implements Serializable
{
  @Id
  @Column(name="`Cust-no`", nullable=false)
  private String custno;

  @OneToMany(mappedBy="customer")
  private List<CustomerOrder> orders;
...................
}

@Entity
@Table(name="pub.order")
public class CustomerOrder implements Serializable
{
  @EmbeddedId
  private CustomerOrderPK customerOrderPK;

  @Column(name="`Cust-no`", nullable=false, insertable=false, updatable=false)
  private String custno;

  @ManyToOne(fetch=FetchType.LAZY)
  @JoinColumn(name="`Cust-no`")
  private Customer customer;
.................
}


...and here's the PK class from the CustomerOrder entity, just for the sake of being thorough:

Code:
@Embeddable
public class CustomerOrderPK implements Serializable
{
  @Column(name="`Ar-entity`", nullable=false)
  private String arentity;

  @Column(name="`Order-no`")
  private Integer orderno;
.......................
}


I query it in a SLSB like so:

Code:
public Customer getTestCustomer(String custno)
  {
    String query = "select c from Customer c " +
        "left join fetch c.orders " +
        "where c.custno = :custno";
   
    Query q = this.em.createQuery(query);
    q.setParameter("custno", custno);
   
    return (Customer)q.getSingleResult();   
  }


Here is the query that is generated at runtime:

Code:
Hibernate:
    /* select
        c
    from
        Customer c
    left join
        fetch c.orders
    where
        c.custno = :custno */ select
            customer0_."Cust-no" as Cust1_160_0_,
            orders1_."Ar-entity" as Ar1_161_1_,
            orders1_."Order-no" as Order2_161_1_,
            customer0_."Name" as Name2_160_0_,
            customer0_."Filler1" as Filler3_160_0_,
            customer0_."City" as City4_160_0_,
            customer0_."St" as St5_160_0_,
            customer0_."Zip-code" as Zip6_160_0_,
            customer0_."Country" as Country7_160_0_,
            customer0_."Telephone" as Telephone8_160_0_,
            customer0_."Contact" as Contact9_160_0_,
            customer0_."Status-code" as Status10_160_0_,
            customer0_."Slsmn-code" as Slsmn11_160_0_,
            customer0_."Type-code" as Type12_160_0_,
            customer0_."Via-code" as Via13_160_0_,
            customer0_."Terr-code" as Terr14_160_0_,
            customer0_."Sort-name" as Sort15_160_0_,
            customer0_."Priority" as Priority16_160_0_,
            customer0_."Comm-code" as Comm17_160_0_,
            customer0_."Description" as Descrip18_160_0_,
            customer0_."Dest-loc" as Dest19_160_0_,
            customer0_."Country-code" as Country20_160_0_,
            customer0_."Address" as Address21_160_0_,
            customer0_."Partner" as Partner22_160_0_,
            customer0_."Residential" as Residen23_160_0_,
            customer0_."Gst-code" as Gst24_160_0_,
            customer0_."Cust-number" as Cust25_160_0_,
            customer0_."sls-contact" as sls26_160_0_,
            customer0_."hold-order" as hold27_160_0_,
            customer0_."supl-code" as supl28_160_0_,
            orders1_."In-entity" as In3_161_1_,
            orders1_."Whs-code" as Whs4_161_1_,
            orders1_."Cust-no" as Cust5_161_1_,
            orders1_."Ship-no" as Ship6_161_1_,
            orders1_."Cust-po" as Cust7_161_1_,
            orders1_."Order-date" as Order8_161_1_,
            orders1_."Order-code" as Order9_161_1_,
            orders1_."Slsmn-code" as Slsmn10_161_1_,
            orders1_."Via-desc" as Via11_161_1_,
            orders1_."Order-disc" as Order12_161_1_,
            orders1_."Ship-name" as Ship13_161_1_,
            orders1_."Ship-city" as Ship14_161_1_,
            orders1_."Ship-st" as Ship15_161_1_,
            orders1_."Ship-country" as Ship16_161_1_,
            orders1_."Ship-zip" as Ship17_161_1_,
            orders1_."Pps-no" as Pps18_161_1_,
            orders1_."Invoice-no" as Invoice19_161_1_,
            orders1_."Invoice-date" as Invoice20_161_1_,
            orders1_."Qty-orig-ord" as Qty21_161_1_,
            orders1_."Qty-shipped" as Qty22_161_1_,
            orders1_."Qty-open-ord" as Qty23_161_1_,
            orders1_."Alloc-qty" as Alloc24_161_1_,
            orders1_."Alloc-value" as Alloc25_161_1_,
            orders1_."Seq-no" as Seq26_161_1_,
            orders1_."Partial-inv" as Partial27_161_1_,
            orders1_."Estimate-no" as Estimate28_161_1_,
            orders1_."Total-weight" as Total29_161_1_,
            orders1_."Sent-by" as Sent30_161_1_,
            orders1_."Sent-order" as Sent31_161_1_,
            orders1_."Sent-entity" as Sent32_161_1_,
            orders1_."Transfer-to" as Transfer33_161_1_,
            orders1_."Via-code" as Via34_161_1_,
            orders1_."Country-code" as Country35_161_1_,
            orders1_."Dest-loc" as Dest36_161_1_,
            orders1_."Drop-ship" as Drop37_161_1_,
            orders1_."Site-code" as Site38_161_1_,
            orders1_."Ship-address" as Ship39_161_1_,
            orders1_."Trans-type" as Trans40_161_1_,
            orders1_."Trans-mode" as Trans41_161_1_,
            orders1_."Ship-site" as Ship42_161_1_,
            orders1_."Order-site" as Order43_161_1_,
            orders1_."ship-date" as ship44_161_1_,
            orders1_."address-no" as address45_161_1_,
            orders1_."bev-country" as bev46_161_1_,
            orders1_."Route-no" as Route47_161_1_,
            orders1_.Cust-no as Cust48_0__, --PROBLEM!!
            orders1_."Ar-entity" as Ar1_0__,
            orders1_."Order-no" as Order2_0__
        from
            pub.customer customer0_
        left outer join
            pub.order orders1_
                on customer0_."Cust-no"=orders1_.Cust-no --PROBLEM!!
        where
            customer0_."Cust-no"=?


As you can see, the field names are quoted but the right-hand side of the join is incorrect...the join field is not quoted, resulting in this exception:

Code:
Caused by: javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: cou
ld not execute query
        at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManag
erImpl.java:647)
        at org.hibernate.ejb.QueryImpl.getSingleResult(QueryImpl.java:99)
        at com.myapp.CustomerBean.getTestCustomer(CustomerBean.java:61)
...............................

Caused by: org.hibernate.exception.GenericJDBCException: could not execute query
        at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.j
ava:103)
        at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
        at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
        at org.hibernate.loader.Loader.doList(Loader.java:2147)
        at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2028)
        at org.hibernate.loader.Loader.list(Loader.java:2023)
        at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:393)
        at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
        at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
        at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
        at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
        at org.hibernate.ejb.QueryImpl.getSingleResult(QueryImpl.java:80)
        ... 71 more
Caused by: java.sql.SQLException: [DataDirect][OpenEdge JDBC Driver][OpenEdge] Column "ORDERS1_.CUST" cannot be found or is not specified for query. (13865)
        at com.ddtek.jdbc.openedge.client.OpenEdgeClientRequest.prepareProcessReply(Unknown Source)
        at com.ddtek.jdbc.openedge.client.OpenEdgeClientRequest.prepare(Unknown Source)
        at com.ddtek.jdbc.openedge.OpenEdgeImplStatement.prepare(Unknown Source)
        at com.ddtek.jdbc.base.BaseImplStatement.prepare(Unknown Source)
...............................................


Hibernate version: 3.2.0

EDIT - 12/11/2006

I've continued to test this for the past few days...I cannot get a @OneToMany, @OneToOne, or @ManyToMany to work correctly if the table's fields require quoting.

Should I file a bug report? Is this already a known bug? I would be happy to provide a small example project to demonstrate the problem.

I'm sorry to bump but I'm under tremendous pressure to finish a project and I'd rather not have to use Toplink in the place of Hibernate...but it does work correctly in Toplink.


Top
 Profile  
 
 Post subject: Re: Problem w/ quoted fields in generated SQL
PostPosted: Sun Dec 17, 2006 4:47 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
tsar bomba wrote:
Should I file a bug report? Is this already a known bug? I would be happy to provide a small example project to demonstrate the problem.

Yes please open a JIRA issue, I'm not sure whether it's an annotations bug of a core bug (reproduceable using hbm.xml files)

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 22, 2006 12:10 pm 
Regular
Regular

Joined: Mon Nov 14, 2005 7:33 pm
Posts: 73
I will most definitely create a simple test-case for you today and post it in JIRA.

Meanwhile, any chance you can point me to where in the source I might find the logic for this behavior? I'm rather desperate and am willing to at least try to fix it, if possible...however I'm not familiar w/ the innards of Hibernate and wouldn't even know where to begin.

I'm in a tight spot. While this works w/ Toplink...there are so MANY other problems w/ Toplink (via JPA) that I just can't trust it...at this point I can't complete this project w/ either Toplink or Hibernate...but I could if I could get past this quoting issue.

Thanks very much for your help!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 22, 2006 2:36 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Honestly, if there is a bug, its pretty weird, since it's pretty well tested. This might as well be something I haven't seen in your post. The test case will help.

If there is a bug, this is either:
- a wrong metadata translation AnnotationBinder and co
- a Persister bug
- an AST issue

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 22, 2006 2:43 pm 
Regular
Regular

Joined: Mon Nov 14, 2005 7:33 pm
Posts: 73
emmanuel wrote:
Honestly, if there is a bug, its pretty weird, since it's pretty well tested. This might as well be something I haven't seen in your post. The test case will help.

If there is a bug, this is either:
- a wrong metadata translation AnnotationBinder and co
- a Persister bug
- an AST issue


The test project I'm creating now is built against MSSQL 2000...but the actual issue I'm having is on Progress DB 10.1A - which is a bit less common. Could it somehow be database-specific?

My company acquired another one that uses Progress for everything, and they're fond of hyphenated names on tables and fields.

I'd create this sample app against Progress but I don't have it installed anywhere locally or on our LAN...we talk to their DB, which is huge, over the WAN.

Hell, I'd even be willing to slop it and hard-code the quotes around fields right into Hibernate just to get by until the real fix (if one is needed) can be introduced into the code-base.


Top
 Profile  
 
 Post subject: JIRA Issue Submitted...
PostPosted: Fri Dec 22, 2006 7:39 pm 
Regular
Regular

Joined: Mon Nov 14, 2005 7:33 pm
Posts: 73
I was able to reproduce the problem on MSSQL 2000 as previously described. I created a small, two-table/entity Netbeans 5.5 solution which I deployed to Glassfish V1 UR1 - using Hibernate 3.2.1 as the persistence engine.

The connection string could be changed to Postgres or something else, obviously...hopefully this is enough to nail down the issue!

Thanks very much!


Top
 Profile  
 
 Post subject: testing...
PostPosted: Mon Jan 22, 2007 1:24 pm 
Regular
Regular

Joined: Mon Nov 14, 2005 7:33 pm
Posts: 73
Emmanuel,

I noticed you left a message to test here:

http://opensource.atlassian.com/project ... se/ANN-515

...and I'd love to...but I'm not very familiar w/ Ant and so far have been unsuccessful. I downloaded everything from svn but get numerous errors associated w/ Hibernate missing...documentation missing, etc. I just don't know how to set it up right.

Is there a binary anywhere I can try? beta? anything? I'm anxious to see if this helps us...I'd use it immediately, if so.

If not, I suppose I'll just have to wait for 3.2.2 to be released to find out...however that doesn't do much good for testing to see if it's fixed.

Thanks for everything!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 24, 2007 3:49 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Try and follow those steps http://hibernate.org/6.html, you should be able to get the jars up and running

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 25, 2007 2:14 pm 
Regular
Regular

Joined: Mon Nov 14, 2005 7:33 pm
Posts: 73
emmanuel wrote:
Try and follow those steps http://hibernate.org/6.html, you should be able to get the jars up and running


I've tried following those instructions and I get a lot of failures. I have Ant 1.7 installed and ANT_HOME is set....and the instructions also say that you can just use build.bat to build it w/o using your local Ant installation...but both fail.

I did it again just now to show you what I get...

For Hibernate, typing "ant" gives me an antlr error:

Code:
C:\Documents and Settings\me\My Documents\Projects\Code Library\Hibernate3>ant
Buildfile: build.xml
  [taskdef] Could not load definitions from resource clovertasks. It could not b
e found.

splash:

init:
     [echo] Build Hibernate-3.2.0.cr3 (2007-01-25 10:58:01)
     [echo] JDK version: 1.6

init.antlr:

antlr:
    [mkdir] Created dir: C:\Documents and Settings\me\My Documents\Projects\
Code Library\Hibernate3\build\gensrc\org\hibernate\hql\antlr
[antlrtask] java.lang.NoClassDefFoundError: antlr/Tool
[antlrtask] Exception in thread "main"

BUILD FAILED
C:\Documents and Settings\me\My Documents\Projects\Code Library\Hibernate3\b
uild.xml:171: ANTLR returned: 1

Total time: 2 seconds


"build" for the build.bat file says JAVA_HOME isn't pointing to my JDK...but alas it is, so I just don't get that one:

Code:
C:\Documents and Settings\me\My Documents\Projects\Code Library\Hibernate3>b
uild

C:\Documents and Settings\me\My Documents\Projects\Code Library\Hibernate3>j
ava -cp "lib/ant-launcher-1.6.5.jar" org.apache.tools.ant.launch.Launcher -lib l
ib
Unable to locate tools.jar. Expected to find it in C:\Program Files\Java\jre1.6.0\lib\tools.jar
Buildfile: build.xml
  [taskdef] Could not load definitions from resource clovertasks. It could not b
e found.

splash:

init:
     [echo] Build Hibernate-3.2.0.cr3 (2007-01-25 10:58:17)
     [echo] JDK version: 1.5

init.antlr:

antlr:
[antlrtask] ANTLR Parser Generator   Version 2.7.6 (2005-12-22)   1989-2005
[antlrtask] ANTLR Parser Generator   Version 2.7.6 (2005-12-22)   1989-2005
[antlrtask] ANTLR Parser Generator   Version 2.7.6 (2005-12-22)   1989-2005
    [touch] Creating C:\Documents and Settings\me\My Documents\Projects\Code
Library\Hibernate3\build\gensrc\org\hibernate\hql\antlr\.antlr_run

compile:
    [mkdir] Created dir: C:\Documents and Settings\me\My Documents\Projects\
Code Library\Hibernate3\build\classes
    [javac] Compiling 1056 source files to C:\Documents and Settings\me\My D
ocuments\Projects\Code Library\Hibernate3\build\classes

BUILD FAILED
\Hibernate3\build.xml:209: Unable to find a javac compiler;
com.sun.tools.javac.Main is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK

Total time: 4 seconds


for HibernateExt, I get much of the same:

Code:
C:\Documents and Settings\me\My Documents\Projects\Code Library\HibernateExt
>ant
Buildfile: build.xml

BUILD FAILED
C:\Documents and Settings\me\My Documents\Projects\Code Library\HibernateExt
\build.xml:22: The following error occurred while executing this line:
C:\Documents and Settings\me\My Documents\Projects\Code Library\HibernateExt
\common\common-build.xml:61: C:\Documents and Settings\me\My Documents\Proje
cts\Code Library\hibernate-3.2\lib not found.

Total time: 0 seconds
C:\Documents and Settings\me\My Documents\Projects\Code Library\HibernateExt
>build

C:\Documents and Settings\me\My Documents\Projects\Code Library\HibernateExt
>set HIBERNATECORE=C:\Documents and Settings\me\My Documents\Projects\Code L
ibrary\HibernateExt\..\hibernate-3.2

C:\Documents and Settings\me\My Documents\Projects\Code Library\HibernateExt
>java -cp "C:\Documents and Settings\me\My Documents\Projects\Code Library\H
ibernateExt\..\hibernate-3.2\lib\ant-launcher-1.6.5.jar" org.apache.tools.ant.la
unch.Launcher -lib C:\Documents and Settings\me\My Documents\Projects\Code L
ibrary\HibernateExt\..\hibernate-3.2/lib
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/tools/ant/
launch/Launcher


Following the directions under the Annotations build section, w/ the two folders (Hibernate3 and HibernateExt) at the same level:

Code:
C:\Documents and Settings\me\My Documents\Projects\Code Library\Hibernate3>a
nt clean jar prepare-dir-up
Buildfile: build.xml
  [taskdef] Could not load definitions from resource clovertasks. It could not b
e found.

splash:

init:
     [echo] Build Hibernate-3.2.0.cr3 (2007-01-25 11:15:09)
     [echo] JDK version: 1.6

clean:
   [delete] Deleting directory C:\Documents and Settings\me\My Documents\Pro
jects\Code Library\Hibernate3\build

splash:

init:
     [echo] Build Hibernate-3.2.0.cr3 (2007-01-25 11:15:09)
     [echo] JDK version: 1.6

init.antlr:

antlr:
    [mkdir] Created dir: C:\Documents and Settings\me\My Documents\Projects\
Code Library\Hibernate3\build\gensrc\org\hibernate\hql\antlr
[antlrtask] java.lang.NoClassDefFoundError: antlr/Tool
[antlrtask] Exception in thread "main"

BUILD FAILED
C:\Documents and Settings\me\My Documents\Projects\Code Library\Hibernate3\b
uild.xml:171: ANTLR returned: 1

Total time: 1 second


Anyhow, I don't want to waste your time on my ignorance w/ Ant and how (not) to build Hibernate from source. I noticed core 3.2.2 was released today...hopefully Annoations is coming soon?

When the time comes, can the hibernate/annoations jars just be dropped into JBoss 4.0.5 or will that break other things?

Thanks, sorry I can't be more helpful in testing.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 25, 2007 5:02 pm 
Regular
Regular

Joined: Mon Nov 14, 2005 7:33 pm
Posts: 73
Whoo hoo!

Finally, after some trial and error (and shooting self in foot) - I was able to successfully build HibernateExt - and the quoting issue appears to be fixed.

It works in the sample application I submitted w/ the bug report, I will now try it on our Progress-backed app.

I staggered through it by downloading Hibernate core 3.2.2, unzipping it to the same level directory as the 3.2 annotations svn branch "HibernateExt" folder....and then running plain 'ol "ant" inside of the metadata folder.

Thanks so much! I'm extremely impressed w/ how fast you were able to fix this and get it out.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 29, 2007 4:13 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
no pb
Apparently, there might be some javac discovery issues with JDK 6, we'll need to have a look

_________________
Emmanuel


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

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.