Need help with Derby JAVA_OBJECT and JPA [message #648309] |
Wed, 12 January 2011 11:29 |
Mike Messages: 4 Registered: January 2011 |
Junior Member |
|
|
Hi,
I'm really struggling to try and get eclipselink JPA to work with a JavaDB (a.k.a. Derby) JAVA_OBJECT column type. It keeps complaining about passing a byte[] to a JAVA_OBJECT.
Seems like eclipselink is doing the serialization and then trying to pass the resulting byte[] to Derby. But, Derby seems to be expecting a java.io.Serializable with which it will do it's own transformation.
Any idea how to get these two to play nice?
The Derby table looks something like this:
CREATE TYPE SERIALIZABLE EXTERNAL NAME 'java.io.Serializable' LANGUAGE JAVA;
CREATE TABLE PROPERTY_SETTING (
ACTIVITY_ID INTEGER NOT NULL CONSTRAINT PROPERTY_SETTING_ACTIVITY_FK REFERENCES ACTIVITY(ID),
PROPERTY_ID INTEGER NOT NULL CONSTRAINT PROPERTY_SETTING_PROPERTY_FK REFERENCES PROPERTY(ID),
SETTING SERIALIZABLE,
PRIMARY KEY (ACTIVITY_ID, PROPERTY_ID));
The Java source looks something like this:
@Entity
@Table(name = "PROPERTY_SETTING")
public class JpaPropertySetting implements Serializable {
private static final long serialVersionUID = 1L;
@EmbeddedId
protected JpaPropertySettingPK jpaPropertySettingPK;
@Column(name = "SETTING")
private Serializable setting;
@JoinColumn(name = "PROPERTY_ID", referencedColumnName = "ID", insertable = false, updatable = false)
@ManyToOne(optional = false)
private JpaProperty jpaProperty;
@JoinColumn(name = "ACTIVITY_ID", referencedColumnName = "ID", insertable = false, updatable = false)
@ManyToOne(optional = false)
private JpaActivity jpaActivity;
Trying to commit a transaction via the EntityManager results in an exception as follows:
"Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.0.2.v20100323-r6872): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: An attempt was made to put a data value of type 'byte[]' into a data value of type 'JAVA_OBJECT'.
Error Code: 20000
Call: INSERT IGNORE INTO PROPERTY_SETTING (SETTING, ACTIVITY_ID, PROPERTY_ID) VALUES (?, ?, ?)
bind => [[B@f3436a, 32, 19]
Query: InsertObjectQuery(com.afltools.grid.extension.jpa.JpaPropertySetting[jpaPropertySettingPK=com.afltools.grid.extension.jpa.JpaPropertySettingPK[activityId=32, propertyId=19]])"
Any suggestions would be greatly appreciated
Thanks.
[Updated on: Wed, 12 January 2011 11:31] Report message to a moderator
|
|
|
Re: Need help with Derby JAVA_OBJECT and JPA [message #648580 is a reply to message #648309] |
Thu, 13 January 2011 15:08 |
|
The default converter for JPA on a none basic type is to Serialize it.
You can avoid this but adding your own Converter for the type using @Converter/@Convert.
Your converter would be pretty simple, just doing nothing in its conversion methods.
You could also just store the object into a BLOB or binary column type.
James : Wiki : Book : Blog : Twitter
|
|
|
|
Powered by
FUDForum. Page generated in 0.04547 seconds