views:

133

answers:

1

Hi, I'm trying to decide whether to switch from having Hibernate sprinkled all over to using JPA2.0 and thus be provider portable.
1.Does JPA2.0 support custom user-types?
2.I'm on the verge of implementing Terracotta as a second-level cache to Hibernate with its clustering abilities mainly in mind. I would imagine, but I don't actually know, that JPA2.0 also defines a spec for second-level cache providers. If I'm right, does Terracotta implement it? (If someone could point me to a getting started with Terracotta and JPA I'd appreciate it).

Thanks in advance,
Ittai

+2  A: 

Does JPA2.0 support custom user-types?

Nothing beyond @Embedded and @Embeddable (already in JPA 1.0). Depending on the complexity of your needs, they might do the job).

I would imagine, but I don't actually know, that JPA2.0 also defines a spec for second-level cache providers.

JPA 2.0 defines methods on the EntityManager to access the second level cache that is maintained by the persistence provider, a Cacheable annotation, some other things. But the way to plug a cache on your JPA provider is provider specific. So no, JPA doesn't define a spec for L2 cache providers. And if you want to use Terracota as the L2 cache provider with Hibernate as JPA 2.0 implementation, look at the Hibernate integration documentation.

References

  • JPA 2.0 specification
    • Section 3.7 "Caching"
    • Section 7.10 "Cache Interface"
    • Section 11.1.7 "Cacheable Annotation"
Pascal Thivent
@Pascal, thanks for your reply. Seeing as I'm still trying to understand how and where I can use JPA2.0 and where I must use Hibernate itself I'd appreciate it if you can give a bit more detail on the relationship between JPA->JPAImpl(mine being Hibernate)->L2CacheProvider. Is the L2CacheProvider "invisible" to the JPA? meaning I configure Terracotta to use Hibernate as if I would have just used Hibernate and then in my app use the JPA annotations and interfaces where I can? thanks
Ittai
@ittai Yes, you configure *Hibernate* (the JPA Provider) to use Terracotta as L2 cache provider and then you use the JPA `Cacheable` annotation and query hints to cache your entities and queries. The L2 cache provider itself is not visible to JPA. You interact with the JPA provider and the JPA provider interacts with a L2 cache.
Pascal Thivent
@Pascal, thank you.
Ittai