Wednesday, March 19, 2014

Packt Publishing reaches 2000 titles milestone

Extra! Extra!

Hello, I want to share with you all the following press release from Packt Publishing which is celebrating its title number 2000! Packt is giving its reader a chance to dive into their comprehensive catalog and Buy One, Get One Free across their entire range of eBooks during 18th-Mar-2014 and will continue until 26th-Mar-2014. The following conditions apply:

  • Unlimited purchases during the offer period
  • Offer is automatically applied at checkout

For more information about Packt, the kind of books they publish and to qualify for the discounts, visit: Remember, the campaign ends on 26th-Mar-2014.

see ya!

Thursday, February 27, 2014

CLOJUG - February 2014: Adopt a JSR + WildFly 8

Hello all! This is a small update about what we did at the Cali (CLO) Java User Group - CLOJUG during February 2014.

We run our regular meeting on 15-FEB-2014 at Universidad del Valle. We had the opportunity to learn about the JCP, JSRs, the Adopt a JSR program, etc. Why they are important to Java developers and to the Java community. We also had the intervention of other JUG leaders from soujava (Brazil), GuadalajaraJUG (Mexico) and LJC (London) who shared with us their experiences with the program and gave us advice about how to start and keep moving Java forward. Special thanks to +Bruno Souza +Guillermo Munoz +Jim Gough
The hangout can be found at:

During the same meeting we celebrated our first birthday, ate cake and had fun sharing stories from the last year. Here are some pictures from the event:

We also had another meeting where +Arun Gupta introduced us to the new WildFly 8 which is Red Hat's Java EE 7 compliant open source application server. The main features are:

  • Lightweight : It starts in about 2 secs, light disk/memory footprint, loads containers on demand
  • Centralized Administration and Management: Starts in standalone or managed domain mode, provides multiple options to manage using CLI, REST, Admin Console, Ruby, PHP, Java, and others
  • Feature rich: Java EE 7 compliant, polyglot, role based access control, highly optimized new web server

As always, Arun's presentation was very informative and attendees were glad to have another JavaEE7 compliant application server and are eager to download and start playing/using WildFly 8. The event can be found at the following link, but it was not created as a "Hangout on Air" so there is no replay, only links to the slides:

Here are some pictures of this event:

Stay tuned for our events and if you live in Cali-Colombia, come to our meetings and become a member of our great community!

see ya

Monday, February 24, 2014

GlassFish Extension for JDeveloper 12c Go live!

Hi all, I just wanted to share with you that the Glassfish Extension for JDeveloper 12c is available now. As noted in my previous post, this extension is based on the source code provided by Shay Shmeltzer. You can learn more about his GlassFish Extension for JDeveloper 11g in the following post:

The source code for the extension can be found at the Oracle JDeveloper 3rd Party Extensions project at, so you can help to enhance the extension and further develop it.
While the extension is deployed and hosted on Oracle's servers, so you can download it via JDeveloper's menu: help->check for updates, you can follow these steps in order to do a manual installation:
  1. Download the extension here: Glassfish Extension for JDeveloper 12c

  2. Open JDeveloper and go to: Help->check for updates

  3. Select Install From Local File and browse for the file that you downloaded in step 1 (a .zip file)

  4. JDeveloper will show you a summary before installation, press the Finish button and will restart itself to complete the installation

  5. Once the installation is complete, yo can find a new section in the toolbar and inside the Run menu with the Glassfish Extension buttons

  6. Before you can use the extension, you should configure the paths to your Glassfish server installation, you do that in: Tools->Preferences->Glassfish Preferences

That's it, now you can control your GlassFish server from inside JDeveloper 12c.

see ya!

Tuesday, February 11, 2014

ADF Entity Track Change History Attributes and MySQL Database

Hello all.
Oracle ADF can be used with other databases vendors rather than Oracle, however some out-of-the-box functionalities may not work properly and you'll find yourself looking for workarounds to make them work. Today, we are going to see how we can use the Track Change History properties (CreatedBy, CreatedOn, ModifiedBy, ModifiedOn) of a Business Components Entity when using MySQL.

What you need
JDeveloper 12c
MySQL 5.6.4 or higher

