jpaのblobタイプのサポート、エラー

3850 ワード

これはエンティティです.
@Entity
@Table(name="Person3")
public class Person3 implements Serializable {

	public enum Level{LEVEL1,LEVEL2,LEVEL3};
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Long id;

	@Column(name="username",unique=true,nullable=false)
	private String name;
	private int age;
	private double salary;
	[color=red]@Lob
	private byte[] image;[/color]
	@Temporal(TemporalType.DATE)
	private Date birthday;
	@Column(name="isMarried",columnDefinition="tinyint(1)")
	private boolean isMarried;
	@Enumerated(EnumType.STRING)
	private Level level;
	
	public String getName() {
		return name;
	}

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

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	public double getSalary() {
		return salary;
	}

	public void setSalary(double salary) {
		this.salary = salary;
	}

	public byte[] getImage() {
		return image;
	}

	public void setImage(byte[] image) {
		this.image = image;
	}

	public Date getBirthday() {
		return birthday;
	}

	public void setBirthday(Date birthday) {
		this.birthday = birthday;
	}

	public boolean isMarried() {
		return isMarried;
	}

	public void setMarried(boolean isMarried) {
		this.isMarried = isMarried;
	}

	public Level getLevel() {
		return level;
	}

	public void setLevel(Level level) {
		this.level = level;
	}

	public Person3() {
	}

	public Long getId() {
		return this.id;
	}

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

	public int hashCode() {
		return (this.id == null) ? 0 : this.id.hashCode();
	}

	public boolean equals(Object object) {
		if (object instanceof Person3) {
			final Person3 obj = (Person3) object;
			return (this.id != null) ? this.id.equals(obj.id)
					: (obj.id == null);
		}
		return false;
	}

}

これはテストクラスです.
private static void main() throws Exception {
		Context ctx = new InitialContext();
		PersonManageBeanRemote pmb = (PersonManageBeanRemote) ctx.lookup("PersonManageBean/remote");
		Person3 p = new Person3();
		p.setName("lili");
		p.setAge(23);
		p.setMarried(true);
		p.setLevel(Person3.Level.LEVEL1);
		p.setSalary(2000.0);
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		try {
			p.setBirthday(sdf.parse("1980-08-08"));
		} catch (ParseException e) {
			e.printStackTrace();
		}
                  // 
		InputStream is = Test.class.getClassLoader().getResourceAsStream("holly-11-10c.gif");
		byte[] buf=new byte[is.available()];
		is.read(buf);
		System.out.println("
===="+buf.length); is.close(); p.setImage(buf); pmb.save(p); Person3 p2 = pmb.findPerson("lili"); System.out.println(p2.getSalary()+"=="+p2.getBirthday()); byte[] image = p2.getImage(); System.out.println("
----"+image.length); // FileOutputStream fos2 = new FileOutputStream("temp2.gif"); fos2.write(image); fos2.close(); }

皆さん:最後に出てきた画像が間違っていて、表示されているのは元のものと違って、元のバイト数より8つ多いです.
印刷結果:
====1473
2000.0==1980-08-08
----1481
どうしたの?