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

Monday, December 24, 2012

Run JBoss, Tomcat/Tomee in debug mode

 

The needed params are:

-Xdebug -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n

For jboss as 7 in bin/standalone.bat (or sh) add those additional params to line 53

set JAVA_OPTS=-Dprogram.name=%PROGNAME% %JAVA_OPTS%

the line will look like this:

set JAVA_OPTS=-Dprogram.name=%PROGNAME% %JAVA_OPTS% -Xdebug -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n

For tomcat/tomee

in catalina.bat (.sh) at this as the first line in file:

set JAVA_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n

To debug the code in Eclipse:

  1. Run -> Debug Configurations… -> Remote Java Application -> Right click –> New
  2. Then on Connect tab, set these Connection Properties: host = localhost, port=8787
  3. Then select your Project and in Source tab add extra projects or libraries.
  4. Press Apply button
  5. Press Debug button
  6. You are connected!!! – the server must be started
  7. Add a Breakpoint in your code
  8. Trigger your application to reach a Breakpoint

To debug the code in Netbeans:

  1. Go in menu: Debug->AttachDebuger…
  2. set port to 8787
  3. press ok (make sure that the server is up and running) – repeat the process every time when you need debugging

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;

Updating GlasFish v3 with latest EclipseLInk and JSF Mojara

 

Download newer version of EclipseLink binaries from http://www.eclipse.org/eclipselink/downloads/. Choose OSGI bundles from the available downloads.

Download javax.faces-2.1.14.jar from http://javaserverfaces.java.net/download.html (the latest at the moment, not use 2.2.x version because this will be part of the new jee7 spec and may not work with glassfish 3.1)

Replace following files under $GLASSFISH_HOME/glassfish/modules with corresponding jars you downloaded above:

  • org.eclipse.persistence.antlr.jar
  • org.eclipse.persistence.jpa.jar
  • org.eclipse.persistence.asm.jar
  • org.eclipse.persistence.jpa.modelgen.jar
  • org.eclipse.persistence.core.jar
  • org.eclipse.persistence.oracle.jar
  • javax.persistence.jar
  • javax.faces.jar

    Restart GlassFish

  • Note: This will solve problems with create-tables in hsqldb – the defauld eclipse link from glassfish 3 generate some SQLs which are not executed for tables creation.

    Thursday, December 6, 2012

    Switching to the dark side … of development in Netbeans 7.2

    Netbeans_dark

     

    • download JTatoo.jar and put it in [netbeans install folder]/platform/lib
    • edit [netbeans install dirf]\etc\netbeans.conf find the line starting with netbeans_default_options="-J-client -J-Xss2m -J-Xms32m -J-XX:PermSize=32m
      1. append this text to the line:  -J-Dswing.aatext=true -J-Dawt.useSystemAAFontSettings=on -J-Dawt.useSystemAAFontSettings=lcd --laf com.jtattoo.plaf.hifi.HiFiLookAndFeel --fontsize 11

      (you can also use –laf Nimbus for Nibus build in look & feel)

      1. the section should look similar to this:
    netbeans_default_options="-J-client -J-Xss2m -J-Xms32m -J-XX:PermSize=32m -J-Dapple.laf.useScreenMenuBar=true -J-Dapple.awt.graphics.UseQuartz=true -J-Dsun.java2d.noddraw=true -J-Dsun.zip.disableMemoryMapping=true -J-Dswing.aatext=true -J-Dawt.useSystemAAFontSettings=on -J-Dawt.useSystemAAFontSettings=lcd --laf com.jtattoo.plaf.hifi.HiFiLookAndFeel --fontsize 11"

  • download and install Monaco font (not the latest 5.1 version for windows is not working well with line spacing, you can also use Anonymous fonts as alternative)
  • restart netbeans
  • go to in menu Tools->Options->Fonts&Colors and select Sunburst, Netbeans_Twilight or Monster theme and customize the theme as you like
  • Develop with pleasure Smile