Showing posts with label JEE_Dev. Show all posts
Showing posts with label JEE_Dev. Show all posts

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

Tuesday, December 11, 2012

Global JNDI Names standardized in JEE6

The Enviromental Naming Context (ENC) is a JNDI context that can be accessed via java:comp/env.

This Context is used to create portable JNDI names for EJBs. Names in the ENC are created with entries in a deployment descriptor. The JEE6 adds support for sandard JNDI names of EJBs withour requiring usage of the ENC:

java:global[/<app-name>]/<module-name>/<bean-name>

java:app[/<module-name>]/<bean-name>

java:module/<bean-name>

app-name is same as ear without extension, module-name is ejb jar or war name without extension

also CDI can target specific JNDI name


@EJB(mappedName=”java:global/ejbmodule/FooBean”)
FooRemote foo;