Sunday, December 30, 2012

Test JPQL (or HQL) using SQuirrel SQL 3.4.0

image
  • In Netbeans 7.2 create a new Java Application Project
  • Add a connection to your database in Services tab –>Databases
  • Copy all JPA entity classes in your project (in correct package)
  • In newly created java app project right click on “Source Packages” –>New –>(Other)->Persistence Unit
  • In New Persistence Unit dialog:
    • Persistence LIbrary = Hibernate (JPA 1.0)  (I tried with hibernate 4.1.9 and jpa 2 but is not working)
    • Database connection = chose your db connection
    • Table generation strategy = none
  • Edit your persistence.xml
    • In design tab –> Include Entity Classes –> add all of them
    • In the source tab –> add the hibernate.dialect property e.g.
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/>
  • Right click on your project and in Build –>Packaging->select Copy Dependency Libs (this will create a lib folder with all you need in the dist folder)
  • Build your project
  • Right click on your project and in Build –>Packaging->deselect Copy Dependency Libs (this will create your jar without references to other jars – perfect for squirrelsql)
  • Build your project again
  • In Squirrel File –> Global Preferences –> Hibernate: create a new configuration
  • With “Add classpath entity” button:
    • add jars for your jdbc driver
    • add all jars in from your_java_app/dist/lib
    • add your exported java app jar from dist folder
  • select call … persistence-unit and complete persistence-unit name
  • Select Run Hibernatate in SQuirreL’s Java VM
  • Hit Apply Changes to this configuration and OK
image
After you’re connected to your db in the Hibernate tab is all the magic Open-mouthed smile

13 comments:

  1. This is the key point: "(I tried with hibernate 4.1.9 and jpa 2 but is not working)".
    SquirrelSql works correctly only with hibernate 3.x.

    ReplyDelete
  2. You can find a patch for squirrel to work with hibernate here: http://pastebin.com/yinBqy4m

    ReplyDelete
  3. How to use the patch?? any idea!!

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. Your good knowledge and kindness in playing with all the pieces were very useful. I don’t know what I would have done if I had not encountered such a step like this.
    AWS Training in Bangalore
    AWS training in sholinganallur
    AWS training in Tambaram
    AWS training in Velachery

    ReplyDelete
  6. This comment has been removed by the author.

    ReplyDelete
  7. Simply wanted to inform you that you have people like me who appreciate your work. Definitely a great post.
    Hats off to you! The information that you have provided is very helpful.
    aws training in chennai | aws training in annanagar | aws training in omr | aws training in porur | aws training in tambaram | aws training in velachery

    ReplyDelete
  8. Thank You and that i have a neat present: Where To Remodel House whole home renovation cost

    ReplyDelete