Mapping For Composite Primary Key

20 views
Skip to first unread message

Tom Gregory

unread,
Jun 19, 2020, 1:33:13 PM6/19/20
to mongo-jackson-mapper
I am trying to create an object with a composite primary key.  There doesn't seem to be any examples on how to do it and I keep getting an Illegal argument exception.

public class LogPK {
  private ObjectId logId;
  private Date logDate;
}

public class logEntry {
  @Id
  private LogPK id;
  private String note;
}

I can do this in Spring Data, but it doesn't work with MongoJack.  I get:

java.lang.IllegalArgumentException: Unsupported ID type: class .....

Can someone please point me in the right direction.  Composite keys are pretty standard in Mongo and I'm surprised I'm having such a difficult time with this.

Thanks for your help.

Tom Gregory

unread,
Jun 19, 2020, 1:41:17 PM6/19/20
to mongo-jackson-mapper
It appears as though the item is getting created, but I'm guessing it is trying to update the value of the key and that is why it is throwing an exception.  Not sure.  Regardless, this should work, No?

James Roper

unread,
Jun 22, 2020, 2:18:01 AM6/22/20
to mongo-jack...@googlegroups.com
I don't think I ever implemented support for that - I'm not sure if I was even aware MongoDB supported objects as keys. I don't see why it couldn't be supported, it'd probably make some aspects of the code a lot simpler, we'd just have to workout what serializer/deserializer Jackson had decided to use for the id field, and then cache and use that everywhere.

--
You received this message because you are subscribed to the Google Groups "mongo-jackson-mapper" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongo-jackson-ma...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongo-jackson-mapper/3ac3c263-128d-4aa9-8314-efef829c55a5o%40googlegroups.com.

Tom Gregory

unread,
Jun 23, 2020, 2:32:45 PM6/23/20
to mongo-jackson-mapper
Hey James, thanks for the follow-up.  Yes, composite primary keys are used extensively by us in mongo.  If you look at how Spring Data for Mongo supports them, you'll see a model for how it might be implemented in MongoJack.  For the moment, I'm just using the Mongo API directly to deal with the composite keys, but would be great if MongoJack would support it.
To unsubscribe from this group and stop receiving emails from it, send an email to mongo-jackson-mapper+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages