未调用的域对象上的hibernate setter

时间:2016-11-20 11:31:39

标签: java mysql eclipse hibernate

我正在尝试发布这样的请求:

<event><name>test</name><description>event description</description></event>

然而在mySQL表中,我的表项目显示:

id | description       | name
1  | event description | NULL

我无法弄清楚为什么即使描述有效,也不会调用事件名称的setter。以下是我如何调用我的方法

资源类发布方法:

...
//add event a method in my service class
//getEventName is null, getDescription gets description
myservice.addEvent(event.getEventName(),event.getDescription());
...

域类:

@Entity
@Table( name = "events" )
@XmlRootElement(name = "event")
public class Event {
    @XmlAttribute
    private Long id;
    private String eventName;
    private String description;

    public Event() {
        // this form used by Hibernate
    }

    public Event(String eventName, String description) {
        this.description = description;
        this.eventName = eventName;
    }

    @Id
    @GeneratedValue(generator="increment")
    @GenericGenerator(name="increment", strategy = "increment")
    public Long getId() {
        return id;
    }

    private void setId(Long id) {
        System.out.println("id " + id); //prints id correctly
        this.id = id;
    }

    @Column(name="name")
    public String getEventName() {
        return eventName;
    }

    public void setEventName(String eventName) {
        System.out.println("here event" + eventName); //prints nothing
        this.eventName = eventName;
    }

    @Column(name="description")
    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        System.out.println("here desc " + description); //prints correctly
        this.description = description;
    }
}

控制台输出:

here desc event description
id 3

是什么导致我的setEventName被忽略?控制台

中没有出现任何错误

0 个答案:

没有答案