Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Need help with Derby JAVA_OBJECT and JPA(Does eclipselink have support for Derby JAVA_OBJECT?)
Need help with Derby JAVA_OBJECT and JPA [message #648309] Wed, 12 January 2011 11:29 Go to next message
Mike  is currently offline Mike Friend
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 Sad

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 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

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
Re: Need help with Derby JAVA_OBJECT and JPA [message #648871 is a reply to message #648580] Fri, 14 January 2011 19:08 Go to previous message
Mike  is currently offline Mike Friend
Messages: 4
Registered: January 2011
Junior Member
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.
Previous Topic:EclipseLink-7198, Class was not found while converting from class names to classes
Next Topic:Does EclipseLink support OracleXADataSource?
Goto Forum:
  


Current Time: Fri Mar 29 00:13:32 GMT 2024

Powered by FUDForum. Page generated in 0.04547 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top