编辑直接从JPA查询获得的数据

时间:2014-03-02 09:01:15

标签: java jpa

我有一个Presentation类:

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package entity;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Entity;
import javax.persistence.FetchType;

@Entity
@Table(name = "Presentation") 
public class Presentation implements Serializable
{
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int id;

    @Column(name = "start_time")
    private Timestamp startTime;

    @Column(name = "end_time")
    private Timestamp endTime;

    @ManyToOne(targetEntity = Location.class, fetch = FetchType.LAZY)
    private Location location;

    @ManyToMany
    private List<User> users;

    @ManyToMany(mappedBy = "presentations")
    private List<Planning> plannings;

    public int getId() {
        return id;
    }

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

    public Timestamp getEndTime() {
        return endTime;
    }

    public void setEndTime(Timestamp endTime) {
        this.endTime = endTime;
    }

    public Location getLocation() {
        return location;
    }

    public void setLocation(Location location) {
        this.location = location;
    }

    public List<User> getUsers() {
        return users;
    }

    public void setUsers(List<User> users) {
        this.users = users;
    }

    public List<Planning> getPlannings() {
        return plannings;
    }

    public void setPlannings(List<Planning> plannings) {
        this.plannings = plannings;
    }

    public Timestamp getStartTime() {
        return startTime;
    }

    public void setStartTime(Timestamp startTime) {
        this.startTime = startTime;
    }
}

现在我可以使用以下查询获取这些内容:

Query q = session.createQuery("SELECT p FROM " + Presentation.class.getSimpleName() + " p");

获取清单。

现在我需要将一些东西传递给我用于在时间轴上显示演示文稿的库。我想以某种方式直接编辑这个结构,我拿它来匹配库api。

public PresentationModified(JaretDate date, int h, int m, double durH, String text) {
    JaretDate begin = date.copy().setTime(h, m, 0);
    setRealBegin(begin);

    JaretDate end = begin.copy().advanceHours(durH);
    setRealEnd(end);

    _text = text;
    checkSpanMultiple();
    changed();
}

我找不到一个好方法来获取查询并直接创建相应的对象。

0 个答案:

没有答案