BLOBS and EJB3

J

Java and Swing

Anyone know how I would store a BLOB using EJB3? for example if i want
to store a file.

thanks
 
D

Danno

My gift to you.

package com.mycompany.data;

import java.util.Date;
import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.Table;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;

@Entity(name="Resource")
@Table(name="ag_resource")
public class Resource implements Serializable {


private Long id;


private String notes;


private byte[] byteArray;


private Date createdDate;


private String description;


private Date updatedDate;


private String name;


private String mimeType;

public Resource() {
setCreatedDate(new Date());
setUpdatedDate(new Date());
}

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

@Id @GeneratedValue(strategy=GenerationType.AUTO)
public Long getId() {
return id;
}

public void setNotes(final String notes) {
this.notes = notes;
}

@Lob @Basic(fetch = FetchType.EAGER)
public String getNotes() {
return notes;
}

public void setByteArray(final byte[] byteArray) {
this.byteArray = byteArray;
}

@Lob @Basic(fetch = FetchType.EAGER)
public byte[] getByteArray() {
return byteArray;
}

public void setCreatedDate(final Date createdDate) {
this.createdDate = createdDate;
}

public Date getCreatedDate() {
return createdDate;
}

public void setDescription(final String description) {
this.description = description;
}

@Lob @Basic(fetch = FetchType.EAGER)
public String getDescription() {
return description;
}

public void setUpdatedDate(final Date updatedDate) {
this.updatedDate = updatedDate;
}

public Date getUpdatedDate() {
return updatedDate;
}

public void setName(final String name) {
this.name = name;
}

public String getName() {
return name;
}

public void setMimeType(final String mimeType) {
this.mimeType = mimeType;
}

public String getMimeType() {
return mimeType;
}

public String toString() {
return new ToStringBuilder(this)
.append("name", getName())
.append("mimeType", getMimeType())
.append("notes", getNotes())
.append("createdDate", getCreatedDate())
.append("description", getDescription())
.append("updatedDate", getUpdatedDate())
.toString();
}

public boolean equals(Object object) {
if (!(object instanceof Resource)) return false;
Resource resource = (Resource) object;
return new EqualsBuilder()
.append(this.getName(), resource.getName())
.append(this.getMimeType(), resource.getMimeType())
.append(this.getNotes(), resource.getNotes())
.append(this.getCreatedDate(), resource.getCreatedDate())
.append(this.getDescription(), resource.getDescription())
.append(this.getUpdatedDate(), resource.getUpdatedDate())
.isEquals();
}

public int hashCode() {
return new HashCodeBuilder()
.append(getName())
.append(getMimeType())
.append(getNotes())
.append(getCreatedDate())
.append(getDescription())
.append(getUpdatedDate())
.toHashCode();
}
}
 
Joined
Aug 17, 2006
Messages
1
Reaction score
0
I found it useful, but for a large LOB, what shall I do?


Regards;
Stephen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top