Hibernate - 嵌入式类的复合键

时间:2016-07-19 10:09:45

标签: java hibernate key c3p0 composite

我面临一个严重的问题,关于复合键与Hibernate 4.3.9 Final和c3p0 4.3.8。

首先,我想简要介绍一下我的实体和我的数据库的关系。

重要的表格:

CREATE TABLE `TrainingplanHistory` (
  `TrainingplanID` int(11) NOT NULL,
  `time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`TrainingplanID`,`time`),
  CONSTRAINT `fk_trainingplanHistory_trainingplan` FOREIGN KEY (`TrainingplanID`) REFERENCES `Trainingplan` (`TrainingplanID`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=latin1

   CREATE TABLE `TrainingplanHistoryExercises` (
  `TrainingplanID` int(11) NOT NULL,
  `ExerciseID` int(11) NOT NULL,
  `Time` datetime NOT NULL,
  `ParameterID` int(11) NOT NULL,
  `value` varchar(45) NOT NULL,
  `position` int(11) NOT NULL,
  PRIMARY KEY (`TrainingplanID`,`Time`,`ParameterID`,`position`),
  KEY `fk_trainingplanhistory_exercises_trainingplanhistory_idx` (`TrainingplanID`,`Time`),
  KEY `fk_trainingplanhsitoryexercises_exercises_idx` (`ExerciseID`),
  KEY `fk_trainingplanhsitoryexercises_exercises_parameter_idx` (`ExerciseID`,`ParameterID`),
  CONSTRAINT `fk_trainingplanhistory_exercises_trainingplanhistory` FOREIGN KEY (`TrainingplanID`, `Time`) REFERENCES `TrainingplanHistory` (`TrainingplanID`, `time`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=latin1

Java中的我的数据类:

TrainingplanHistory.java
package beans;

import javax.persistence.*;
import java.util.Date;

/**
 * Created by Administrator on 18.07.2016.
 */
@Entity
@Table(name="TrainingplanHistory")
public class TrainingplanHistory {
    private TrainingplanHistoryId id;
    private Date time;

    public TrainingplanHistory(TrainingplanHistoryId id, Date time)
    {
        this.id = id;
        this.time = time;
    }

    public TrainingplanHistory()
    {
        this(null,null);
    }

    @EmbeddedId
    public TrainingplanHistoryId getId() {
        return id;
    }

    public void setId(TrainingplanHistoryId id) {
        this.id = id;
    }

    public Date getTime() {
        return time;
    }

    public void setTime(Date time) {
        this.time = time;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        TrainingplanHistory that = (TrainingplanHistory) o;

        if (!id.equals(that.id)) return false;
        return time.equals(that.time);

    }

    @Override
    public int hashCode() {
        int result = id.hashCode();
        result = 31 * result + time.hashCode();
        return result;
    }

    @Override
    public String toString() {
        return "TrainingplanHistory{" +
                "id=" + id +
                ", time=" + time +
                '}';
    }
}


TrainingplanHistoryId.java
package beans;

import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;

/**
 * Created by Administrator on 17.07.2016.
 */
@Embeddable
public class TrainingplanHistoryId implements Serializable{
    private Training training;

    public TrainingplanHistoryId(Training training) {
        this.training = training;
    }

    public TrainingplanHistoryId()
    {

    }

    @ManyToOne(fetch = FetchType.LAZY, targetEntity = Training.class, cascade = CascadeType.ALL)
    @JoinColumn(name = "TrainingplanID")
    public Training getTraining() {
        return training;
    }

    public void setTraining(Training training) {
        this.training = training;
    }


    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        TrainingplanHistoryId that = (TrainingplanHistoryId) o;

        return training.equals(that.training);

    }

    @Override
    public int hashCode() {
        return training.hashCode();
    }

    @Override
    public String toString() {
        return "TrainingplanHistoryId{" +
                "training=" + training +
                '}';
    }
}

此代码与conmposite Key“TrainingplanID”和“time”的效果非常好,但我的主要问题是“时间”是外键,也是我的表TrainingSTnHistoryExercises中的主键。

因此我写了这段代码:

TrainingplanHistoryExercise.java
package beans;

import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;

/**
 * Created by Administrator on 17.07.2016.
 */
@Entity
@Table(name="TrainingplanHistoryExercises")
public class TrainingplanHistoryExercise{
    private Exercise exercise;
    private StringProperty value;
    private TrainingplanHistoryExerciseId id;

    public TrainingplanHistoryExercise(Exercise exercise, String value, TrainingplanHistoryExerciseId id) {
        this.exercise = exercise;
        this.value = new SimpleStringProperty(value);
        this.id = id;
    }

    public TrainingplanHistoryExercise()
    {
        this(null,null,null);
    }

    @ManyToOne(fetch = FetchType.LAZY, targetEntity = Exercise.class)
    @JoinColumn(name = "ExerciseID")
    public Exercise getExercise() {
        return exercise;
    }

    public void setExercise(Exercise exercise) {
        this.exercise = exercise;
    }

    public String getValue() {
        return value.get();
    }

    public StringProperty valueProperty() {
        return value;
    }

    public void setValue(String value) {
        this.value.set(value);
    }

    @EmbeddedId
    public TrainingplanHistoryExerciseId getId() {
        return id;
    }

    public void setId(TrainingplanHistoryExerciseId id) {
        this.id = id;
    }

    @Transient
    public int getPosition()
    {
        return id.getPosition();
    }

    @Transient
    public Parameter getParameter()
    {
        return id.getParameter();
    }

    @Transient
    public Date getTime()
    {
        return id.getTime();
    }

    @Transient
    public Training getTraining()
    {
        return id.getTraining();
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        TrainingplanHistoryExercise that = (TrainingplanHistoryExercise) o;

        if (!exercise.equals(that.exercise)) return false;
        if (!value.equals(that.value)) return false;
        return id.equals(that.id);

    }

    @Override
    public int hashCode() {
        int result = exercise.hashCode();
        result = 31 * result + value.hashCode();
        result = 31 * result + id.hashCode();
        return result;
    }

    @Override
    public String toString() {
        return "TrainingplanHistoryExercise{" +
                "exercise=" + exercise +
                ", value=" + value +
                ", id=" + id +
                '}';
    }
}

TrainingplanHistoryExerciseId.java 包豆;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;

/**
 * Created by Administrator on 18.07.2016.
 */
@Embeddable
public class TrainingplanHistoryExerciseId implements Serializable{
    private Training training;
    private Date time;
    private Parameter parameter;
    private int position;

    public TrainingplanHistoryExerciseId(Training training, Date time, Parameter parameter, int position) {
        this.training = training;
        this.time = time;
        this.parameter = parameter;
        this.position = position;
    }

    public TrainingplanHistoryExerciseId(){}

    @ManyToOne(fetch = FetchType.LAZY, targetEntity = Training.class, cascade = CascadeType.ALL)
    @JoinColumn(name = "TrainingplanID")
    public Training getTraining() {
        return training;
    }

    public void setTraining(Training training) {
        this.training = training;
    }

    @ManyToOne(fetch = FetchType.LAZY, targetEntity = TrainingplanHistory.class, cascade = CascadeType.ALL)
    @JoinColumn(name = "Time")
    public Date getTime() {
        return time;
    }

    public void setTime(Date time) {
        this.time = time;
    }

    @ManyToOne(fetch = FetchType.LAZY, targetEntity = Parameter.class, cascade = CascadeType.ALL)
    @JoinColumn(name = "ParameterID")
    public Parameter getParameter() {
        return parameter;
    }

    public void setParameter(Parameter parameter) {
        this.parameter = parameter;
    }

    public int getPosition() {
        return position;
    }

    public void setPosition(int position) {
        this.position = position;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        TrainingplanHistoryExerciseId that = (TrainingplanHistoryExerciseId) o;

        if (position != that.position) return false;
        if (!training.equals(that.training)) return false;
        if (!time.equals(that.time)) return false;
        return parameter.equals(that.parameter);

    }

    @Override
    public int hashCode() {
        int result = training.hashCode();
        result = 31 * result + time.hashCode();
        result = 31 * result + parameter.hashCode();
        result = 31 * result + position;
        return result;
    }

    @Override
    public String toString() {
        return "TrainingplanHistoryExerciseId{" +
                "training=" + training +
                ", time=" + time +
                ", parameter=" + parameter +
                ", position=" + position +
                '}';
    }
}

我的问题是我的应用程序无法启动,因为我猜测会出现一些映射错误。

这是我的log4j输出的一部分:

2016-07-19 12:04:50,078}ABSOLUTE{ TRACE org.hibernate.event.internal.DefaultLoadEventListener}1{:251 - Loading entity: [beans.Training#2016]
2016-07-19 12:04:50,078}ABSOLUTE{ TRACE org.hibernate.event.internal.DefaultLoadEventListener}1{:348 - Creating new proxy for entity
2016-07-19 12:04:50,080}ABSOLUTE{ TRACE org.hibernate.type.descriptor.sql.BasicExtractor}1{:78 - extracted value ([Training4_13_0_] : [INTEGER]) - [66]
2016-07-19 12:04:50,080}ABSOLUTE{ TRACE org.hibernate.event.internal.DefaultLoadEventListener}1{:251 - Loading entity: [beans.Parameter#5]
2016-07-19 12:04:50,080}ABSOLUTE{ TRACE org.hibernate.event.internal.DefaultLoadEventListener}1{:338 - Entity found in session cache
2016-07-19 12:04:50,080}ABSOLUTE{ TRACE org.hibernate.event.internal.DefaultLoadEventListener}1{:251 - Loading entity: [beans.TrainingplanHistory#component[training]{training=beans.Training#2016}]
2016-07-19 12:04:50,080}ABSOLUTE{ TRACE org.hibernate.event.internal.DefaultLoadEventListener}1{:348 - Creating new proxy for entity
2016-07-19 12:04:50,081}ABSOLUTE{ TRACE org.hibernate.event.internal.DefaultLoadEventListener}1{:251 - Loading entity: [beans.Training#66]
2016-07-19 12:04:50,081}ABSOLUTE{ TRACE org.hibernate.event.internal.DefaultLoadEventListener}1{:338 - Entity found in session cache
2016-07-19 12:04:50,081}ABSOLUTE{ ERROR org.hibernate.property.BasicPropertyAccessor}1{:121 - HHH000123: IllegalArgumentException in class: beans.TrainingplanHistoryExerciseId, setter method of property: time
2016-07-19 12:04:50,081}ABSOLUTE{ ERROR org.hibernate.property.BasicPropertyAccessor}1{:122 - HHH000091: Expected type: java.util.Date, actual value: beans.TrainingplanHistory_$$_jvst390_6
2016-07-19 12:04:50,082}ABSOLUTE{ DEBUG org.hibernate.internal.SessionImpl}1{:1008 - Initializing proxy: [beans.TrainingplanHistory#component[training]{training=beans.Training#2016}]
2016-07-19 12:04:50,082}ABSOLUTE{ TRACE org.hibernate.event.internal.DefaultLoadEventListener}1{:425 - Attempting to resolve: [beans.TrainingplanHistory#component[training]{training=beans.Training#2016}]
2016-07-19 12:04:50,082}ABSOLUTE{ TRACE org.hibernate.event.internal.DefaultLoadEventListener}1{:463 - Object not resolved in any cache: [beans.TrainingplanHistory#component[training]{training=beans.Training#2016}]
2016-07-19 12:04:50,083}ABSOLUTE{ TRACE org.hibernate.persister.entity.AbstractEntityPersister}1{:4122 - Fetching entity: [beans.TrainingplanHistory#component[training]{training=beans.Training#2016}]
2016-07-19 12:04:50,083}ABSOLUTE{ DEBUG org.hibernate.SQL}1{:109 - select trainingpl0_.TrainingplanID as Training2_12_0_, trainingpl0_.time as time1_12_0_ from TrainingplanHistory trainingpl0_ where trainingpl0_.TrainingplanID=?
Hibernate: select trainingpl0_.TrainingplanID as Training2_12_0_, trainingpl0_.time as time1_12_0_ from TrainingplanHistory trainingpl0_ where trainingpl0_.TrainingplanID=?
2016-07-19 12:04:50,083}ABSOLUTE{ DEBUG com.mchange.v2.async.ThreadPoolAsynchronousRunner}1{:236 - com.mchange.v2.async.ThreadPoolAsynchronousRunner@5100cfa1: Adding task to queue -- com.mchange.v2.c3p0.stmt.GooGooStatementCache$1StmtAcquireTask@79eb85cf
2016-07-19 12:04:50,084}ABSOLUTE{ DEBUG com.mchange.v2.c3p0.stmt.GooGooStatementCache}1{:475 - cxnStmtMgr.statementSet( com.mysql.jdbc.JDBC4Connection@49882f9b ).size(): 14
2016-07-19 12:04:50,084}ABSOLUTE{ DEBUG com.mchange.v2.c3p0.stmt.GooGooStatementCache}1{:232 - checkoutStatement: com.mchange.v2.c3p0.stmt.GlobalMaxOnlyStatementCache stats -- total size: 14; checked out: 2; num connections: 1; num keys: 14
2016-07-19 12:04:50,084}ABSOLUTE{ TRACE org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl}1{:371 - Registering statement [com.mchange.v2.c3p0.impl.NewProxyPreparedStatement@742941c0]
2016-07-19 12:04:50,084}ABSOLUTE{ TRACE org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl}1{:386 - Registering last query statement [com.mchange.v2.c3p0.impl.NewProxyPreparedStatement@742941c0]
2016-07-19 12:04:50,085}ABSOLUTE{ TRACE org.hibernate.type.descriptor.sql.BasicBinder}1{:81 - binding parameter [1] as [INTEGER] - [2016]
2016-07-19 12:04:50,086}ABSOLUTE{ TRACE org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader}1{:304 - Bound [2] parameters total
2016-07-19 12:04:50,109}ABSOLUTE{ TRACE org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl}1{:437 - Registering result set [com.mchange.v2.c3p0.impl.NewProxyResultSet@70b5154]
2016-07-19 12:04:50,110}ABSOLUTE{ TRACE org.hibernate.loader.plan.exec.process.internal.ResultSetProcessorImpl}1{:124 - Processing result set
2016-07-19 12:04:50,110}ABSOLUTE{ TRACE org.hibernate.loader.plan.exec.process.internal.ResultSetProcessorImpl}1{:138 - Done processing result set (0 rows)
2016-07-19 12:04:50,110}ABSOLUTE{ TRACE org.hibernate.loader.plan.exec.process.internal.AbstractRowReader}1{:237 - Total objects hydrated: 0
2016-07-19 12:04:50,110}ABSOLUTE{ TRACE org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl}1{:455 - Releasing result set [com.mchange.v2.c3p0.impl.NewProxyResultSet@70b5154]
2016-07-19 12:04:50,110}ABSOLUTE{ TRACE org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl}1{:573 - Closing result set [com.mchange.v2.c3p0.impl.NewProxyResultSet@70b5154]
2016-07-19 12:04:50,111}ABSOLUTE{ TRACE org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl}1{:412 - Releasing statement [com.mchange.v2.c3p0.impl.NewProxyPreparedStatement@742941c0]
2016-07-19 12:04:50,111}ABSOLUTE{ TRACE org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl}1{:525 - Closing prepared statement [com.mchange.v2.c3p0.impl.NewProxyPreparedStatement@742941c0]
2016-07-19 12:04:50,133}ABSOLUTE{ DEBUG com.mchange.v2.c3p0.stmt.GooGooStatementCache}1{:307 - checkinStatement(): com.mchange.v2.c3p0.stmt.GlobalMaxOnlyStatementCache stats -- total size: 14; checked out: 1; num connections: 1; num keys: 14
2016-07-19 12:04:50,133}ABSOLUTE{ TRACE org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl}1{:278 - Starting after statement execution processing [ON_CLOSE]
2016-07-19 12:04:50,134}ABSOLUTE{ DEBUG org.hibernate.internal.SessionImpl}1{:208 - Initializing proxy: [beans.Training#2016]
2016-07-19 12:04:50,134}ABSOLUTE{ TRACE org.hibernate.event.internal.DefaultLoadEventListener}1{:208 - Attempting to resolve: [beans.Training#2016]
2016-07-19 12:04:50,134}ABSOLUTE{ TRACE org.hibernate.event.internal.DefaultLoadEventListener}1{:208 - Object not resolved in any cache: [beans.Training#2016]
2016-07-19 12:04:50,134}ABSOLUTE{ TRACE org.hibernate.persister.entity.AbstractEntityPersister}1{:208 - Fetching entity: [beans.Training#2016]
2016-07-19 12:04:50,134}ABSOLUTE{ DEBUG org.hibernate.SQL}1{:234 - select training0_.TrainingplanID as Training1_10_0_, training0_.Active as Active2_10_0_, training0_.Annotation as Annotati3_10_0_, training0_.client as client8_10_0_, training0_.Name as Name4_10_0_, training0_.trainer as trainer9_10_0_, training0_.type as type10_10_0_, training0_.Unit as Unit5_10_0_, training0_.validFrom as validFro6_10_0_, training0_.validTo as validTo7_10_0_, person1_.PersonID as PersonID1_7_1_, person1_.Annotation as Annotati2_7_1_, person1_.birthdate as birthdat3_7_1_, person1_.CustomerID as Customer4_7_1_, person1_.forname as forname5_7_1_, person1_.Password as Password6_7_1_, person1_.surename as surename7_7_1_, person1_.isTrainer as isTraine8_7_1_, exercises2_.trainingplan as training4_10_2_, exercises2_.parameter as paramete3_11_2_, exercises2_.position as position1_11_2_, exercises2_.trainingplan as training4_11_2_, exercises2_.parameter as paramete3_11_3_, exercises2_.position as position1_11_3_, exercises2_.trainingplan as training4_11_3_, exercises2_.exercise as exercise5_11_3_, exercises2_.value as value2_11_3_, person3_.PersonID as PersonID1_7_4_, person3_.Annotation as Annotati2_7_4_, person3_.birthdate as birthdat3_7_4_, person3_.CustomerID as Customer4_7_4_, person3_.forname as forname5_7_4_, person3_.Password as Password6_7_4_, person3_.surename as surename7_7_4_, person3_.isTrainer as isTraine8_7_4_, trainingpl4_.TrainingplanTypeID as Training1_14_5_, trainingpl4_.imgLink as imgLink2_14_5_, trainingpl4_.Name as Name3_14_5_ from Trainingplan training0_ left outer join Person person1_ on training0_.client=person1_.PersonID left outer join TrainingplanExercises exercises2_ on training0_.TrainingplanID=exercises2_.trainingplan left outer join Person person3_ on training0_.trainer=person3_.PersonID left outer join TrainingplanType trainingpl4_ on training0_.type=trainingpl4_.TrainingplanTypeID where training0_.TrainingplanID=?
Hibernate: select training0_.TrainingplanID as Training1_10_0_, training0_.Active as Active2_10_0_, training0_.Annotation as Annotati3_10_0_, training0_.client as client8_10_0_, training0_.Name as Name4_10_0_, training0_.trainer as trainer9_10_0_, training0_.type as type10_10_0_, training0_.Unit as Unit5_10_0_, training0_.validFrom as validFro6_10_0_, training0_.validTo as validTo7_10_0_, person1_.PersonID as PersonID1_7_1_, person1_.Annotation as Annotati2_7_1_, person1_.birthdate as birthdat3_7_1_, person1_.CustomerID as Customer4_7_1_, person1_.forname as forname5_7_1_, person1_.Password as Password6_7_1_, person1_.surename as surename7_7_1_, person1_.isTrainer as isTraine8_7_1_, exercises2_.trainingplan as training4_10_2_, exercises2_.parameter as paramete3_11_2_, exercises2_.position as position1_11_2_, exercises2_.trainingplan as training4_11_2_, exercises2_.parameter as paramete3_11_3_, exercises2_.position as position1_11_3_, exercises2_.trainingplan as training4_11_3_, exercises2_.exercise as exercise5_11_3_, exercises2_.value as value2_11_3_, person3_.PersonID as PersonID1_7_4_, person3_.Annotation as Annotati2_7_4_, person3_.birthdate as birthdat3_7_4_, person3_.CustomerID as Customer4_7_4_, person3_.forname as forname5_7_4_, person3_.Password as Password6_7_4_, person3_.surename as surename7_7_4_, person3_.isTrainer as isTraine8_7_4_, trainingpl4_.TrainingplanTypeID as Training1_14_5_, trainingpl4_.imgLink as imgLink2_14_5_, trainingpl4_.Name as Name3_14_5_ from Trainingplan training0_ left outer join Person person1_ on training0_.client=person1_.PersonID left outer join TrainingplanExercises exercises2_ on training0_.TrainingplanID=exercises2_.trainingplan left outer join Person person3_ on training0_.trainer=person3_.PersonID left outer join TrainingplanType trainingpl4_ on training0_.type=trainingpl4_.TrainingplanTypeID where training0_.TrainingplanID=?
2016-07-19 12:04:50,135}ABSOLUTE{ DEBUG com.mchange.v2.async.ThreadPoolAsynchronousRunner}1{:236 - com.mchange.v2.async.ThreadPoolAsynchronousRunner@5100cfa1: Adding task to queue -- com.mchange.v2.c3p0.stmt.GooGooStatementCache$1StmtAcquireTask@78d63b22
2016-07-19 12:04:50,136}ABSOLUTE{ DEBUG com.mchange.v2.c3p0.stmt.GooGooStatementCache}1{:475 - cxnStmtMgr.statementSet( com.mysql.jdbc.JDBC4Connection@49882f9b ).size(): 15
2016-07-19 12:04:50,136}ABSOLUTE{ DEBUG com.mchange.v2.c3p0.stmt.GooGooStatementCache}1{:232 - checkoutStatement: com.mchange.v2.c3p0.stmt.GlobalMaxOnlyStatementCache stats -- total size: 15; checked out: 2; num connections: 1; num keys: 15
2016-07-19 12:04:50,137}ABSOLUTE{ TRACE org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl}1{:208 - Registering statement [com.mchange.v2.c3p0.impl.NewProxyPreparedStatement@53295f57]
2016-07-19 12:04:50,137}ABSOLUTE{ TRACE org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl}1{:208 - Registering last query statement [com.mchange.v2.c3p0.impl.NewProxyPreparedStatement@53295f57]
2016-07-19 12:04:50,137}ABSOLUTE{ TRACE org.hibernate.type.descriptor.sql.BasicBinder}1{:234 - binding parameter [1] as [INTEGER] - [2016]
2016-07-19 12:04:50,137}ABSOLUTE{ TRACE org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader}1{:208 - Bound [2] parameters total
2016-07-19 12:04:50,186}ABSOLUTE{ TRACE org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl}1{:208 - Registering result set [com.mchange.v2.c3p0.impl.NewProxyResultSet@34045ac0]
2016-07-19 12:04:50,187}ABSOLUTE{ TRACE org.hibernate.loader.plan.exec.process.internal.ResultSetProcessorImpl}1{:234 - Processing result set
2016-07-19 12:04:50,187}ABSOLUTE{ TRACE org.hibernate.loader.plan.exec.process.internal.ResultSetProcessorImpl}1{:234 - Done processing result set (0 rows)
2016-07-19 12:04:50,187}ABSOLUTE{ TRACE org.hibernate.loader.plan.exec.process.internal.AbstractRowReader}1{:234 - Total objects hydrated: 0
2016-07-19 12:04:50,187}ABSOLUTE{ TRACE org.hibernate.engine.loading.internal.LoadContexts}1{:208 - Constructing collection load context for result set [com.mchange.v2.c3p0.impl.NewProxyResultSet@34045ac0]
2016-07-19 12:04:50,188}ABSOLUTE{ DEBUG org.hibernate.engine.loading.internal.CollectionLoadContext}1{:208 - No collections were found in result set for role: beans.Training.exercises
2016-07-19 12:04:50,188}ABSOLUTE{ TRACE org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl}1{:208 - Releasing result set [com.mchange.v2.c3p0.impl.NewProxyResultSet@34045ac0]
2016-07-19 12:04:50,188}ABSOLUTE{ TRACE org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl}1{:208 - Closing result set [com.mchange.v2.c3p0.impl.NewProxyResultSet@34045ac0]
2016-07-19 12:04:50,188}ABSOLUTE{ TRACE org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl}1{:208 - Releasing statement [com.mchange.v2.c3p0.impl.NewProxyPreparedStatement@53295f57]
2016-07-19 12:04:50,189}ABSOLUTE{ TRACE org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl}1{:208 - Closing prepared statement [com.mchange.v2.c3p0.impl.NewProxyPreparedStatement@53295f57]
2016-07-19 12:04:50,212}ABSOLUTE{ DEBUG com.mchange.v2.c3p0.stmt.GooGooStatementCache}1{:307 - checkinStatement(): com.mchange.v2.c3p0.stmt.GlobalMaxOnlyStatementCache stats -- total size: 15; checked out: 1; num connections: 1; num keys: 15
2016-07-19 12:04:50,212}ABSOLUTE{ TRACE org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl}1{:208 - Starting after statement execution processing [ON_CLOSE]
2016-07-19 12:04:50,212}ABSOLUTE{ DEBUG org.hibernate.loader.entity.plan.AbstractLoadPlanBasedEntityLoader}1{:208 - Done entity load : beans.Training#2016
2016-07-19 12:04:50,214}ABSOLUTE{ TRACE org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl}1{:412 - Releasing statement [com.mchange.v2.c3p0.impl.NewProxyPreparedStatement@633e5dfc]
2016-07-19 12:04:50,214}ABSOLUTE{ TRACE org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl}1{:573 - Closing result set [com.mchange.v2.c3p0.impl.NewProxyResultSet@65abe6f1]
2016-07-19 12:04:50,214}ABSOLUTE{ TRACE org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl}1{:525 - Closing prepared statement [com.mchange.v2.c3p0.impl.NewProxyPreparedStatement@633e5dfc]
2016-07-19 12:04:50,236}ABSOLUTE{ DEBUG com.mchange.v2.c3p0.stmt.GooGooStatementCache}1{:307 - checkinStatement(): com.mchange.v2.c3p0.stmt.GlobalMaxOnlyStatementCache stats -- total size: 15; checked out: 0; num connections: 1; num keys: 15
2016-07-19 12:04:50,236}ABSOLUTE{ TRACE org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl}1{:278 - Starting after statement execution processing [ON_CLOSE]
2016-07-19 12:04:54,977}ABSOLUTE{ DEBUG com.mchange.v2.async.ThreadPoolAsynchronousRunner}1{:730 - com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@755e664a -- Running DeadlockDetector[Exiting. No pending tasks.]

对我来说非常奇怪的是以下几行:

2016-07-19 12:04:50,081}ABSOLUTE{ ERROR org.hibernate.property.BasicPropertyAccessor}1{:121 - HHH000123: IllegalArgumentException in class: beans.TrainingplanHistoryExerciseId, setter method of property: time
2016-07-19 12:04:50,081}ABSOLUTE{ ERROR org.hibernate.property.BasicPropertyAccessor}1{:122 - HHH000091: Expected type: java.util.Date, actual value: beans.TrainingplanHistory_$$_jvst390_6

如果您需要任何进一步的信息,请告诉我们!

如果有人可以帮助我,我会很高兴:)

谢谢!

1 个答案:

答案 0 :(得分:0)

我认为问题在于:

@ManyToOne(fetch = FetchType.LAZY, targetEntity = TrainingplanHistory.class, cascade = CascadeType.ALL)
    @JoinColumn(name = "Time")
    public Date getTime() {
        return time;
    }

targetEntity = TrainingplanHistory.class这必须是targetEntity = Date.class,