-->
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.  [ 4 posts ] 
Author Message
 Post subject: Don't get JOIN work'in - "unexpected token"
PostPosted: Tue May 31, 2005 5:46 pm 
Beginner
Beginner

Joined: Tue May 31, 2005 5:36 pm
Posts: 21
Guys, I have the following problem:

I'd like to do a Query with a JOIN over 2 Tables.

When I perform the query with the HSQL Database Manager, everything works fine:
Code:
SELECT * FROM kunde k JOIN ticketcard t ON t.kartennr = k.kartennr WHERE t.vname LIKE 'Morgan' AND t.nname LIKE 'Breitfuss' AND k.kartennr = 8;


But if I try the same query in my own Java code, the only thing I get is the following Unexpected Token Exception. :cry:
Code:
              Session session = HibernateSessionFactory.currentSession();
              //List vlist = session.find("FROM Veranstaltung WHERE Dauer >= 112 ORDER BY Dauer ASC");
                 session.find("SELECT * FROM kunde JOIN ticketcard ON ticketcard.kartennr = kunde.kartennr WHERE ticketcard.vname LIKE 'Morgan' AND ticketcard.nname LIKE 'Breitfuss' AND kunde.kartennr = 8");

Code:
java.lang.RuntimeException: unexpected token: join [SELECT * FROM kunde JOIN ticketcard ON ticketcard.kartennr = kunde.kartennr WHERE ticketcard.vname LIKE 'Morgan' AND ticketcard.nname LIKE 'Breitfuss' AND kunde.kartennr = 8]
    at ticketline.WebAccount$1.widgetSelected(WebAccount.java:153)
    at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:89)
    at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:82)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:842)
    at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:2908)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2541)
    at ticketline.MainApp1.open(MainApp1.java:736)
    at ticketline.MainApp1.runMain(MainApp1.java:103)
    at ticketline.Login1$2.widgetSelected(Login1.java:139)
    at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:89)
    at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:82)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:842)
    at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:2908)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2541)
    at ticketline.Login1.open(Login1.java:216)
    at ticketline.Login1.main(Login1.java:61)


Can someone explain what I did wrong? I don't see any fault in my code ...

------------------
Hibernate version: 2


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 31, 2005 5:59 pm 
Senior
Senior

Joined: Tue Feb 08, 2005 5:26 pm
Posts: 157
Location: Montréal, Québec - Canada
HQL Examples that I see always use alias... maybe it is required:

try:


FROM kunde as kun JOIN ticketcard as tick ON tick.kartennr = kun.kartennr WHERE tick.vname LIKE 'Morgan' AND tick.nname LIKE 'Breitfuss' AND kun.kartennr = 8

Let me know if it works
Good luck,

_________________
Vincent Giguère
J2EE Developer


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 31, 2005 6:04 pm 
Beginner
Beginner

Joined: Tue May 31, 2005 5:36 pm
Posts: 21
vgiguere wrote:
FROM kunde as kun JOIN ticketcard as tick ON tick.kartennr = kun.kartennr WHERE tick.vname LIKE 'Morgan' AND tick.nname LIKE 'Breitfuss' AND kun.kartennr = 8

Hummmmm ... unfortunately this is not the solution. Seems that AS is an unexpected token too ...
Code:
java.lang.RuntimeException: unexpected token: as [FROM kunde as kun JOIN ticketcard as tick ON tick.kartennr = kun.kartennr WHERE tick.vname LIKE 'Morgan' AND tick.nname LIKE 'Breitfuss' AND kun.kartennr = 8]
   at ticketline.WebAccount$1.widgetSelected(WebAccount.java:153)
   at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:89)
   at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:82)
   at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:842)
   at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:2908)
   at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2541)
   at ticketline.MainApp1.open(MainApp1.java:736)
   at ticketline.MainApp1.runMain(MainApp1.java:103)
   at ticketline.Login1$2.widgetSelected(Login1.java:139)
   at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:89)
   at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:82)
   at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:842)
   at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:2908)
   at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2541)
   at ticketline.Login1.open(Login1.java:216)
   at ticketline.Login1.main(Login1.java:61)


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 31, 2005 6:06 pm 
Senior
Senior

Joined: Tue Feb 08, 2005 5:26 pm
Posts: 157
Location: Montréal, Québec - Canada
kunde is your table name or your entity name?

_________________
Vincent Giguère
J2EE Developer


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.