• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Chapter 11 nativequeries example modification for MySQL users

 
Bartender
Posts: 2450
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, for all MySQL users,
here is the modification I need to make in Employee.java class:


Since MySQL cannot interpret the Oracle specific SQL, I need to use a simple MySQL SQL.
If we use the Oracle SQL for MySQL, the createNamedQuery method will not work and it outputs an error :


Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'manager_id = 1 CONNECT BY PRIOR emp_id = manager_id' at line 1
Error Code: 1064
Call: SELECT emp_id, name, salary FROM emp START WITH manager_id = ? CONNECT BY PRIOR emp_id = manager_id
bind => [1 parameter bound]
Query: ReadAllQuery(referenceClass=Employee sql="SELECT emp_id, name, salary FROM emp START WITH manager_id = ? CONNECT BY PRIOR emp_id = manager_id")
at org.eclipse.persistence.internal.jpa.QueryImpl.getDetailedException(QueryImpl.java:378)...

 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There's a "with" clause in standard sql however MySQL somewhat doesn't fully support the "with recursive"

http://stackoverflow.com/questions/959804/simulation-of-connect-by-prior-of-oracle-in-sql-server

http://mysqlserverteam.com/with-recursive-and-mysql/
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic