Declaring a @ElementCollection on a List<String> causes strange error #209

Closed
jmcollin78 opened this Issue Mar 13, 2013 · 8 comments

4 participants

@jmcollin78

Hello,

This piece of code in a @Entity leads to strange error:
@ElementCollection(fetch=FetchType.LAZY)
@Column(name="directSubTagIds")
private List directSubTagIds = new ArrayList<>();

The error generated is the following :
java.lang.IllegalArgumentException: attribute of the given name and type is not present in the managed type, for name:serialVersionUID
at com.impetus.kundera.metadata.model.type.AbstractManagedType.checkForValid(AbstractManagedType.java:955)
at com.impetus.kundera.metadata.model.type.AbstractManagedType.getAttribute(AbstractManagedType.java:470)
at com.impetus.client.mongodb.utils.MongoDBUtils.getCompoundKeyColumns(MongoDBUtils.java:53)
at com.impetus.client.mongodb.utils.MongoDBUtils.populateCompoundKey(MongoDBUtils.java:34)
at com.impetus.client.mongodb.MongoDBDataHandler.getDocumentFromEntity(MongoDBDataHandler.java:312)
at com.impetus.client.mongodb.MongoDBClient.onPersist(MongoDBClient.java:645)
at com.impetus.client.mongodb.MongoDBClient.onPersist(MongoDBClient.java:520)
at com.impetus.kundera.client.ClientBase.persist(ClientBase.java:86)
at com.impetus.kundera.lifecycle.states.ManagedState.handleFlush(ManagedState.java:183)
at com.impetus.kundera.graph.Node.flush(Node.java:525)
at com.impetus.kundera.persistence.DefaultTransactionResource.onFlush(DefaultTransactionResource.java:89)
at com.impetus.kundera.persistence.DefaultTransactionResource.onCommit(DefaultTransactionResource.java:75)
at com.impetus.kundera.persistence.Coordinator.coordinate(Coordinator.java:79)
at com.impetus.kundera.persistence.KunderaEntityTransaction.onTransaction(KunderaEntityTransaction.java:127)
at com.impetus.kundera.persistence.KunderaEntityTransaction.commit(KunderaEntityTransaction.java:77)
at clouderial.saas.commons.jpamongo.JPAMongoPersistenceContext.commitTransaction(JPAMongoPersistenceContext.java:81)

What happends is that the declaration of the @ElementCollection puts the class String in the MetamodelImpl.embeddables. So each id (String) is converted to DBObject using 'MongoDBUtils.populateCompoundKey(dbObj, m, metaModel, id);' instead of using 'dbObj.put("_id", MongoDBUtils.populateValue(id, id.getClass()));'.
This is done in MongoDBDataHandler.getDocumentFromEntity :
if (metaModel.isEmbeddable(m.getIdAttribute().getBindableJavaType()))
{
MongoDBUtils.populateCompoundKey(dbObj, m, metaModel, id);
}
else
{
dbObj.put("_id", MongoDBUtils.populateValue(id, id.getClass()));
}

To my opininon, you should never put String into MetamodelImpl.embeddables, and maybe a clear error message would be helpfull (or supports the @ElementCollection on List).
How to have a Lazy List without @ElementCollection ?

Thanks in advance for your advice

@mevivs
Collaborator

We are working on @Elementcollection annotation, trying to fit it properly as per JPA. As per current implementation it will create a sub document for each such element in list.

As per error, Can you make SerialVersionUID as static variable and try?

if (metaModel.isEmbeddable(m.getIdAttribute().getBindableJavaType()))
{
MongoDBUtils.populateCompoundKey(dbObj, m, metaModel, id);
}
else
{
dbObj.put("_id", MongoDBUtils.populateValue(id, id.getClass()));
}

Not sure what you are discussing about above code snippet. But this one is related to handling of Composite key support in mongodb( if block).

-Vivek

@jmcollin78
@xamry

Can we close this one?

@jmcollin78
@mevivs
Collaborator

Releasing with 2.5

-Vivek

@ceineke

I'm using kundera 2.5's cassandra layer and I'm annotating an entity that has a Set attribute as follows:

    @ElementCollection(targetClass=String.class)
    private Set<String> values;

This causes java.lang.String to become a default embeddable type and find-queries against any entity with a String @Id y generated with this where clause:

    WHERE value=[C@... and hash=0

This bug has not been fixed.

Edit: The behaviour is the same if I remove the targetClass parameter from the annotation.

@mevivs
Collaborator

@ElementCollection in Cassandra will work for embeddable entities. Any entity annotated with @ElementCollection or @Embedded will be considered as a super column family in Cassandra.

-Vivek

@mevivs
Collaborator

@ElementCollection over basic type: Support added for Cassandra,Mongo

@mevivs mevivs closed this Aug 7, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment