Need help with Derby JAVA_OBJECT and JPA [message #648309] |
Wed, 12 January 2011 06:29  |
Eclipse User |
|
|
|
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 06:31] by Moderator
|
|
|
|
Re: Need help with Derby JAVA_OBJECT and JPA [message #648871 is a reply to message #648580] |
Fri, 14 January 2011 14:08  |
Eclipse User |
|
|
|
Thanks for the help. Both approaches worked (more or less).
I never know what type the ultimate value will be. So, I wanted to go with the JAVA_OBJECT column type and let the database do what it felt was best.
However, when the Object ends up being a long, eclipselink seems to pass long, instead of the Long returned by my Converter. This again causes the operation to fail.
Setting the column type to BLOB and using the @Lob tag works fine. Not sure what kind of space waste this will result in. But, I don't anticipate having very many rows. It's enough to at least allow me to continue making forward progress.
Thanks again.
|
|
|
Powered by
FUDForum. Page generated in 0.07737 seconds