Tuesday, November 11, 2014

Some tips when install new Ubuntu 14.04 64bit

Back to Gnome Flashback

apt-get install gnome-session-flashback

Enable Logout / Shutdown / Restart button:

gsettings set com.canonical.indicator.session suppress-logout-restart-shutdown true

Install ibus-unikey
Using unity or default ubuntu interface, after install ibus-unikey success, you can change to gnome flashback

sudo apt-get install ibus-unikey
ibus restart

Install dock
sudo apt-get install plank

Edit plank config at

nano ~/.config/plank/dock1/settings

Change maximize control to right
gsettings set org.gnome.desktop.wm.preferences button-layout ':minimize,maximize,close'

Install Java
Using normal user
tar xvf jdk-7u51-linux-x64.tar.gz
mv jdk1.7.0_51 jdk1.7.0
sudo -s
mkdir /usr/lib/jvm
mv jdk1.7.0 /usr/lib/jvm/
update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.7.0/bin/java" 1
update-alternatives --set java /usr/lib/jvm/jdk1.7.0/bin/java
nano /etc/profile

Add content below to /etc/profile
JAVA_HOME=/usr/lib/jvm/jdk1.7.0
JRE_HOME=$JAVA_HOME/jre
PATH=$JAVA_HOME/bin:$PATH
CLASSPATH=.:$JAVA_HOME/lib
MANPATH=$MANPATH:$JAVA_HOME/man
export JAVA_HOME JRE_HOME PATH CLASSPATH MANPATH

Fix Skype theme
sudo apt-get install gtk2-engines-murrine:i386 gtk2-engines-pixbuf:i386


Some problem with JavaHL (install sublipse for eclipse)
Go to Eclipse > Preferences > Team > SVN Under "SVN interface", choose client as "SVNKit(Pure Java) SVNKit v..xx". That's all.

Saturday, October 18, 2014

EXP 13: disable cache feature of EclipseLink

Problem
Sometimes, I query data from database using EclipseLink. The query as below:
EntityManager em;
em.createQuery("SELECT o FROM Tbexample as o", Tbexample.class).getResultList();
I get nothing but when I access to database, some record exists in table Tbexample.

Cause
By default, EclipseLink enable caching feature. This feature help increase performance but sometimes it make difficult to control real data in database in very small time (nanosecond). So to ensure the query result show real data on table of database, you have to disable caching feature.

Solution
On persistence.xml, add the line:
<shared-cache-mode>NONE</shared-cache-mode>

On query, add the hint
EntityManager em;
em.createQuery("SELECT o FROM Tbexample as o", Tbexample.class).setHint("javax.persistence.cache.storeMode", "REFRESH").getResultList();
That's all for disable caching feature on querying.

EXP 12: add static route on linux network

Problem
Connect both wired and wifi network.

Wired for LAN and wifi for internet.

Connected to LAN but can not connect internet.

Cause
On console, type

route

Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default 9.9.9.1 0.0.0.0 UG 0 0 0 eth0
9.9.9.0 * 255.255.255.0 U 1 0 0 eth0
10.0.0.0 * 255.0.0.0 U 2 0 0 wlan0
link-local * 255.255.0.0 U 1000 0 0 eth0

default gateway using eth0, ip 9.9.9.1, so you can not connect internet with this.

Solution
Change default gateway from eth0 to wlan0 using static route

sudo route add -net default gw 10.128.128.128 netmask 0.0.0.0 dev wlan0 metric 0

sudo route del -net default gw 9.9.9.1 netmask 0.0.0.0 dev eth0 metric 0

Saturday, October 11, 2014

EXP 11: replace String in postgresql

Problem
Replace String "EJB" by "Bean" in postgresql

Solution
Using function regexp_replace(input_string, original_expression, new_expresstion)

Sample
UPDATE tbfunction
SET functionresource = regexp_replace(functionresource, 'EJB', 'Bean')

Wednesday, October 8, 2014

EXP 10: Cannot import javax.enterprise.context.SessionScoped

Problem
Cannot import javax.enterprise.context.SessionScoped
Webserver: Glassfish 4.1
IDE: Eclipse Luna

Cause
default Eclipse Luna dont add cdi-api.jar package into build path. So, you cannot import javax.enterprise.context.SessionScoped  class.

Solution
Add cdi-api.jar to build path. You can find it in <glassfins-install-dir>/glassfish/modules

EXP 9: org.jboss.weld.exceptions.DefinitionException: WELD-000075: Normal scoped managed bean implementation class has a public field: [EnhancedAnnotatedFieldImpl]

Problem
When using @Named annotation, console output error:
org.jboss.weld.exceptions.DefinitionException: WELD-000075: Normal scoped managed bean implementation class has a public field:  [EnhancedAnnotatedFieldImpl]

Cause
The field in @Named injection  is must declared not public visibility

Solution
Change public access to private or protected

Monday, September 8, 2014

EXP 8: Software Life Cycle Processes from IEEE Std 12208-2008

This image is extracted from IEEE Std 12208-2008  document. Hope it help you recognize about process standards and give you more perspectives about your project.



