As long as I know myself to be a coward I shall be unhappy.
L. Frank Baum (1856-1919)
As long as I know myself to be a coward I shall be unhappy.
L. Frank Baum (1856-1919)
At times when debugging ORMs lke hibernate we may need to know what queries are actually hitting the db. MySql gives an easy way to do this. Add the below in the my.cnf file
at times when u import the db it may erase ur userid and pwd. When the java tries to connect to the db it throws exception that this ip is not allowed to connect to the db; in such a case use the below fix. it removes the necessity to have userid and pwd to loginto the mysql
be careful that u dont do this on production dbs
This is generally the case when u try to import a database from a dump. The fix is to increase the max_allowed_packet size follow the below steps
This should do.
suppose we want to search for a string “abc” in a file then we use
grep “abc” /path/to/file/file.txt
but what if u want to search for either “abc” or “xyz”? u need to grep twice. instead use egrep
egrep “abc|xyz” /path/to/file/file.txt
the best use of egrep comes in when we tail a file and want to search for a set of strings in the tail eg:
tail –f /path/to/file/file.txt | egrep “abc|xyz”
getSession() –> the java doc says it will create a new session/ continue with the existing one based on getHibernateTemplate().setAllowCreate(…); set to true/ false.
How ever, i found the things to be diffarent. I had a 2 DAOs one executing: getHibernateTemplate().find(..); the other using getSession().createCriteria(..); They are wrapped by the same transaction interceptor. What i found is when the 2nd DAO runs the hibernate throws illegal state exception.
Why?? The getSession() always tries to crate a new session, if the setAllowCreate is set to false, then it throws illegal argument exception. Why this devaiation??? as always only god knows it.
To get the current session in 2nd DAO, i found the fix: getHibernateTemplate().getSessionFactory().getCurrentSession(); and things went off very fine.
Recently i had to do a query as:
select * from t_table where (t.a=’a’ and t.b=’b’) or (t.a=’aa’ and t.b=’bb’). One way to get over this is via HQL query… which i hate.. i wanted to do it using criterias… finally Conjunction and disjunctions came for resque. Below is the code.
Session session = getSession();
try {
Criteria crit = session.createCriteria(Table.class);
Disjunction conMerOrs = Restrictions.disjunction();
for (AB ab: ABList) {
Conjunction ands = new Conjunction();
ands.add(Restrictions.eq("a", ab.a()));
ands.add(Restrictions.eq("b", ab.b));
ors.add(ands);
}
crit = crit.add(ors);
return crit.list();
} finally {
session.close();
}
let me know if it helped