开发者

Storing BLOB in Database Spring Hibernate Persistence

This is a problem iv encountered and tried most of the solutions that i have been offered so far and little seems to work , the problem making this harder to fix is for some reason the hibernate session wont print its details to the log providing me with very little in terms of error tracing. I want to upload a string of Json converted to a blob into the database . If anyone knows where i am going wrong or can provide and pointers this would be great as im struggling to solve this alone.

@Entity
@Table(name="workout")
public class Workout implements Serializable{


    private static Lo开发者_开发技巧gger logger = Logger.getLogger(Workout.class);


    @Id
    @Column(name="workout_id")
    private int workout_id;

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

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

    @Lob
    @Column(name="workout")
    Blob workout;

    public int getWorkout_id() {
        return workout_id;
    }

    public void setWorkout_id(int workout_id) {
        this.workout_id = workout_id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getAdded_date() {
        return added_date;
    }

    public void setAdded_date(String added_date) {
        this.added_date = added_date;
    }

    public Blob getWorkout() {
        return workout;
    }

    public void setWorkout(Blob workout) {
        this.workout = workout;
    }


    }

method from Service that trys to upload

public String uploadWorkout(String json){
    Workout w = new Workout();
    w.setUsername("cmac458");
    DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
    Date date = new Date();
    w.setAdded_date(date.toGMTString());
    w.setWorkout(getBLOBfromJSON(json));
    w.setWorkout_id(4);
    workoutDao.getSession().save(w);
    return "done";

    }

I am using the basic hibernatetemplate.save(entity) that works in other parts of my application.

Any help here is much appreciated. Thanks Chris


I use byte[] instead ob Blob type, and that works fine.

@Lob
@Column(nullable = false, length = 2097152)
private byte[] data;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