gpt4 book ai didi

JAVA hibernate/webservice - 时间戳问题

转载 作者:行者123 更新时间:2023-12-02 08:31:58 25 4
gpt4 key购买 nike

在我的一个 hibernate 类中,我有一个时间戳变量。现在,当我只使用服务器上的 hibernate 功能时,一切都很好。但现在我正在使用 wsgen 实现 Web 服务。

我收到错误,因为 Timestamp 没有无参数默认构造函数。

消息;

Caused by: java.security.PrivilegedActionException: com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
java.sql.Timestamp does not have a no-arg default constructor.

类(class):

package com.PTS42.planner;

import java.io.Serializable;
import java.sql.Timestamp;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.persistence.*;
import org.hibernate.annotations.GenericGenerator;

@WebService
@Entity @Table(name="Reserveringen")
public class Reservering implements Serializable {

@Id @GenericGenerator(name = "generator", strategy = "increment")
@GeneratedValue(generator = "generator")
private int id;

private Timestamp vanaf;

private Timestamp tot;

@ManyToOne
@Embedded
private Klant klant;

@ManyToOne
@Embedded
private Machine machine;

public int getId() {
return id;
}

public void setId(@WebParam(name="reservering_id")int id) {
this.id = id;
}

public Klant getKlant() {
return klant;
}

public void setKlant(@WebParam(name="reservering_klant")Klant klant) {
this.klant = klant;
}

public Timestamp getTot() {
return tot;
}

public void setTot(@WebParam(name="reservering_tot")Timestamp tot) {
int tempint = tot.getMonth();
tot.setMonth(tempint-1);
this.tot = tot;
}

public Timestamp getVanaf() {
return vanaf;
}

public void setVanaf(@WebParam(name="reservering_vanaf")Timestamp vanaf) {
int tempint = vanaf.getMonth();
vanaf.setMonth(tempint-1);
this.vanaf = vanaf;
}

public Machine getMachine() {
return machine;
}

public void setMachine(@WebParam(name="reservering_machine")Machine machine) {
this.machine = machine;
}




public Reservering() {
}

public Reservering(@WebParam(name="reservering_constructor_vanaf") Timestamp vanaf, @WebParam(name="reservering_constructor_tot")Timestamp tot, @WebParam(name="reservering_constructor_klant")Klant klant, @WebParam(name="reservering_constructor_machine")Machine machine)
{

this.vanaf = vanaf;
this.tot = tot;
this.klant = klant;
this.machine = machine;
}



}

任何人都知道如何解决这个问题,而无需使用除时间戳之外的其他类型的变量。

最佳答案

我不确定您为什么反对使用除时间戳之外的其他内容。以下代码将为您提供相同的数据库结构,并且它不会尝试公开 SQL 类,而 SQL 类与公开的业务无关:

package com.PTS42.planner;

import java.io.Serializable;
import java.util.Date
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.persistence.*;
import org.hibernate.annotations.GenericGenerator;

@WebService
@Entity @Table(name="Reserveringen")
public class Reservering implements Serializable {

@Id @GenericGenerator(name = "generator", strategy = "increment")
@GeneratedValue(generator = "generator")
private int id;

@Temporal(TemporalType.TIMESTAMP)
private Date vanaf;

@Temporal(TemporalType.TIMESTAMP)
private Date tot;

@ManyToOne
@Embedded
private Klant klant;

@ManyToOne
@Embedded
private Machine machine;

public int getId() {
return id;
}

public void setId(@WebParam(name="reservering_id")int id) {
this.id = id;
}

public Klant getKlant() {
return klant;
}

public void setKlant(@WebParam(name="reservering_klant")Klant klant) {
this.klant = klant;
}

public Date getTot() {
return tot;
}

public void setTot(@WebParam(name="reservering_tot")Date tot) {
//int tempint = tot.getMonth();
//tot.setMonth(tempint-1);
this.tot = tot;
}

public Date getVanaf() {
return vanaf;
}

public void setVanaf(@WebParam(name="reservering_vanaf")Date vanaf) {
//int tempint = vanaf.getMonth();
//vanaf.setMonth(tempint-1);
this.vanaf = vanaf;
}

public Machine getMachine() {
return machine;
}

public void setMachine(@WebParam(name="reservering_machine")Machine machine) {
this.machine = machine;
}

public Reservering() {
}

public Reservering(@WebParam(name="reservering_constructor_vanaf") Date vanaf, @WebParam(name="reservering_constructor_tot")Date tot, @WebParam(name="reservering_constructor_klant")Klant klant, @WebParam(name="reservering_constructor_machine")Machine machine)
{

this.vanaf = vanaf;
this.tot = tot;
this.klant = klant;
this.machine = machine;
}
}

关于JAVA hibernate/webservice - 时间戳问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3093300/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com