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