-->
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.  [ 2 posts ] 
Author Message
 Post subject: Relationship building in createSQLQuery using a join table
PostPosted: Tue Feb 07, 2006 11:27 pm 
Newbie

Joined: Sun Apr 11, 2004 2:25 am
Posts: 9
Hibernate version:
Hibernate 3.1.2

Mapping documents:
Not provided, mostly a syntax question, however they are Hibernate 2.0 mapping files.



Hey guys, quick use question. I've ran into a problem attempting to use a join table (many-2-many) in createSQLQuery when building relationships.

To illustrate the problem I'm going to use the box -> ball analogy; that is box is mapped to ball via a many-2-many table (ball_for_box).

An attempt to load a box and its collection of balls using the many-2-many table and createSQLQuery could look as follows:

Code:
SQLQuery query = sess.createSQLQuery("select {box.*}, {ball.*}, {joinTable.*} from Box box left join Ball_For_Box {joinTable} on joinTable.box_id = box.box_id left join Ball ball on joinTable.ball_id = ball.ball_id

query.addEntity("box", Box.class);
query.addEntity("ball", Ball.class);
query.addJoin("joinTable, "box.balls");

query.list();


The above code works in Hibernate 3.0.4, however appears to fail in the newest version:

Code:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1
   at org.hibernate.loader.custom.SQLQueryParser.substituteBrackets(SQLQueryParser.java:133)
   at org.hibernate.loader.custom.SQLQueryParser.process(SQLQueryParser.java:85)
   at org.hibernate.loader.custom.SQLCustomQuery.<init>(SQLCustomQuery.java:157)
   at org.hibernate.engine.query.NativeSQLQueryPlan.<init>(NativeSQLQueryPlan.java:21)
   at org.hibernate.engine.query.QueryPlanCache.getNativeSQLQueryPlan(QueryPlanCache.java:113)
   at org.hibernate.impl.AbstractSessionImpl.getNativeSQLQueryPlan(AbstractSessionImpl.java:140)
   at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:147)
   at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:164)

...


I saw no code demonstrating the use of a join table (In this case "Ball_For_Box") when building relationships in createSQLQuery anywhere. Any help is appreciated!

Note, the following code gives the same exception:

Code:
SQLQuery query = sess.createSQLQuery("select {box.*}, {ball.*}, joinTable.* from Box box left join Ball_For_Box joinTable on joinTable.box_id = box.box_id left join Ball ball on joinTable.ball_id = ball.ball_id

query.addEntity("box", Box.class);
query.addJoin("ball", "box.balls");

query.list();


Thanks in advance


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 08, 2006 3:42 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
submit a *minimal* and *runnable* test case. sounds like a bug in the alias injection handling.

_________________
Max
Don't forget to rate


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.