使用Springboot数据rest和OpenJPA更新数据时出错

时间:2017-04-30 19:34:11

标签: postgresql spring-data-jpa spring-data-rest openjpa

我正在使用OpenJPA应用程序处理Springboot数据休息,但得到以下异常: RepositoryRestExceptionHandler : Cannot cast org.apache.openjpa.util.LongId to java.lang.Long java.lang.ClassCastException: Cannot cast org.apache.openjpa.util.LongId to java.lang.Long

以下是实体类: Station.java

@Entity
@Table(name = "STATION")
public class Station extends GenericEntityModel<Long> {

@Id
@SequenceGenerator(name="STATION_SEQ_GEN", sequenceName="STATION_SEQ_GEN", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator="STATION_SEQ_GEN")
@Column(name = "STATION_ID")
private Long id;

@Column(name = "STATION_NAME")
private String name;

@Column(name = "STATION_DESC")
private String description;

 @OneToMany(cascade = CascadeType.ALL, mappedBy = "station", fetch = FetchType.EAGER)
public List<Track> tracks;

 // setters getters

Track.java:

@Entity
@Table(name = "TRACK")
public class Track extends GenericEntityModel<Long> {

@Id
@SequenceGenerator(name = "TRACK_SEQ_GEN", sequenceName = "TRACK_SEQ_GEN", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "TRACK_SEQ_GEN")
@Column(name = "TRACK_ID")
private Long id;

@Column(name = "TRACK_NAME")
private String name;

@Column(name = "TRACK_DESC")
private String description;

@Enumerated(EnumType.STRING)
@Column(name = "TRACK_TYPE")
private TrackType type;

@Column(name = "TRACK_LENGTH")
private int trackLength;

@Enumerated(EnumType.STRING)
@Column(name = "DIRECTION")
private Direction direction;

@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "STATION_ID", nullable = false)
public Station station;

// setters and getters

GenericEntityModel.java

@MappedSuperclass
public abstract class GenericEntityModel<ID extends Serializable> implements Serializable {
  private static final long serialVersionUID = 1L;
  public static final String DEFAULT_SYSTEM_USER = "SYSTEM";

  @Column(name = "CREATED_DATE", insertable = true, updatable = false)
  @Temporal(TemporalType.TIMESTAMP)
  protected Date createdDate = new Date();

  @Column(name = "CREATED_BY")
  protected String createdBy = DEFAULT_SYSTEM_USER;

  @Column(name = "MODIFIED_DATE", insertable = true, updatable = true)
  @Temporal(TemporalType.TIMESTAMP)
  protected Date modifiedDate = new Date();

  @Column(name = "MODIFIED_BY")
  protected String modifiedBy = DEFAULT_SYSTEM_USER;

我正在使用spring数据休息。 这是存储库类:

@RepositoryRestResource(collectionResourceRel = "station", path = "station")
public interface StationRepository extends PagingAndSortingRepository<Station, 
Long> {
 }

// For Track
@RepositoryRestResource(collectionResourceRel = "track", path = "track")
public interface TrackRepository extends PagingAndSortingRepository<Track, Long> {
 }

Q1。当我尝试使用springdata休息更新电台时,我得到了上述异常。

0 个答案:

没有答案