Hibernate : ManyToOne getId eagerly and avoid saving ManyToOne object


Today I found good trick to achieve this.

i.e. directly use ManyToOne to getId
and to get the full object lazily loaded
and avoid saving the same object


It is from blog post
http://stackoverflow.com/questions/1900788/hibernate-manytoone-save-org-hibernate-transientobjectexception


ManyToOne(fetch=FetchType.EAGER)
@**JoinColumn**(name = "DEPARTMENT_ID", referencedColumnName = "DEPARTMENT_ID", **insertable=false, updatable=false**)
private Department department;

@Column(name = "department_id")
private Long departmentId;

Make sure to annotate all fields with @Column annotation with the name, otherwise hibernate will throw exception

Dumping a java object's properties


From this stackoverflow question and answer,

I got the answer which is very useful to dump properties of a java object.

Mostly useful for debugging.

org.apache.commons.lang3.builder.ReflectionToStringBuilder.toString(object);

Running Google Chrome as root


Open Terminal and run below commands 
1)xhost +
2) sudo -i -u google-chrome

When done

3) xhost - 

Taking thread/heap dump of running server/process


2. After extracting the jdk , run the following command to take the dump 
/bin/jmap -dump:format=b,file=./heapdump PID

3. To take only thread dump
./bin/jstack -l PID 
./bin/jstack -l PID > /tmp/thread_dump.txt


Following linux commands can be used for digging 

awk '/State: B/ { print }' < /tmp/thread_dump.txt  | sort | uniq -c
awk '/State: WAITING/ { getline; print }' < /tmp/thread_dump.txt | sort | uniq -c

Ways to debug apache tomcat


1) Start tomcat with this command 
~/apache-tomcat-7.0.47/bin/catalina.sh jpda start -Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n

OR 

2) export CATALINA_OPTS='-Djava.awt.headless=true -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000'


And attache IDE to 8000 remote process.

Remote Management By JConsole


Getting trouble while connecting jconsole with remote process

Here is how to achieve it

As described here http://docs.oracle.com/javase/tutorial/jmx/remote/jconsole.html is not enough

sometimes one more java system property needs to be set which is
java.rmi.server.hostname=

for example in case of Apache Tomcat
follow this
1) Export JAVA_OPTS
export JAVA_OPTS='-Dcom.sun.management.jmxremote.port=9999 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=192.168.1.13'

2) Restart application

3) now from the jconsole connect to 192.168.1.13:9999 by providing credentials

Note : Firewall should be configured to allow these connections (or simply for the time stop iptables services (in linux))

Ref : http://stackoverflow.com/questions/1263991/connecting-remote-tomcat-jmx-instance-using-jconsole

Mondrian [MDX] accessing Member PROPERTIES

I was trying to access the properties of Dimension in my MDX schema, but the way it is mentioned in the Mondrian documentation was not working in 3.5.8 version. Then we got in trouble and wasted lot of time in figuring out that, how to access properties in Mondrian.

Here is how it worked for me

SELECT
{[Measures].[Total Sales Count]} ON COLUMNS,
[Store].[Store Id].MEMBERS DIMENSION PROPERTIES [Store].[Store Id].[Name] ON ROWS
FROM [Sales]

Where [Name] is the property of the level [Store Id]

Hope if you are searching for this, it may help you.