Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » The attribute type must implement the Serializable interface.
The attribute type must implement the Serializable interface. [message #676165] Fri, 03 June 2011 00:42 Go to next message
Hugo Herrera is currently offline Hugo Herrera
Messages: 20
Registered: July 2009
Junior Member
Hola,

i moved from Galileo to Helios and from JPA 1.1 to 2.2 and now when running my app i'm receiving following error:

Caused by: Exception [EclipseLink-7155] (Eclipse Persistence Services - 2.2.0.v20110202-r8913): org.eclipse.persistence.exceptions.ValidationException
Exception Description: The type [class inventory.entity.Item] for the attribute [item] on the entity class [class sale.entity.ItemSold] is not a valid type for a serialized mapping. The attribute type must implement the Serializable interface.


On my previous environment was running with no problems.

can you pls help?

Here are my classes:

@Entity
public class ItemSold extends ModelObject implements Serializable {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -2793958653008272733L;
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	private Integer id;
	private Integer quantity;
	@Column(precision=6,scale=2)
	private BigDecimal price;
	@Column(precision=6,scale=2)
	private BigDecimal discount;
	private Item item;
	@ManyToOne
	private Sale sale;
	
	public ItemSold() {
	}
        ...
}


and

@Entity
public class Item extends ModelObject implements Serializable {
		
	/**
	 * 
	 */
	private static final long serialVersionUID = -7789306711121155171L;
	@Id
	@GeneratedValue(generator="ItemTab")
	@TableGenerator(name="ItemTab",table="SEQUENCE",
			pkColumnName="SEQ_NAME",valueColumnName="SEQ_COUNT",
			pkColumnValue="ITEM_GEN",allocationSize=1)
	private Integer id;
	private String code;
	private String key;
	private String description;
	private Preferences brand;
	private Preferences category;
	@Column(precision=6,scale=2)
	private BigDecimal buyPrice=BigDecimal.valueOf(0);
	@Column(precision=6,scale=2)
	private BigDecimal previousBuyPrice=BigDecimal.valueOf(0);
	@Column(precision=6,scale=2)
	private BigDecimal salePrice=BigDecimal.valueOf(0);
	@Column(precision=6,scale=2)
	private BigDecimal minimumSalePrice=BigDecimal.valueOf(0);
	private Integer stock=0;
	private Integer threshold=0;
	private Integer sold=0;
	private Integer bought=0;
	@ManyToMany(cascade=CascadeType.PERSIST,fetch=FetchType.EAGER,targetEntity=inventory.entity.Year.class)
	private List<Year> years;

       ...
}
Re: The attribute type must implement the Serializable interface. [message #676839 is a reply to message #676165] Mon, 06 June 2011 13:25 Go to previous messageGo to next message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

For some reason the Item class is not known to be an Entity. Ensure you include a <class> tag for it in your persistence.xml, and that it is contained in the same jar file as your persistence.xml.

What environment are you using? (JSE, Glassfish, WebLogic, OSGi, etc.)


James : Wiki : Book : Blog : Twitter
Re: The attribute type must implement the Serializable interface. [message #965933 is a reply to message #676165] Wed, 31 October 2012 12:19 Go to previous messageGo to next message
helmi bouzrara is currently offline helmi bouzrara
Messages: 1
Registered: October 2012
Junior Member
The type [class java.awt.Image] for the attribute [photo] on the entity class [class ejb.immobika.persistence.Annonces] is not a valid type for a serialized mapping. The attribute type must implement the Serializable interface


package ejb.immobika.persistence;



import java.awt.Image;
import java.io.Serializable;



import javax.persistence.Entity;

import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;


@Entity
public class Annonces implements Serializable{

private static final long serialVersionUID = 1L;
private int idAnnonce;

private Image photo;
private Biens bien;



public Annonces() {


super();

}



@Id
public int getIdAnnonce() {
return idAnnonce;
}




public void setIdAnnonce(int idAnnonce) {
this.idAnnonce = idAnnonce;
}











@OneToOne
@JoinColumn(name="BIENS_ID",referencedColumnName="idBiens")
public Biens getBien() {
return bien;
}



public void setBien(Biens bien) {
this.bien = bien;
}



public Image getPhoto() {
return photo;
}



public void setPhoto(Image photo) {
this.photo = photo;
}




}
Re: The attribute type must implement the Serializable interface. [message #966209 is a reply to message #965933] Wed, 31 October 2012 17:06 Go to previous message
Chris Delahunt is currently offline Chris Delahunt
Messages: 1016
Registered: July 2009
Senior Member
The exception in this case states the problem - the java.awt.Image type is not an entity and is not serializable, so JPA has no idea how to put this object in a database for you. Are you trying to map this to a blob database type? I'm not familiar with the java.awt .Image type but suspect you'll need to use a converter to convert Image instances to/from a byte array. See http://eclipse.org/eclipselink/documentation/2.4/jpa/extensions/a_converter.htm#CHDEHJEB

Best regards
Chris
Previous Topic:EntityManager.find(...) with pessimistic lock never throws LockTimeoutException
Next Topic:JPA Project with EclipseLink 2.4.1 Error-Msg
Goto Forum:
  


Current Time: Sat Jul 26 09:19:36 EDT 2014

Powered by FUDForum. Page generated in 0.02286 seconds