Before we start, you need to know the following:
  • In MySQL 5.5 and higher, InnoDB is the default storage engine. The benefits of this are: ACID Transactions, Referential Integrity, and Crash Recovery.
  • Previous versions of MySQL do NOT store fractional seconds (milliseconds) into columns of any temporal data type. More info on this, here.
  • From version 5.6.4, MySQL stores fractional seconds (milliseconds) into columns of any temporal data type. More info in this, here.
  • You can define how many milliseconds to store from 0 to 6.

To start, execute the following script in MySQL database:

CREATE  TABLE `Player` (
  `name` VARCHAR(150) NOT NULL ,
  `age` INT NOT NULL ,
  `created_by` VARCHAR(50) NULL ,
  `created_on` DATETIME(3) NULL ,
  `modified_by` VARCHAR(50) NULL ,
  `modified_on` DATETIME(3) NULL ,
  PRIMARY KEY (`idPlayer`) )

You can see that we are creating a table with an autoincrement primary key. We have seen before, a workaround about having autoincrement columns in MySQL to work with ADF, but we are not using it in this post. 

Also, notice that we are defining that the DATETIME columns will have 3 milliseconds. Once you have executed the script, go to File->New->Business Components From Tables and follow the wizard to create an Entity of the table Player, a default ViewObject and an Application Module. Remember to configure the SQL Platform as SQL92 and Data Type Map as Java:

JDeveloper will map the DATETIME columns as Timestamp fields in the Entity, which is fine since we want to store milliseconds:

Configure each history attribute as one of: Created On, Created By, Modified On, Modified By and notice that when you configure an attribute as a Track Change History Attribute, JDeveloper will select default values for other properties:

Once all the Track Change History Attributes are set, you can run the Application Module in order to test the functionality. However, you may find the following error when trying to commit to the database:

Current time is not available from SQL statement "select sysdate from dual".: Unknown column 'sysdate' in 'field list'...

This is happening because the Application Module tries to get the current date from the database using Oracle's statement: "select sysdate from dual", which is not valid in MySQL. In order to change that, go to your Application Module and edit the LOCAL configuration:

A pop up opens, go to the Properties section and look for a property called: jbo.sql92.DbTimeQuery

We need to change the value of that property to something that works on MySQL. There are many DATE related functions in MySQL, here we are going to use NOW(). So, change the value of the jbo.sql92.DbTimeQuery to:

select NOW() from dual

Click OK button and save your changes.

CAUTION: At the time of this writing, JDeveloper is using mysql-connector-java-commercial-5.1.22-bin.jar as the default MySQL library. However, when I tried the above configuration using that library, it didn't work because no milliseconds information were being stored into the database. The solution is to update the MySQL driver. You can find the official MySQL connector drivers at:

If you don't update the MySQL driver, you may experience the following error when trying to modify a row (this is the so called Phantom Error):

The following picture was taken when using the default MySQL library, notice that there is no milliseconds information saved into the database:

And here is the picture after using the latest MySQL connector, notice the milliseconds information:

When you have downloaded the new version of the driver, you have to remove the default MySQL library from your project and add the new jar. Go to your project Properties:

Run the Application Module again, create or modify rows and this time it should work.

That's it, with the above configuration you are now ready to use the Track Change History functionality when using MySQL database.

see ya!


MySQL 5.6 Reference Manual :: 12.7. Date and Time Functions. MySQL [online].
Available on Internet:
[accessed on February 09 2014].

MySQL 5.6 Reference Manual :: 11.3.6. Fractional Seconds in Time Values. MySQL [online].
Available on Internet:
[accessed on February 09 2013].

MySQL 5.6 Reference Manual :: InnoDB as the Default MySQL Storage Engine. MySQL [online].
Available on Internet:
[accessed on February 09 2013].

Wednesday, February 5, 2014

Whizlabs Discount

Wondering where to study for your next certification? Whizlabs provides end to end certification preparation solutions for Oracle Java, Cisco and Project Management Certification. I have used their exam simulators before and I can tell they are good for preparing yourself for the certification exam.

