Labels

Tuesday, December 31, 2013

Javascript Event Keys

Ways to get the keycode (or charcode) of keys that were pressed.

onkeypress:
  • which (i.e. e.which)
onkeyup/onkeydown:
  •  keyCode (i.e. e.keyCode)

<script>
     function testkeydown(e)
     {
          alert("Key pressed was " + e.keyCode);
     }

     function testkeyup(e)
     {
          testkeydown(e);
     }

     function testkeypress(str, e)
     {
          alert("Key pressed was " + e.which + " and the additional parameter was " + str + ".");
     }
</script>

<input type="text" onkeydown="testkeydown(event);" />
<input type="text" onkeyup="testkeyup(event);" />
<input type="text" onkeypress="testkeypress("additional parameter", event);" />

Wednesday, October 30, 2013

uses a non-entity as target entity in the relationship

This error or similar appears in the Glassfish server log even though everything appears correct in the project.  Double-check the persistence.xml to be sure it is correct.  If it is, the problem is likely being caused by a cached persistence.xml.  If you are using an IDE such as Netbeans be sure to Clean & Build before deploying.

Caused by: java.lang.IllegalStateException: Attempting to execute an operation on a closed EntityManagerFactory.

According to this site (site), this is caused by a Glassfish bug and redeploying will fix this.  The following steps solved the issue:

  1. Undeploy the project
  2. Restart the Glassfish server
  3. Clean and build project
  4. Deploy project to Glassfish server

These steps work using the following configurations:
  • Netbeans 7.4 and Glassfish 4.0
  • Netbeans 8.0 and Glassfish 4.0

Friday, October 25, 2013

SSH issues in Ubuntu

Problem 1:

When using ssh to connect to a remote server from an Ubuntu based machine, there is a long delay before the password prompt is displayed.

Solution:

On the local machine, edit the ~/.ssh/config file (or create it if it does not exist) and add the line:

GSSAPIAuthentication=no




Problem 2:

When connected to a remote server with ssh, if idle too long, connection will be ended with this message:

Write failed:  Broken pipe


Solution:

On the local machine, edit the ~/.ssh/config file (or create it if it does not exist) and add the line:

ServerAliveInterval 120

Monday, October 14, 2013

Runtime ClassNotFoundExceptions may result

Problem:

When using Eclipse Kepler to create Java EE projects, I was getting the following warnings:

Classpath entry <jar library here> will not be exported or published.  Runtime ClassNotFoundExceptions may result.

Solution:

The warning is telling me that the jar file (in my case it was a log4j library) will not be included in the archive that is deployed to application server.  This warning is just a reminder that unless you put the jar file in the classpath of the application server you will receive ClassNotFoundExceptions when trying to run the projects.  A very handy reminder but somewhat irritating since I don't like the little yellow triangle with exclamation point that appears on the project because of the warning.  The can be fixed by adding the jar file for the required library to the Deployment Assembley (Project Properties -> Deployment Assembly -> Add... -> Java Build Path Entries -> <jar library>).  The downside to this is that the jar will be included in the EAR or WAR that is generated thus making is much larger.

Wednesday, October 2, 2013

Null or zero primary key encountered in unit of work clone

Null or zero primary key encountered in unit of work clone [Object@3622086c], primary key [0]. Set descriptors IdValidation or the "eclipselink.id-validation" property.

Ran into this at runtime when running a EJB on Glassfish using JPA Entities.  The problem turned out to be a missing annotation on one of the properties in one of the JPA Entities (@GeneratedValue).

The value in question was the primary key for the table and was auto-generated.

Full corrected code:
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;

Wednesday, August 14, 2013

Setup Git Repository

I created a Git server to host our companies code repositories.  It is an ubuntu server with ssh enabled and git installed.  Here are steps I use to create a new repository:
1. Create directory to host new repository
$ sudo mkdir /testrepo1
2. Change group of repository directory to group used by developers that will be using this repository
$ sudo chgrp -R git /testrepo1
3. Change default permissions on directory so that all new files will be crated with the new group
$ sudo chmod g+rws /testrepo1
$ sudo git --base /testrepo1
4. Initialize empty Git repository
$ cd /testrepo1
$ git --bare init --shared=group

Thursday, May 16, 2013

InnoDB: Unable to lock ./ibdata1, error: 11

This is an error I see in the logs from time to time.  I am running a MySQL server with an openvz container on a Proxmox server.  From time to time the Proxmox server will crash which causes all the VMs it is running to stop unexpectedly (in defense of Proxmox this has only happened on a development box that is installed on a workstation).  When I attempt to access the MySQL server through the MySQL Workbench I get an error like "Can't connect to the MySQL server on <server name> (111)":
I also receive an error when trying to access the database from the command line:
# mysql -u root -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

In the logs I found:
InnoDB: Unable to lock ./ibdata1, error: 11
InnoDB: Check that you do not already have another mysqld process
InnoDB: using the same InnoDB data or log files.
InnoDB: Error in opening ./ibdata1

I was able to fix the problem by restoring the permissions on several files (modified from this post):
# cd /var/lib/mysql
# mkdir bak
# mv ibdata1 bak/.
# mv ib_logfile* bak/.
# cp -a bak/ibdata1 ibdata1
# cp -a bak/ib_logfile* .
# service mysql restart

Wednesday, April 10, 2013

Ubuntu 12.04 Joomla 3

I recently setup an Ubuntu server with Joomla 3.  I used the instructions found here with a few modifications.  I did not want the joomla site to be under the /joomla subdirectory so I skipped the first three commands under step 2.  The steps I used are as follows:

  1. sudo apt-get install lamp-server^
    mysql -u root -p
    CREATE DATABASE dbjoomla;
    CREATE USER joomlauser;
    (Change <password> to the password of your choice)
    SET PASSWORD FOR joomlauser = PASSWORD("<password>");
    GRANT ALL PRIVILEGES ON dbjoomla.* TO joomlauser@localhost IDENTIFIED BY '<password>';
    FLUSH PRIVILEGES;
    exit
    wget http://joomlacode.org/gf/download/frsrelease/17965/78414/Joomla_3.0.3-Stable-Full_Package.zip
    sudo unzip -q Joomla_3.0.1-Stable-Full_Package.zip -d /var/www
    You will want to remove the index.html that exists in /var/www by default
    sudo chown -R www-data.www-data /var/www
    Install joomla 3.0 from a browser by typing http://[hostname]

Wednesday, February 13, 2013

Locale error

August 8, 2012

I had been getting an error on some Ubuntu servers when using apt:
locale: Cannot set LC_CTYPE to default locale: No such file or directory       
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory             

After some googling I found a solution:

localedef -v -c -i en_US -f UTF-8 en_US.UTF-8                                            

EDIT:  This occurs when I setup Ubuntu 12.04 servers using an openvz image that I downloaded (I don't remember from where).