Re: The id class specified by type does not match the primary key fields of the class

2014-03-20 Thread Joe_DAMS
Hello Rick,
Ty for your answer.

I tried to update my entities like mentionned in your link (Not same
entities inside my first post but same problem):

Entity with embeddedId


Embeddable class


And persistence.xml


But always got this log message:


Are there any solutions to fix it ?
Ty ! (I'm copying this reply to SO)



--
View this message in context: 
http://openjpa.208410.n2.nabble.com/The-id-class-specified-by-type-does-not-match-the-primary-key-fields-of-the-class-tp7586109p7586114.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.


Re: The id class specified by type does not match the primary key fields of the class

2014-03-20 Thread Rick Curtis
Joe -

First off, the exception that I assume you meant to post isn't showing up?
Second, the patch I posted wasn't for you to modify your Entities. The
important part of that patch is a code fix to the OpenJPA runtime. I
believe this is an OpenJPA code bug and I wanted to get others to take a
look at it. I'll try to bug someone else to review the patch today.

Thanks,
Rick


On Thu, Mar 20, 2014 at 5:34 AM, Joe_DAMS orl...@kizux.fr wrote:

 Hello Rick,
 Ty for your answer.

 I tried to update my entities like mentionned in your link (Not same
 entities inside my first post but same problem):

 Entity with embeddedId


 Embeddable class


 And persistence.xml


 But always got this log message:


 Are there any solutions to fix it ?
 Ty ! (I'm copying this reply to SO)



 --
 View this message in context:
 http://openjpa.208410.n2.nabble.com/The-id-class-specified-by-type-does-not-match-the-primary-key-fields-of-the-class-tp7586109p7586114.html
 Sent from the OpenJPA Users mailing list archive at Nabble.com.




-- 
*Rick Curtis*


Re: The id class specified by type does not match the primary key fields of the class

2014-03-20 Thread Joe_DAMS
Rick,

Sorry, I failed my copy/paste, this is the whole exception:


In
http://openjpa.markmail.org/thread/bqjomb4mtqj66p2p#query:+page:1+mid:zcxl7qjlqfgv3iwi+state:results

The author said openjpa.jdbc.SynchronizeMappings=validate did the trick!
so I tried to change it in my persistence.xml file but without good results
:(

I also read : The fields of a compound ID class should be one of the
following types : any Java primitive type; any primitive wrapper type;
java.lang.String; java.util.Date;java.sql.Date. That why I tried to change
my entities but same problem.

Thanks for your help



--
View this message in context: 
http://openjpa.208410.n2.nabble.com/The-id-class-specified-by-type-does-not-match-the-primary-key-fields-of-the-class-tp7586109p7586116.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.


Re: Using a time UUID as a sequence

2014-03-20 Thread Rick Curtis
Todd -

Honestly, I don't have much experience in this area. If you are able to put
together a small unit test I'll try to take a look when I get some time.

Thanks,
Rick


On Wed, Mar 19, 2014 at 10:05 PM, Todd Nine t...@spidertracks.com wrote:

 Just to follow up my own email, my configuration in the persistence XML
 does work as expected.  However, I'm receiving this error.

 Caused by: org.apache.openjpa.lib.jdbc.ReportingSQLException: BLOB/TEXT
 column 'id' used in key specification without a key length {stmnt 992554479
 CREATE TABLE AlertAcknowlege (id BLOB NOT NULL, createTime DATETIME,
 imeiNumber VARCHAR(255), queuedDate DATETIME, statusCode INTEGER, DTYPE
 VARCHAR(255), PRIMARY KEY (id)) ENGINE = innodb} [code=1170, state=42000]
  at

 org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.wrap(LoggingConnectionDecorator.java:247)


 Here is my mapping class.

 **
  * The value handler for converting com.eaio.uuid.UUID objects to byte
 arrays.
  *
  *
  * @author Todd Nine
  */
 public class UUIDValueHandler extends ByteArrayValueHandler {

 @Override
 public Object toDataStoreValue(ValueMapping vm, Object val, JDBCStore
 store) {

 final byte[] data = UUIDSerializer.toBytes((com.eaio.uuid.UUID)
 val);

 return super.toDataStoreValue(vm, data, store);

 }


 @Override
 public Object toObjectValue(ValueMapping vm, Object val) {
 byte[] data = (byte[]) val;

 final UUID uuid = UUIDSerializer.fromBytes(data);

 return uuid;
 }

 @Override
 public Column[] map(ValueMapping vm, DBIdentifier name, ColumnIO io,
 boolean adapt) {

 Column col = new Column();
 col.setIdentifier(name);
 col.setJavaType(JavaSQLTypes.BYTES);
 //we should always be binary 16 for the uuid
 col.setType(Types.BINARY);
 col.setSize(UUIDSerializer.LENGTH);

 return new Column[]{ col };
 }


 }

 As you can see on the type, I'm definitely setting the type to binary, and
 the length to 16 for every UUID type I encounter.  Am I doing this
 incorrectly for the schema generation to work properly?

 Thanks,
 Todd


 On 19 March 2014 18:56, Todd Nine t...@spidertracks.com wrote:

  Thanks for the reply Rick.  That does the trick for one field, but this
  class is used heavily throughout the model.  If possible I'd like to
 create
  a custom field mapping, so that every time a UUID is encountered, this
  mapping happens automatically.I've created a custom field mapping.
 
  public class UUIDValueHandler extends ByteArrayValueHandler {
 
  @Override
  public Object toDataStoreValue(ValueMapping vm, Object val, JDBCStore
  store) {
 
  final byte[] data = UUIDSerializer.toBytes((com.eaio.uuid.UUID)
  val);
 
  return super.toDataStoreValue(vm, data, store);
 
  }
 
 
  @Override
  public Object toObjectValue(ValueMapping vm, Object val) {
  byte[] data = (byte[]) val;
 
  final UUID uuid = UUIDSerializer.fromBytes(data);
 
  return uuid;
  }
  }
 
  However, it's not clear to me how to configure this as a plugin via the
  JPA configuration.  I searched through the documentation, but I can't
 find
  any examples for how to do this.  I referenced this section.
 
 
 
 http://ci.apache.org/projects/openjpa/trunk/docbook/manual.html#ref_guide_mapping_custom_field_conf
 
  However when I navigate to the reference of section 4 it takes me to this
  section.
 
 
 
 http://ci.apache.org/projects/openjpa/trunk/docbook/manual.html#ref_guide_mapping_defaults
 
  Should I define a property as follows?
 
  property name=openjpa.jdbc.MappingDefaults
 
 value=FieldStrategies='com.eaio.uuid.UUID=com.spidertracks.aviator.dataaccess.jpa.mysql.UUIDValueHandler'/
 
 
 
  On 19 March 2014 08:56, Rick Curtis curti...@gmail.com wrote:
 
  Todd -
 
  Take a look at @Externalizer/@Factory in the user manual[1]. Below is a
  snippet of code where I have a String field in my Entity, but the
 backing
  column in the DB is an int. The Externalizer/Factory methods convert
  values
  from/to the database. Let me know how this goes.
 
  Thanks,
  Rick
 
  @Id
 
 
 
 @Externalizer(org.apache.openjpa.persistence.kernel.common.apps.RuntimeTest1.toDb)
 
 
 
 @Factory(org.apache.openjpa.persistence.kernel.common.apps.RuntimeTest1.fromDb)
  private String intField;
 
  public static int toDb(String val){
  return Integer.valueOf(val);
  }
 
  public static String fromDb(int val) {
  return String.valueOf(val);
  }
 
  [1]
 
 
 http://ci.apache.org/projects/openjpa/trunk/docbook/manual.html#ref_guide_pc_extern
 
 
  On Wed, Mar 19, 2014 at 12:10 AM, Todd Nine t...@spidertracks.com
  wrote:
 
   Hi all,
We're migrating from a Key/Value system to MySQL for some components
 of
   our system for easier administration and maintenance.  As part of this
   migration, we need to retain the time UUIDs that have been generated
 for
   primary keys.