They sponsor my Java User Group ( and have allowed me to extend the promo code that we get as members of the JUG to everyone that reads my blog. So, you can get 7.5% off on your next purchase by using the following code at check out:

Visit for a complete list of their Certification Preparation Solutions.

see ya!

Thursday, January 23, 2014

GlassFish Extension for JDeveloper 12c

Hi all, I just wanted to share with you that I'm working on a GlassFish extension that works with the new JDeveloper 12c. This extension will be based on the source code provided by Shay Shmeltzer. You ca learn more about his GlassFish Extension for JDeveloper 11g in the following post:

The 12c extension is in its early testing phase, I'll do tests on OpenSuse, Ubuntu 13.10, Windows Vista and Mac OSX (Mavericks). Once the test phase is complete I will release the extension so you can download it using JDeveloper's menu: help->check for updates. Also, the source code will be uploaded to the Oracle JDeveloper 3rd Party Extensions project at

see ya!

Thursday, December 19, 2013

USD $5 Bonanza - Pack Publishing

Just a quick post with a great offer from Packt Publishing:

From December 19th 2013 to January 3rd 2014, you can get any eBook or Video from Packt for just USD $5!
More info:

This is a great offer to start the new year (2014) with some books to read. Go get yours!

see ya

Monday, November 25, 2013

CLOJUG - November 2013: Last meeting of the year

We run our regular JUG meeting on 23-NOV-2013 at a local pizzeria in Cali, Colombia. We decided to meet outside the classrooms in order to have a more easygoing and networking oriented meeting. It was a success, members of the CLOJUG started to talk each other about their roles, projects and, of course, Java. This was our last meeting in 2013, we hope to see you all again in JAN-2014.

Thanks to all our sponsors: Univalle, Unicesi, Oracle, PluralSight, Whizlabs, Codesa, O'reilly and Pack Publishing for their support during 2013.

Here are some pictures of this event:

Stay tuned for our events and if you live in Cali-Colombia, come to our meetings and become a member of our great community!

see ya!

Saturday, November 23, 2013

Using MySQL autoincrement PK column in ADF Entity PK attribute

Hello all. Continuing with the ADF + MySQL workaround series, today we are going to see what we need to do in order to use MySQL PK autoincrement columns with our ADF Entities PK attributes. If we were using Oracle database, we would use the oracle.jbo.domain.DBSequence along with a sequence and a trigger in order to do that out-of-the-box.

For simplicity, we are going to modify the Java file associated to the Entity, but as a good practice, you should have your own implementation of the oracle.jbo.server.EntityImpl class and configure JDeveloper so it uses your own implementation for every new Entity in your application. Check this post for more information about that.

This is not a step by step tutorial about how to create ADF BC from tables, we'll assume that you already have your Business Components definitions.

What you need
JDeveloper 12c
MySQL 5.5+

This is the database table that we are going to use in this post:

CREATE  TABLE `test`.`Actor` (
  `name` VARCHAR(100) NOT NULL ,
  PRIMARY KEY (`id_actor`) );

Once you have created your entities from tables, JDeveloper will map your Entity attributes against the table columns and will set some properties based on the type of column. For example, for our PK column (id_actor), JDeveloper will set the attribute as a mandatory Integer and always updatable. We need to change that because we want our PK to be updatable while new (while creating a new instance) and not mandatory (because we are reading the autoincrement value after posting to the database):

You may have several tables in your database and hence several Entities in your ADF application but not all tables may have autoincrement PK columns, so we need a way to mark or identify when the Entity's PK attribute is coming from an autoincrement column in the database. We are going to do that using Property Set, which allows us to define a collection of key/values properties and then we can associate those properties to an attribute and access them during runtime:
  1. In JDeveloper select: File-->New-->From Gallery...

  2. In the ADF Business Components select Property Set

  3. Set the name and package of the new property set:

  4. Once created, we can define the set of key/value properties and if the properties are going to be shown to the users, we can even define them in translatable mode. This is not our case, so we are going to define a non-translatable property:

  5. Set the property name as AI (for AutoIncrement) and its value as true (because attributes who use this Property Set are coming from an autoincrement column):

  6. Now that we have our Property Set ready, we can use it in our Entity PK attribute:

In order to retrieve the autoincrement value for our PK attribute, we need to override the default implementation of our Entity class (remember we do this for simplicity, but you can do better as described at the beginning of this post). We can do that by implementing a Java class for our Entity and then by overriding the EntityImpl.doDML(int, TransactionEvent) method, which is where changes are posted to database:
  1. Go to the Java section of the Entity and click on the pencil icon:

  2. In the pop up window, select Generate Entity Object Class:... and click OK:

  3. The Java section of the Entity class now shows the Java file, click on the link to the Java File name:

  4. JDeveloper will open a new window with the Java code. Copy and paste the following methods:

        protected void doDML(int i, TransactionEvent transactionEvent) {
            //got to call first to super, so the record is posted 
            //and we can then ask for the last insert id
            super.doDML(i, transactionEvent);
            //after the record is inserted, we can ask for the last insert id
            if (i == DML_INSERT) {
        * Determines if the Entity PK is marked as an autoincrement col
        * and executes a MySQL function to retrieve the last insert id
        private void populateAutoincrementAtt() {
            EntityDefImpl entdef = this.getEntityDef();
            AttributeDef pk = null;
            //look for primary key with Autoincrement property set
            for (AttributeDef att : entdef.getAttributeDefs()) {
                if (att.isPrimaryKey() && (att.getProperty("AI") != null 
                    && new Boolean(att.getProperty("AI").toString()))) {
                    pk = att;
            if (pk != null) {
                try (PreparedStatement stmt = 
                         .createPreparedStatement("SELECT last_insert_id()", 1)) {
                    try (ResultSet rs = stmt.getResultSet()) {
                        if ( {
                            setAttribute(pk.getName(), rs.getInt(1));
                } catch (SQLException e) {

    The above code is posting changes to database and then asks whether we were inserting values. If that's the case, we need to retrieve the autoincrement value and set it in our PK attribute. Refer to the MySQL function LAST_INSERT_ID() for more information about retrieving autoincrement values.

OK, let's try out our solution. First, run your application module:

Once the Oracle ADF Model Tester tool appears, select (double click) the ActorView1 View Object, on the left panel, and click on the green plus sign icon, on the right panel,  in order to add a new Actor:

Enter a name for the Actor and press the "Save changes to the database" button (little database with the checklist icon on the toolbar):

You will notice that the autoincrement value is now set to the idActor attribute!

No need to be worried about concurrent inserts, MySQL documentation states that it is OK (check this documentation):

Using LAST_INSERT_ID() and AUTO_INCREMENT columns simultaneously from multiple clients is perfectly valid. Each client will receive the last inserted ID for the last statement that client executed.

Download the ADF project used in this post.

See ya!


Vesterli E., Sten (2013). Developing Web Applications with Oracle ADF Essentials. United Kingdom: Packt Publishing Ltd.

MySQL 5.5 Reference Manual :: 12.14 Information Functions. MySQL [online].
Available on Internet:
[accessed on November 14 2013].

MySQL 5.5 Reference Manual :: How to Get the Unique ID for the Last Inserted Row. MySQL [online].
Available on Internet:
[accessed on November 17 2013].

Friday, November 22, 2013

ADF Good Practice: Provide your own base classes

Hi all. I just wanted to share a really good practice when developing Oracle ADF applications. I have used this on several projects and it has always saved me time when I need to apply some new behavior to all my business components. Credits to Sten Vesterli for this best practice that I found on his book Oracle ADF Enterprise Application Development—Made Simple

When you are working with Business Components (Entities, ViewObjects, Application Modules, etc...) you are extending Oracle ADF base classes, the most common base classes are:
  • oracle.jbo.server.EntityImpl is used for your entities implementations
  • oracle.jbo.server.ViewObjectImpl and oracle.jbo.server.ViewRowImpl are used for your view object implementations
  • oracle.jbo.server.ApplicationModuleImpl is used for your application module implementations
So, what happens if after a few months of coding you need some new behavior in all your entities? If you are thinking in implementing a java class for every entity... you are making a bad decision for the future of your project.
What you need is to provide your own base classes and make sure that all your entities, view objects and application modules use your extended framework. And when changes arises, you can modify your base classes and then changes are applied to all your business components.

For example, when we create a new entity, by default we are getting:

But, when we are providing your own base classes, we will get something like this:

And all we need to do to apply a general change is to modify yourpackage.YourOwnBaseEnityImpl

At first, we will end up with empty classes, but don't worry, you are saving for the future ;-)

In order to create our own base classes framework, in JDeveloper we go to File-->New-->Application... Then, select Applications on the left panel and Custom Application on the right panel:

Select a name for the application and define an application package prefix (optional):

Then select a name for the project and make sure you select ADF Buiness Components as a project feature:

Check the source path and output directory and if everything is OK, press the Finish button:

Once the project has been created, make sure that the BC4J Runtime library has been added to the project properties:

Select the Libraries and Classpath option on the left pane. If there is no BC4J Runtime library already set in your project go to the Add Library option and look for it:

Now we can create our own base classes that extends from the Oracle ADF base classes. Go to: File-->New-->From Gallery...Then look for the General option on the left and select Java class on the right

Set the name for the base class and make sure to extend from Oracle ADF base classes, in the following example we are extending from oracle.jbo.server.EntityImpl:

Following are the most common base classes extended:

//change package according to your company 
package com.javanme.commons.framework;
 * Base class for Applications Modules
public class EntityImpl extends oracle.jbo.server.EntityImpl {

//change package according to your company 
package com.javanme.commons.framework;
 * Base class for ViewObjects
public class ViewObjectImpl extends oracle.jbo.server.ViewObjectImpl {

//change package according to your company 
package com.javanme.commons.framework;
 * Base class for View Rows
public class ViewRowImpl extends oracle.jbo.server.ViewRowImpl {

//change package according to your company 
package com.javanme.commons.framework;
 * Base class for Applications Modules
public class ApplicationModuleImpl extends oracle.jbo.server.ApplicationModuleImpl {

Once we have created all the base classes, we will need to create an ADF library in order to be able to use them in other projects. Right click on the project and select Project Properties... Then select the Deployment option on the left and click on the New button on the right. A dialog pops up, select ADF Library JAR File and set a name for this deployment:

Click OK twice since no more configurations are needed:

Then right click on your project and select Deploy-->YourADFLibDeployment from the pop up menu:

If this is the first time you are deploying the library, a new window pops up, just click on Finish. Then, go to the default deploy location of the project which is on {APP_DIR}/{PROJECT_DIR}/deploy, where APP_DIR and PROJECT_DIR are the paths defined when the application and the project were created:

Copy the library to a directory where you save all your libraries and then in JDeveloper go to Window menu and select Resources:

A new window, on the right,  appears on JDeveloper. Click on the folder icon and select IDE Connections then File System. We are going to define a new resource that points to the directory where we save all the libraries so we can easily add libraries to our projects:

Set a name for the resource and find the directory where the ADF libraries are saved, the one we created steps above. Finally, click on Test Connection in order to validate that everything is OK:

Once we have created the new resource, we can expand the tree below IDE Connections and look for the library that we want to import to the selected project. Right click and select Add to Project:

A confirm dialog pops up, just press Add Library:

You have to repeat the same steps for every library that you want to import into your project. Whenever we want the project to load changes on the imported libraries, right click on the project and select Refresh ADF ibrary Dependencies in {ProjectName}:

Last step is really important because we are telling JDeveloper that it needs to use our base classes instead of the Oracle ADF base classes. We can do this in two ways: the first one is at project level, so we need to configure every project where we want to use our base classes. The second approach is at JDeveloper level so every single project will make use of our base classes. It's up to you to decide which approach to take, but at the end we need to configure the following window:

Notice that we are using our own base classes which are at com.javanme.commons.framework package. If you want this at project level, then right click on the project and select Project Properties from the pop up menu. If you want this at JDeveloper level go to Tools-->Preferences. Whatever the approach is, look for the ADF Business Components/Base Classes in the pop up window.

This was a long post, hopefully it will save you time in your future ADF projects.

See ya!


Vesterli E., Sten (2011). Oracle ADF Enterprise Application Development—Made Simple. United Kingdom: Packt Publishing Ltd.