entityMananger不使用Date参数

时间:2016-01-22 17:24:16

标签: hibernate jpa criteria entitymanager hibernate-entitymanager

使用Hitynate的EntityManager方法。每当使用日期字段查询时,我希望它查找具有完整日期和时间的日期,但它仅使用日期而不是时间。

 where cou0_.expiry_date>'22-Jan-16'

spring config

<bean id="entityManagerFactory"
        class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="packagesToScan" value="com" />
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
        </property>
        <property name="jpaProperties">
            <props>
                <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
                <prop key="hibernate.dialect">${hibernate.dialect}</prop>
                <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
                <prop key="hibernate.cache.use_second_level_cache">${hibernate.cache.use_second_level_cache}</prop>
                <prop key="hibernate.cache.use_query_cache">${hibernate.cache.use_query_caches}</prop>
                <prop key="hibernate.cache.region.factory_class">${hibernate.cache.region.factory_class}</prop>
                <prop key="hibernate.generate_statistics">${hibernate.generate_statistics}</prop>
                <prop key="hibernate.use_sql_comments">${hibernate.use_sql_comments}</prop>
            </props>
        </property>
    </bean>

道具

hibernate.hbm2ddl.auto = update
hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
hibernate.c3p0.min_size = 5
hibernate.c3p0.max_size = 10
hibernate.c3p0.timeout = 300
hibernate.c3p0.max_statements = 50
hibernate.c3p0.idle_test_period = 3000
hibernate.generate_statistics = true
hibernate.show_sql=true
hibernate.use_sql_comments=true

声明为

的列
@Temporal(TemporalType.TIMESTAMP)
    @Column(name = "expiry_date")
    private Date expiryDate;

查询代码

Query query = getEntityManager().createQuery("from **** where c.expiryDate  > :expiryDate");
        Date now = new Date();
        now.setHours(8);
        System.out.println("Date--"+now);
        query.setParameter("expiryDate", now,TemporalType.TIMESTAMP);
        List<****> entity = query.getResultList();

1 个答案:

答案 0 :(得分:0)

问题不在于实体经理。我正在使用间谍跟踪查询。间谍具有可配置属性以格式显示日期。我没有配置它所以它想要使用默认格式,即dd-MMM-yyyy