You can download full this ISO document at here

Friday, September 5, 2014

EXP 7: java.io.NotSerializableException: com.sun.faces.context.FacesContextImpl

Problem
Get exception java.io.NotSerializableException: com.sun.faces.context.FacesContextImpl when deploy application in cluster

Cause
FacesContext implement should be use as FacesContext.getCurretntInstance() for all case. Dont use any variable e.g:

ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
ec.redirect(url);

Solution
Check all FacesContext implementations, using FacesContext.getCurrentInstance() instead.

Wrong way:
ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
ec.redirect(url);

Right way:
FacesContext.getCurrentInstance().getExternalContext().redirect(url);

Wednesday, September 3, 2014

EXP 6: java.lang.IllegalArgumentException: setAttribute: Non-serializable attribute with name

Prolem
Server log show error:
java.lang.IllegalArgumentException: setAttribute: Non-serializable attribute with name sessionBean

Cause
The instance "sessionBean" of SessionBean class is non--serializable when enable distribute feature on web.xml

Solution
Implement Serializable to SessionBean class  or super of SessionBean class

EXP 5: Connect remote EJBs on clustered environment

Problem
Cannot connect remote EJBs on clustered enviroment (Glassfish 4 app server)

Cause
in clustered environment, Glassfish use different JNDI compare single server.

Solution
Correct JNDI as described as below:

java:globbal/<earname>/<ejbprojectname>/

You can find exactly JNDI on server.log file of Glassfish Server when it startup.

Example

java:global/gbear/gbeejb/

If EJB which you need to connect named TestEJB, the full JNDI is:

java:global/gbear/gbeejb/TestEJB

Quotes from server.log

[2014-09-03T12:48:21.608+0700] [glassfish 4.1] [INFO] [AS-EJB-00054] [javax.enterprise.ejb.container] [tid: _ThreadID=14 _ThreadName=RunLevelControllerThread-1409723271247] [timeMillis: 1409723301608] [levelValue: 800] [[
  Portable JNDI names for EJB TestEJB: [java:global/gbear/gbeejb/TestEJB, java:global/gbear/gbeejb/TestEJB!com.gbsofts.gbe.module.system.service.TestService]]]

[2014-09-03T12:48:21.608+0700] [glassfish 4.1] [INFO] [AS-EJB-00055] [javax.enterprise.ejb.container] [tid: _ThreadID=14 _ThreadName=RunLevelControllerThread-1409723271247] [timeMillis: 1409723301608] [levelValue: 800] [[
  Glassfish-specific (Non-portable) JNDI names for EJB TestEJB: [ejb/TestEJB#com.gbsofts.gbe.module.system.service.TestService, ejb/TestEJB]]]

Tuesday, August 26, 2014

EXP 4: Recovery data on ext4 partition

Problem
Delete all on ext4 partition, cannot recover them using default commands of linux.

Cause
Some programs can delete your data over control.

Solution
Use PhotoRec to recover deleted data. I tried and recover about 95% text files (total over 200 files) when deleted on accident. It can use for NTFS or others supported partition type;

Reference
http://www.cgsecurity.org/wiki/PhotoRec
http://www.cgsecurity.org/wiki/PhotoRec_Step_By_Step
http://www.cgsecurity.org/wiki/After_Using_PhotoRec

Download PhotoRec (included in ubuntu-rescue live cd)
http://ubuntu-rescue-remix.org

EXP 3: Cannot update some packages from Debian 7.5

Problem
Cannot update some official packages when fresh install Debian 7.5

Cause
Maybe default repositories are not enough.

Solution
nano /etc/apt/sources.list

Add following repositories into sources.list file:

deb http://ftp.debian.org/debian/ wheezy main
deb-src http://ftp.debian.org/debian/ wheezy main
deb http://security.debian.org/ wheezy/updates main
deb-src http://security.debian.org/ wheezy/updates main
deb http://ftp.debian.org/debian/ wheezy-updates main
deb-src http://ftp.debian.org/debian/ wheezy-updates main



Save file, and update repos again.

apt-get update

EXP 2: org.postgresql.util.PSQLException: ERROR: prepared transaction with identifier

Problem
org.postgresql.util.PSQLException: ERROR: prepared transaction with identifier

Cause
some configs of postgresql incorrect, especially for XA transaction

Solution
in postresql.conf file, set 2 parameter same value, max_prepared_transaction and max_connections

You can consider increase share_buffers larger (ex: 512MB)

Example
max_connections = 100
max_prepared_transaction = 100 

EXP 1: Local transaction already has 1 non-XA Resource: cannot add more resources

Problem
Local transaction already has 1 non-XA Resource: cannot add more resources

Cause
JavaEE cannot handle transactions which have 2 more resource and one of them is non-XA resource

Solution
Config all resource into XAResource

Example
Config XAResource for Postgresql on Glassfish, using JDBC Connection Pool

Resource Type: javax.sql.XADataSource
Datasource Classname: org.postgresql.xa.PGXADataSource