miracle occurs here|

Archive for December, 2008

Confluence Install – Datasource “Access denied for user” Error

Sunday, December 21st, 2008

I was trying to install a Confluence instance in my hosting account. I had gone through the install and setup successfully locally on my Mac. But the setup on the host was failing:

I kept receiving some sort of access error:
Access denied for user 'foo_user'@'dz64.dailyrazor.com' (using password: YES)

I tried establishing the database connection manually through DbVisualizer, which worked fine:

jdbc:mysql://domain.com:3306/db_name?autoReconnect=true

I looked more closely at the error and realized that something was appending the username with the individual server my account was being hosted on (i.e., dz64.dailyrazor.com). I had a hard time figuring out who was at fault – Confluence, Tomcat, DBCP, or MySQL.

The source of the problem appeared to be my Tomcat resource definition:

Googling around didn’t provide me any answers. I tried replacing “domain.com” in the “url” attribute with “dz64.dailyrazor.com”, but this didn’t achieve anything. In the end, I figured out that specifying “localhost” was the answer:

url="jdbc:mysql://localhost:3306/db_name?autoReconnect=true"

This is what I was doing on my Mac, but it took me a while to figure out that the same had to be done on my host.

If you enjoyed this post, you might want to follow this blog!

Confluence Upgrade – Duplicate Entry Error

Sunday, December 21st, 2008

I’ve been running a Confluence installation (using a personal license) for a couple years. Recently, I’ve been experiencing some issues with it, and figured that it might be time to upgrade (from version 2.2.5, which is from July 2006, I’m guessing). At the time of this writing, the current version (and the version to which I wanted to upgrade), is version 2.10.

My upgrade process consisted of performing a clean install of version 2.10 and importing a backup of the content from my version 2.2.5 installation. According to the documentation, this is an expected and supported operation for these version numbers. But, it did not work. The error I received (in the atlassian-confluence.log file):

I did some Googling, but wasn’t able to find a solution. I looked closer at the information contained in the log and guessed that there were really only two records at issue, and that they both were drafts:

instance of 'class com.atlassian.confluence.pages.Draft' with id 13.

instance of 'class com.atlassian.confluence.pages.Draft' with id 14.

I opened the Confluence entities.xml file (located in the back-up zip) and searched for “draft”. As hoped, I found two elements:

I deleted these two elements from the XML file, re-zipped the back-up, re-executed the import, and it worked perfectly.

If you enjoyed this post, you might want to follow this blog!

Differences Between Hibernate and JPA

Tuesday, December 9th, 2008

Fans of the Hibernate object-relational mapping (ORM) framework will realize that the Java Persistence API (JPA) is basically a standardization of that framework. And, if you’re like me, you really haven’t given much thought to JPA, because, gee, isn’t it just a watered-down Hibernate? Maybe, maybe not. (I’m not going to get into that here and now.)

It can be useful, though (even if only politically or procedurally), to code to JPA instead of the Hibernate API. If you find yourself in that situation, you may find this compare/contrast between the two API’s to be useful:

Hibernate JPA
SessionFactory EntityManagerFactory
Session EntityManager
sessionFactory.getCurrentSession().[method]() entityManager.[method]()
saveOrUpdate() persist()
Query.setInteger/String/Entity() Query.setParameter()
list() getResultList()
uniqueResult() getSingleResult()
uniqueResult() returns null getSingleResult() throws NoResultException
CriteriaQueries – yes CriteriaQueries – no

Additionally, there are a couple Hibernate-specific JPA-isms to keep in mind:

  • If the underlying JPA implementation is Hibernate, either/both annotations or/and mapping files may be used – at the same time. In such a situation, I believe the mapping files act as an override for the annotations.
  • The best of both worlds (in my mind) is to base the code (at an interface- or API-level) on JPA and its EntityManager, but to have the implementation interact with the Hibernate Session, which can be obtained by calling getDelegate() on the EntityManager.

If you enjoyed this post, you might want to follow this blog!