Java Spring数据不保存日期

Java Spring数据不保存日期,java,spring,hibernate,date,spring-data,Java,Spring,Hibernate,Date,Spring Data,我有一个Spring项目,其中有一个简单的实体和一个JPA存储库。实体有三个变量:Name(String)、active(boolean)和date(java.util.date)。部署后,Hibernate使用varchar、tinyint和datetime在MySQL数据库中创建表。所有这些看起来都是正确的,但是当我创建/修改实体的实例并调用存储库的save()方法时,除了日期之外,所有字段都会被保存。在JPA存储库或meaby中存储日期是否有任何问题?我做错了什么 我没有在这里放任何代码,

我有一个Spring项目,其中有一个简单的实体和一个JPA存储库。实体有三个变量:
Name(String)
active(boolean)
date(java.util.date)
。部署后,Hibernate使用
varchar
tinyint
datetime
在MySQL数据库中创建表。所有这些看起来都是正确的,但是当我创建/修改实体的实例并调用存储库的
save()
方法时,除了日期之外,所有字段都会被保存。在JPA存储库或meaby中存储日期是否有任何问题?我做错了什么

我没有在这里放任何代码,因为它只是一个简单的类和存储库的接口。此外,正在保存实体。我的问题只与日期字段(以及我可以定义的任何其他日期字段)有关。话虽如此,如果需要什么,尽管问吧

编辑:

root-context.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:jpa="http://www.springframework.org/schema/data/jpa"
    xmlns:task="http://www.springframework.org/schema/task"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
    http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd">

    <!-- Root Context: defines shared resources visible to all other web components -->

    <import resource="infraestructure.xml" />

    <jpa:repositories base-package="com.smarttabletv.repository" />

</beans>
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:task="http://www.springframework.org/schema/task"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd">

    <!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->

    <!-- Enables the Spring MVC @Controller programming model -->
    <annotation-driven />

    <!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
    <resources mapping="/resources/**" location="/resources/" />

    <!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
    <beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <beans:property name="prefix" value="/WEB-INF/views/" />
        <beans:property name="suffix" value=".jsp" />
    </beans:bean>

    <context:component-scan base-package="com.smarttabletv" />

    <!-- Activates @Scheduled and @Async annotations for scheduling -->
    <task:annotation-driven />

</beans:beans>
代码不工作

Task task = taskService.findDispatchableTask();
task.setDispatched(true); // This is saved
task.setEndDate(new Date()); // But this not
taskService.save(task);
任务类第一行

@Entity
@Table(name = "sttv_tasks")
public class Task {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "tsk_id")
    private Long id;

    @Column(name = "tsk_end_date")
    private Date endDate;

您忘记在endDate上添加临时注释,指定是应该保留日期、时间还是两者

@Column(name = "tsk_end_date")
@Temporal(TemporalType.TIMESTAMP)
private Date endDate;

您忘记在endDate上添加临时注释,指定是应该保留日期、时间还是两者

@Column(name = "tsk_end_date")
@Temporal(TemporalType.TIMESTAMP)
private Date endDate;

请发布包含实体映射、存储库定义以及客户端代码的域类。感谢您的回答@OliverGierke。我刚刚更新了帖子。请发布带有实体映射、存储库定义以及客户端代码的域类。谢谢@OliverGierke的回答。我刚刚更新了帖子,我不知道我必须这么做。非常感谢你!我不知道我必须这么做。非常感谢你!
@Entity
@Table(name = "sttv_tasks")
public class Task {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "tsk_id")
    private Long id;

    @Column(name = "tsk_end_date")
    private Date endDate;
@Column(name = "tsk_end_date")
@Temporal(TemporalType.TIMESTAMP)
private Date endDate;