Software Development, Linux, and Windows

Notes on Software Development, Linux, and Windows

Posts about Language

JPA: How to use a base class for your entities

In order for to extend a base class from you entities, you must use the annotation @MappedSuperclass on the base class: @MappedSuperclass public abstract class AbstractBaseEntity Then in your entity class extend the class as you usually would: @Entity public class MyConcreteEntity extends AbstractBaseEntity

Posted in JPA | Comments Off

How to resolve LazyInitializationException with SpringMVC using JPA with Hibernate

Follow the below steps if you see the org.hibernate.LazyInitializationException being thrown while trying to render your page. Add a filter to your web.xml file: <filter> <filter-name>SpringOpenEntityManagerInViewFilter</filter-name> <filter-class></filter-class> </filter> <filter-mapping> <filter-name>SpringOpenEntityManagerInViewFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>

Posted in Hibernate, JPA, SpringMVC | Comments Off

Handling Multiple Exceptions in one catch block

Overview Java 1.7 added support to handle more than one Exception in a single catch block. Example: This is a nice feature, and here is an example that demonstrates this and how to extract the name of the Exception class being thrown for logging: package com.petersarazin.exception; import; import org.junit.Test; public class ExceptionHandling_Test { @Test [...]

Posted in Java | Comments Off

Installing Oracle JDK on Ubuntu

You must run these 3 commands: sudo apt-get install python-software-properties sudo add-apt-repository ppa:webupd8team/java sudo apt-get update To install Java 7, run this command: sudo apt-get install oracle-java7-installer To install Java 8, run this command: sudo apt-get install oracle-java8-installer To change the default Java installation, run this command: sudo update-alternatives –config java

Posted in Java, Language, Linux, Ubuntu | Comments Off

Change default version of java on CentOS

Perform these steps to change the default version of java: Login in or switch user to root: su – Type this command: alternatives –config java If you do not see the version you want listed then you must use the alternatives –install command, so your version of java can be “installed”. List the versions of [...]

Posted in CentOS, Java | Comments Off

Compare BigDecimal to Zero in Java

You really need to use compareTo() instead of equals() for this: equals() yields inconsistent results with decimal values: new BigDecimal( 0 ).equals( BigDecimal.ZERO ); // true new BigDecimal( 0.00 ).equals( BigDecimal.ZERO ); // false As you can see, eqauls() gives unexpected results. compareTo() does this right thing: new BigDecimal( 0 ).compareTo( BigDecimal.ZERO ) == 0; [...]

Posted in Java | Comments Off

Allow Apache/PHP on CentOS to connect to a remote database

The issue for me was that by defualt SELinux was preventing this access from happening. Perform the following steps on the machine running Apache. Login or swith user to root: su – Enter the following command: setsebool -P httpd_can_network_connect_db=1 NOTE: When I ran this command on my system which is a 2.8 GHz Pentium 4 [...]

Posted in Apache, CentOS, Linux, MySQL, PHP | Comments Off

Install Apache and PHP on CentOS

Follow these steps to install Apache and PHP on CentOS. Install Apache and PHP components with PHP support for MySQL: yum install httpd php php-common php-mysql Start Apache: service httpd start Configure Apache to start at system startup: chkconfig httpd on

Posted in Apache, CentOS, Linux, MySQL, PHP | Comments Off