Posts

Showing posts from 2013

HIBERNATE JPA:How to deploy a WAR created by Netbeans on a Standalone TOMCAT

Image
HIBERNATE JPA: How to deploy a WAR created by Netbeans on a Standalone TOMCAT Years ago TOMCAT was a two-tailed cat, used as the logo for the mighty F-14A Tomcat plane, when I became mature O_o, Tomcat lost a tail, landed on the ground and now is a well know Servlet Container... I think it lost part of its magic during the landing, and a tail too. Tomcat: Hardware embedded version. During compilation of a web project using hibernate with Netbeans, it copies persistence.xml to a new folder named META-INF under the WEB-INF/classes folder. So if you are having trouble launching your application once it is deployed on TOMCAT and getting the error: javax.persistence.PersistenceException: No Persistence provider for EntityManager named ... Most probably Hibernate is not finding persistence.xml in WEB-INF/classes/META-INF/persistence.xml when deployed under TOMCAT. Copy it by hand from 'conf' folder to WEB-INF/classes/META-INF. And salute me!

Assuring there is only an instance of an application. "There Only Can be One!" (JAVA Code)

Image
Assuring there is only an instance of an application.  " There can be only one " (JAVA Code Version) (HighLander Film 1986). Note: It is important for you life to listen to this film's OST song: "Who Wants to Live Forever" (Queen 1986). But I am almost sure you know that song already, so keep on reading my article. This is year 2013 and, as long as I know, Operating Systems do not give the facility for preventing an application to be launched twice. So it has to be done programmatically. Common ways of getting it done are: Creating a file and blocking it so that the new process cannot get access to it. A funny use of a deadlock. Opening a port and closing the new instance as soon as it checks that the port is already under use by another previous launched instance. Both have advantages and disadvantages. This entry gives code for the second solution. Mind the firewall! Now shut up and gimme tha codez: package com.ramon.talav

Generating XML from JavaScript

Image
Generating XML from JavaScript: When to use these functions: In some Javascript-based environments there are no XML libraries available, sometimes external libraries are not allowed or you just want fine control over your xml generation process. They are easy to implement and easy to use too. About the image: well, I just liked it. // Create an XML element. function createXMLElement(parent, name, data) {     var node = new Object();     node["parent"] = parent;     node["name"] = name;     node["data"] = data;     node["children"] = new Array();     node["attributes"] = new Array();     return node; } //Add child function addXMLChild(parent, child) {     child["parent"] = parent;     parent["children"].push(child); } // XML library: add a child function addXMLChildAtPos(parent, child,pos) {     child["parent"] = parent;     parent["children"].spl

Getting Access To Private Fields in JAVA using Reflection:

Image
Getting Access To Private Fields in JAVA using Reflection: Private fields are... ehem, private, that means that they cannot (should not) be known, inspected or changed... now that inversion of control is common around us, what if a class is keeping a field private to protect it from 'abuse' but I want to access it just to abuse it softly (??? I should check my semantics when talking about code). What if I want Inversion of Control and I do not have an IOC Container? Ok, lets do it the hard (O_O ???) way. For example, a Business Object is keeping a Data Object in private for it not to be directly used out of the Business Tier, but a Manager class wants to be made responsible for Business Tier's persistence. So the manager takes the Business Object, takes its DataObject, and persists it... but, it cannot! the Data Object was set to... private. Ok, here is how to change that field access permissions during runtime: Obtain a private field and play with it: