I have some problems getting the hibernate second level cache to work for caching domain objects. According to the ehcache documentation it shouldn't be too complicated to add caching to my existing working application.
I have the following setup (only relevant snippets are outlined):
#Entity
#Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE
public void Entity {
// ...
}
ehcache-entity.xml
<cache name="com.company.Entity" eternal="false"
maxElementsInMemory="10000" overflowToDisk="true" diskPersistent="false"
timeToIdleSeconds="0" timeToLiveSeconds="300"
memoryStoreEvictionPolicy="LRU" />
ApplicationContext.xml
<bean class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="ds" />
<property name="annotatedClasses">
<list>
<value>com.company.Entity</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.generate_statistics">true</prop>
<prop key="hibernate.cache.use_second_level_cache">true</prop>
<prop key="net.sf.ehcache.configurationResourceName">/ehcache-entity.xml</prop>
<prop key="hibernate.cache.region.factory_class">net.sf.ehcache.hibernate.SingletonEhCacheRegionFactory</prop>
....
</property>
</bean>
Maven dependencies
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
<version>3.4.0.GA</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-hibernate3</artifactId>
<version>2.0.8</version>
<exclusions>
<exclusion>
<artifactId>hibernate</artifactId>
<groupId>org.hibernate</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache-core</artifactId>
<version>2.3.2</version>
</dependency>
A test class is used which enables cache statistics:
Cache cache = cacheManager.getCache("com.company.Entity");
cache.setStatisticsAccuracy(Statistics.STATISTICS_ACCURACY_GUARANTEED);
cache.setStatisticsEnabled(true);
// store, read etc ...
cache.getStatistics().getMemoryStoreObjectCount(); // returns 0
No operation seems to trigger any cache changes. What am I missing? Currently I'm using HibernateTemplate in the DAO, perhaps that has some impact.
[EDIT]
The only ehcache log output when set to DEBUG is:
SettingsFactory: Cache region factory : net.sf.ehcache.hibernate.SingletonEhCacheRegionFactory
Do you need to manually tell Hibernate to use the EHCache provider? I've never really been sure if this is required, but Hibernate does support a number of cache providers so I suspect that it might be necessary to explicitly tell Hibernate which one you want. Try adding this property to ApplicationContext.xml:
<prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
There were several causes that I've identified:
Correct maven dependencies:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>3.6.3.Final</version>
</dependency>
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache-core</artifactId>
<version>2.4.1</version>
</dependency>
Added the #Cacheable annotation from javax.persistence to my entities.
Read logging from hibernate instead of ehcache.
getSessionFactory().getStatistics().logSummary();
Not all hibernate operations seems to affect the cache. This I need to read up on further.
By looking at your config, it all seems fine afaict. Only thing worth noticing, is that when using the HibernateTemplate, you have to explicitly setCacheQueries(true) if you plan on using the query cache... Which I wouldn't recommend, except if you really need it: http://static.springsource.org/spring/docs/2.5.x/api/org/springframework/orm/hibernate3/HibernateTemplate.html#setCacheQueries(boolean)
Did you try the Hibernate statistics instead of the Ehcache ones ? Do you get cache misses there ? (reason I ask is to be sure you do use the same CacheManager as Hibernate does)...
you can reference following configure
<prop key="hibernate.cache.use_query_cache">true</prop>
In hibernate.cfg.xml add:
<hibernate-configuration>
<session-factory>
...
<property name="cache.use_second_level_cache">true</property>
<property name="cache.use_query_cache">true</property>
<property name="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</property>
Related
I am trying to configure C3P0 connection pool for my hibernate application.
I am using below dependencies.
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.5.6.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-c3p0</artifactId>
<version>5.5.6.Final</version>
</dependency>
I added below configs in my hibernate.cft.xml
<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.max_size">20</property>
<property name="hibernate.c3p0.acquire_increment">5</property>
<property name="hibernate.c3p0.timeout">1800</property>
But I get the warning below:
WARN: HHH000022: c3p0 properties were encountered, but the c3p0 provider class was not found on the classpath; these properties are going to be ignored
If I explicitly specify the provider class like given below, it works.
<property name="hibernate.connection.provider_class">org.hibernate.c3p0.internal.C3P0ConnectionProvider</property>
But the documentation of the above class says it should be picked by default.
A connection provider that uses a C3P0 connection pool. Hibernate will
use this by default if the hibernate.c3p0.* properties are set.
Why is this not class picked up by default? Is it correct to explicitly specify org.hibernate.c3p0.internal.C3P0ConnectionProvider? It looks like org.hibernate.connection.C3P0ConnectionProvider is the class which is picked up by default, and most of the references found in the web are regarding it, but it is not available in the above mentioned maven dependencies.
Remove hibernate. from the property name, it should be:
<property name="connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
I'm new to apache camel. I was trying to understand the use of Integrating Spring framework with Apache Camel. I am not comparing Spring vs Apache camel here. I am trying to understand if Dependency Injection is the only use of integrating Spring with camel for a Java Project. Since Camel can take care of a lot of things like routing and also JDBC config that even spring framework can do. In my project we are using Google juice for DI instead of spring. I know that there are other modules like spring security, AOP that could be utilized from spring. But don't you think we can achieve the same using other libraries. So what am i missing here? Is my understanding correct? What are the other uses of integrating spring with apache camel when we can achieve the same DI using google guice and camel.
if your project camel has spring, you can use all features of spring framework, for example if you need Spring JDBC you can declare that dependency and use it in camel. I will give you an example:
In your pom.xml
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<scope>provided</scope>
</dependency>
In your camel-context.xml
<!-- Datasource -->
<bean class="org.springframework.jdbc.datasource.SimpleDriverDataSource"
id="dataSource">
<property name="driverClass" value="com.microsoft.sqlserver.jdbc.SQLServerDriver" />
<property name="url"
value="${ds.urlString}://${ds.server}:${ds.port};databaseName=${ds.bd}" />
<property name="username" value="${ds.user}" />
<property name="password" value="${ds.password}" />
</bean>
<!-- processors -->
<bean
class="com.mycomapny.Processor"
id="idProcessor" />
As you can see in the example you are injecting dependency, and you can use it in a dao class.
regards
I have an application with Hibernate 5, and added JPA 2.1 to perform bulk Updates with CriteriaBuilder.createCriteriaUpdate().
But I need to assign CriteriaBuilder from EntityManager.getCriteriaBuilder(), and I can't get the EntityManager.
I don't have a persistence.xml file, and I thought Hibernate would provide an EntityManager for me.
I tried the following annotations in the DAO class:
#Autowired
EntityManager entityManager
and
#PersistenceContext
EntityManager entityManager;
Both fail to inject the dependency.
I also tried to instace an EntityManagerFactory, but it failed as I don't have a persistence.xml file. All the entities are annotated like this:
#Entity
#Table(name = "My_Entity")
public class MyEntity extends BaseEntity {
private static final long serialVersionUID = -8442071276091708080L;
#Column(name = "VALUE", nullable = false)
private BigDecimal value;
...
}
Here is part of my pom.xml:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.1.3.Final</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.1.3.Final</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<version>1.0.0.Final</version>
</dependency>
applicationContext.xml
<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/>
<bean id="transactionManager"
class="org.springframework.orm.hibernate5.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
<property name="nestedTransactionAllowed" value="true"/>
</bean>
Hibernate instances the SessionFactory, is there a way to get the EM from it?
If you use spring it would be much easier to use the spring boot starters modules. For JPA it would be "spring-boot-starter-data-jpa" you can find the definition of the maven dependency here.
Additionally, could you add more information about your configuration? You say you don't use a persistence.xml so what do you use to set your datasources?
I'm inserting, updating and deleting many detached objects with hibernate and a c3p0 connectionpool.
The problem is that hibernate does not batch the statements but instead does a
select ##session.tx_read_only
between every session.persist/insert/update/delete(object). Profiling the sql-connection it looks like this:
select ##session.tx_read_only
insert...
select ##session.tx_read_only
insert...
select ##session.tx_read_only
insert...
select ##session.tx_read_only
insert...
select ##session.tx_read_only
insert...
select ##session.tx_read_only
with select ##session.tx_rad_only always returning "0" (of course). It doesn't matter whether i use a stateless or stateful session. The resulting performance is not acceptable and far of any expectation.
My Hibernate Konfiguration:
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://127.0.0.1:4040/xy?zeroDateTimeBehavior=convertToNull</property>
<property name="hibernate.connection.username">xy</property>
<property name="hibernate.connection.password">xy</property>
<property name="hibernate.connection.autocommit">false</property>
<property name="hibernate.show_sql">false</property>
<property name="hibernate.format_sql">false</property>
<property name="hibernate.use_sql_comments">false</property>
<property name="hibernate.query.factory_class">org.hibernate.hql.internal.classic.ClassicQueryTranslatorFactory</property>
<property name="hibernate.connection.provider_class">org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider</property>
<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.max_size">20</property>
<property name="hibernate.c3p0.timeout">300</property>
<property name="hibernate.c3p0.max_statements">250</property>
<property name="hibernate.c3p0.idle_test_period">3000</property>
<property name="hibernate.jdbc.batch_size">250</property>
<property name="hibernate.connection.release_mode">auto</property>
<property name="hibernate.order_inserts">true</property>
<property name="hibernate.order_updates">true</property>
<property name="hibernate.cache.use_second_level_cache">false</property>
<property name="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</property>
<property name="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</property>
<property name="hibernate.cache.use_query_cache">true</property>
<property name="net.sf.ehcache.configurationResourceName">hibernate_ehcache.xml</property>
I'm using:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-c3p0</artifactId>
<version>4.3.5.Final</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.31</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.3.4.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>ejb3-persistence</artifactId>
<version>1.0.2.GA</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-ehcache</artifactId>
<version>4.3.4.Final</version>
</dependency>
I have nearly no expirience with hibernate and it is a good guess i made a huge mistake so please feel free to suggest anything.
I switched to hibernate because the ORM functionality and am coming from plain jdbc prepared statements with a blazing fast performance. The MYSQL-Server is in a good configuration-state.
edit1:
i'm aware of:
Unnecessary queries in Hibernate - MySql
I've got no transactional annotations in my entities nor a defined isolationlevel anywhere
edit2:
i changed my connectionpool to bonecp - and the problem continues. Seems to be clearly a hibernate copnfiguration issue.
edit3:
tried many different things and found maybe a trace of a hint:
If I manualy session.flush() every 5 inserts (=size of batch e.g.)[tried the batch-example AGAIN from hibernate], the select ##session.tx_read_only query appears double - every 5 queries. I therefore assume that select ##session.tx_read_only is related to flushing. are there any ways to prevent hibernate from flushing every single insert/update?
I tried so far: session.setFlushMode(FlushMode.COMMIT/NEVER/etc) without any change in the behaviour. Maybe I misconfigured anything... what does hibernate trigger to flush every insert? Unique constraint at the tables? hibernate validation framework? complex object-graphs? difficult concurrency? maybe a locking issue (Hibernate isn't sure if someone else locked the tables and doesn't batch but checks every single insert if the table is read only?)?
i found nothing related to this extrem (I assume) flushing bahaviour.
We solved this issue by just setting useLocalSessionState=true in the connection string.
The below link explain the details of ReadOnly related changes happened from Mysql5.6 and the java connector 5.1.23.
http://dev.mysql.com/doc/relnotes/connector-j/en/news-5-1-23.html
You need to include all those CRUD operations in a single Transaction so all statements are executed in the same DB connection.
You can also enable the following Hibernate configurations:
<property name="hibernate.order_inserts" value="true"/>
<property name="hibernate.order_updates" value="true"/>
<property name="hibernate.jdbc.batch_size" value="50"/>
Those queries don't mean you don't have batching. It's a MySQL thing
Some drivers require special batching reordering directives:
<property name="hibernate.connection.url">jdbc:mysql://host:port/db?rewriteBatchedStatements=true</property
I found the flaw in my configuration.
I had to change the mysql-connectionsstring from
<property name="hibernate.connection.url">jdbc:mysql://127.0.0.1:4040/xy?zeroDateTimeBehavior=convertToNull</property>
to
<property name="hibernate.connection.url">jdbc:mysql://127.0.0.1:4040/xy?rewriteBatchedStatements=true</property>
this solved my problems.
i am coming back because i still have problem using JodaTime. After the previous comments, i modified my pom and the #Type annotation is fixed. Here is my new pom :
<properties>
<org.springframework.version>3.0.3.RELEASE</org.springframework.version>
<hibernate.version>3.6.0.Beta1</hibernate.version>
</properties>
<dependencies>
...
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>${hibernate.version}</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<!-- Spring Dependencies -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>3.0.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>20030825.184428</version>
</dependency>
<dependency>
<groupId>commons-pool</groupId>
<artifactId>commons-pool</artifactId>
<version>20030825.183949</version>
</dependency>
<dependency>
<groupId>commons-validator</groupId>
<artifactId>commons-validator</artifactId>
<version>1.3.1</version>
<classifier>sources</classifier>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.5</version>
</dependency>
<!-- Joda Time dependencies -->
<dependency>
<artifactId>joda-time</artifactId>
<groupId>joda-time</groupId>
<version>1.6</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time-jsptags</artifactId>
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time-hibernate</artifactId>
<version>1.2</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
</dependencies>
I am actually developping a personnal project where i use Spring and Hibernate. I also use JodaTime to persist the date fields. When i am doing unit testing with Junit4, i caught this exception :
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [spring/spring-dao.xml]: Invocation of init method failed; nested exception is java.lang.IncompatibleClassChangeError: Implementing class
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1412)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
....
fr.cc2i.intervention.dao.test.WebInterventionTest.oneTimedSetUp(WebInterventionTest.java:33)
.....
Caused by: java.lang.IncompatibleClassChangeError: Implementing class
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2389)
at java.lang.Class.getConstructor0(Class.java:2699)
at java.lang.Class.getDeclaredConstructor(Class.java:1985)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:104)
at
.....
According to that website : http://www.mail-archive.com/joda-interest#lists.sourceforge.net/msg00609.html, jodatime might cause the error.
Can someone explain me what is : java.lang.incompatibleChangeError : Implementing Class ?
and how to solve that problem?
My spring configuration :
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource"> <ref local="dataSource" /></property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.current_session_context_class">thread</prop>
<prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</prop>
<!-- Pour les requetes SQL -->
<prop key="hibernate.query.substitutions">true 1, false 0, yes 'Y', no 'N'</prop>
<!-- manipuler avec attention -->
<prop key="hibernate.hbm2ddl.auto">create</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
<property name="annotatedClasses">
<list>
<value>fr.cc2i.intervention.dao.beans.Client</value>
<value>fr.cc2i.intervention.dao.beans.Intervention</value>
<value>fr.cc2i.intervention.dao.beans.Technicien</value>
<value>fr.cc2i.intervention.dao.beans.Contrat</value>
</list>
</property>
</bean>
My entity class :
package fr.cc2i.intervention.dao.beans;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import org.hibernate.annotations.Type;
import org.joda.time.Period;
/**
* Classe définissant un contrat
* My code is written in French ;)
* #author lindows
*
*/
#Entity
#Table(name="T_Contrat")
public class Contrat {
private long id;
private String reference;
private Period heures_totales;
private Period heures_restantes;
public Contrat(){}
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
public long getId() {
return id;
}
private void setId(long id) {
this.id = id;
}
public String getReference() {
return reference;
}
public void setReference(String reference) {
this.reference = reference;
}
#Column
#Type(type="org.joda.time.contrib.hibernate.PersistantPeriod")
public Period getHeures_totales() {
return heures_totales;
}
public void setHeures_totales(Period heuresTotales) {
heures_totales = heuresTotales;
}
#Column
#Type(type="org.joda.time.contrib.hibernate.PersistantPeriod")
public Period getHeures_restantes() {
return heures_restantes;
}
public void setHeures_restantes(Period heuresRestantes) {
heures_restantes = heuresRestantes;
}
public String toString(){
return this.reference + " - \n Heures totales :" + this.heures_totales.toString() +
" Heures Restantes : " + this.heures_restantes.toString();
}
}
Thanks for your help
As I wrote in a comment, your pom.xml is messy and this is somehow the root cause of the issue. Here comes the full explanation.
According to the announcement of the Simultaneous Hibernate 3.5.4 and 3.6.0.Beta1 Releases quoted below, the hibernate-annotations module has been merged into core in Hibernate 3.6.x (made possible since Hibernate 3.6.x is dropping JDK 1.4 support):
3.6.0.Beta1
3.6 introduces some new features as well as incorporating most of the
fixes from 3.5. Changes of particular
interest include
Dropping support for JDK 1.4
merging some modules into core; specifically hibernate-jmx and
hibernate-annotations
repackaging of classes in hibernate-testing
HHH-2277 : fixes a long known limitation in key-many-to-one support.
HHH-5138, HHH-5182, HHH-5262 : collectively address a
number of improvements to the
"Hibernate type system". See the newly
separated and expanded chapter on
Types in the reference manual for
details.
HHH-5268 : java.util.UUID support
For more details about 3.6.0.Beta1,
including the full list of changes,
see the release page.
And indeed, the latest versions of hibernate-annotations-3.6-SNAPSHOT.jar are actually empty jars (because of the merge) that were temporarily built until the total removal of the maven module itself. But because you're not using hibernate-core-3.6-SNAPSHOT.jar, you just don't have the #Type annotation at all.
Now, here is a summary of my recommendations/remarks:
Use Maven transitive dependency resolution mechanism, do not declare all dependencies but only the "top level" one i.e. hibernate-entitymanager if you want to use JPA.
Starting with version 3.5, Hibernate Core, Annotations, EntityManager are released together, their versions are in sync.
If you want to use Hibernate 3.6.x (Beta2 is there now), the #Type is in hibernate-core (that's not really important if you use transitive dependencies).
I don't recommend to rely on SNAPSHOT unless you know exactly what you're doing.
So your pom.xml should declare something like this for Hibernate:
<project>
...
<properties>
<!--hibernate.version>3.4.O.GA</hibernate.version--> <!-- for JPA 1.0 -->
<hibernate.version>3.5.4-Final</hibernate.version> <!-- for JPA 2.0 -->
<!--hibernate.version>3.6.0.Beta2</hibernate.version--> <!-- experimental -->
<properties>
...
<dependencies>
<!-- Hibernate dependencies -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>${hibernate.version}</version>
</dependency>
...
</dependencies>
...
</project>
And that's all you need.
The #Type annotation is present in hibernate-annotations, version 3.5.1-Final. I don't find the snapshot you are using 3.6.0-SNAPSHOT in the jboss repository, so I couldn't test that specifically, but my guess is that the annotation is missing/has been removed from the snapshot version for some reason.
Unless there is a specific reason you need a snapshot, I would stick to released versions. If you revert to 3.5.1-Final, that will fix the problem.
The Type API is changing in Hibernate 3.6.0. I would be surprised if the Joda Time Contrib classes work at all with Hibernate 3.6 although they should work with Hibernate 3.5. Can I suggest you take a look at my project which has implementations of Usertypes for Joda Time and JSR310: http://usertype.sourceforge.net/
Thanks and regards,
Chris