This is what I ended up with. with help from elsewhere
Thank you labatymo for help. Tell me what is a fair payment.
package jpablob;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
/*
* CREATE TABLE picture (id INTEGER NOT NULL, image BLOB, PRIMARY KEY(id));
*/
@Entity
@Table(name="picture")
public class Picture {
private int id;
private byte[] image;
@Id
@Column(name="id")
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@Column(name="image")
public byte[] getImage() {
return image;
}
public void setImage(byte[] image) {
this.image = image;
}
}
<persistence xmlns="http://java.sun.com/ (...)
xmlns:xsi="http://www.w3.org/ (...)
xsi:schemaLocation="http://java.sun.com/ (...)
http://java.sun.com/ (...)
version="2.0">
<persistence-unit name="test">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>jpablob.Picture</class>
<exclude-unlisted-classes/>
<properties>
<!--<property name="show_sql">true</property>-->
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
<property name="hibernate.connection.url" value="jdbc:mysql://localhost/Test"/>
<property name="hibernate.connection.username" value=""/>
<property name="hibernate.connection.password" value=""/>
<property name="hibernate.connection.pool_size" value="5"/>
</properties>
</persistence-unit>
</persistence>
package jpablob;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
public class TestSave {
public static void main(String[] args) {
EntityManagerFactory factory = Persistence.createEntityManagerFactory("test");
EntityManager em = factory.createEntityManager();
Picture p = new Picture();
p.setId(1);
p.setImage(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
em.getTransaction().begin();
em.persist(p);
em.getTransaction().commit();
em.close();
}
}
package jpablob;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
public class TestLoad {
public static void main(String[] args) {
EntityManagerFactory factory = Persistence.createEntityManagerFactory("test");
EntityManager em = factory.createEntityManager();
Picture p = em.find(Picture.class, 1);
em.close();
System.out.println(p.getId());
for(byte b : p.getImage()) {
System.out.print(" " + b);
}
System.out.println();
}
}