Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package test;
- import java.io.*;
- import javax.persistence.*;
- @Entity
- public class XXXEntity {
- @Id private Long id;
- @Transient private Object entity;
- @Lob private byte[] binEntity;
- public Object getEntity() {
- try {
- return this.entity!=null ? this.entity : (this.entity = new ObjectInputStream(new ByteArrayInputStream(this.binEntity)).readObject());
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
- public void setEntity(Object entity) {
- this.entity = entity;
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- try {
- final ObjectOutputStream oos = new ObjectOutputStream(baos);
- oos.writeObject(entity);
- oos.close();
- this.binEntity = baos.toByteArray();
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement