Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NPE with generated value #292

Closed
bejayoharen opened this issue Jun 11, 2013 · 16 comments
Closed

NPE with generated value #292

bejayoharen opened this issue Jun 11, 2013 · 16 comments
Milestone

Comments

@bejayoharen
Copy link

I am porting some code and am getting this exception:

Caused by: java.lang.NullPointerException
at com.impetus.kundera.configure.MetamodelConfiguration.processGeneratedValueAnnotation(MetamodelConfiguration.java:452)
at com.impetus.kundera.configure.MetamodelConfiguration.scanClassAndPutMetadata(MetamodelConfiguration.java:370)
at com.impetus.kundera.configure.MetamodelConfiguration.loadEntityMetadata(MetamodelConfiguration.java:227)
at com.impetus.kundera.configure.MetamodelConfiguration.configure(MetamodelConfiguration.java:107)
at com.impetus.kundera.configure.Configurator.configure(Configurator.java:65)
at com.impetus.kundera.KunderaPersistence.initializeKundera(KunderaPersistence.java:109)
at com.impetus.kundera.KunderaPersistence.createEntityManagerFactory(KunderaPersistence.java:81)
at javax.persistence.Persistence.createEntityManagerFactory(Unknown Source)
at javax.persistence.Persistence.createEntityManagerFactory(Unknown Source)
at com.xonami.rest.db.EMFactory.(EMFactory.java:19)
... 61 more

I assuming this has something to do with the @GeneratedValue annotations, but I can't figure out what. I am using mongodb. My annotations look like this:

@Id
@Column
@GeneratedValue(strategy = GenerationType.AUTO)
private String key;

Some of them are annotated with @column, some are not.

@mevivs
Copy link
Collaborator

mevivs commented Jun 11, 2013

Hi,
Do you need primary key to be auto generated using @GeneratedValue?

-Vivek

@mevivs
Copy link
Collaborator

mevivs commented Jun 11, 2013

@bejayoharen
Copy link
Author

The original code uses it (@GeneratedValues). I'd like to map the original code as closely as possible before changing things, so yes, I need autogenerated primary keys.

@bejayoharen
Copy link
Author

That link uses ObjectIds, which are familiar from mongo. It also uses @TableGenerator. The docs here:

https://github.com/impetus-opensource/Kundera/wiki/Primary-Key-Auto-generation

use Strings and no mention of @TableGenerator. I Followed the docs. What do I need to change?

If my usage is not correct:

  • the docs should be updated, and
  • A correct error message should be displayed rather than a NPE.

@mevivs
Copy link
Collaborator

mevivs commented Jun 11, 2013

Did you try referrring to:
https://github.com/impetus-opensource/Kundera/tree/trunk/kundera-mongo/src/test/java/com/impetus/client/generatedId

for more on usage of @GeneratedValue over MongoDB.

If yes, and still getting error, please share your code snippet link

-Vivek

@ghost ghost assigned kkmishra Jun 11, 2013
@mevivs
Copy link
Collaborator

mevivs commented Jun 11, 2013

KK,
Please look into this.

-Vivek

@bejayoharen
Copy link
Author

"Did you try referrring to:" Yes. As I said, it is different from the docs:

  • The Docs use the String type for generated ids, whereas the code you linked to uses ObjectIds.
  • The Docs make no mention of @TableGenerator, whereas the code you linked to uses it.

Do I need to change both things, or just the type? I have 19 generated values in my code, so it's a fair bit of code to go over and I'd like to just change the type if that's all I need to change. Moreover:

  • Your docs are wrong.
  • This should not cause a NPE. it should display a useful error message.

@mevivs
Copy link
Collaborator

mevivs commented Jun 11, 2013

As per
https://github.com/impetus-opensource/Kundera/wiki/Primary-Key-Auto-generation:

Table generation strategy is only applicable to "Cassandra" and "HBase".

The Docs use the String type for generated ids, whereas the code you linked to uses ObjectIds.

In case, you want _id field in mongodb to be of type ObjectId, then only you need to declare it as "ObjectId" in your entities. If you define them as "String" type, by default _id field in mongodb will persisted as auto generated "ObjectId.toString()", method

Your docs are wrong.

I will get them updated for above mentioned information, Thanks for pointing it out.

This should not cause a NPE. it should display a useful error message.

It should not be thrown and a proper message should have been displayed. I will verify it.

Thanks,
-Vivek

@mevivs
Copy link
Collaborator

mevivs commented Jun 11, 2013

Version of Kundera referring to? Is it 2.5 or 2.5.1?

-Vivek

@bejayoharen
Copy link
Author

  • I am using 2.5. I'll try 2.5.1 and will report if it's different.
  • I have changed all instances of String to ObjectId and error remains. I cannot share the code, but if I can't get past this I'll try to reproduce on a smaller example, if I can.

@mevivs
Copy link
Collaborator

mevivs commented Jun 11, 2013

For:

This should not cause a NPE. it should display a useful error message.

Did you specify Entity with @table annotation, as for example:

@Table(name = "PERSON", schema = "keyspace@mongo_pu")

To map it correctly with MongoDB, you need to add this over Entity definition.

-Vivek

@bejayoharen
Copy link
Author

Yes, I did that. IIRC, I also got a different mysterious error until I added that.

It is possible I'm using some other unsupported annotations.

@mevivs
Copy link
Collaborator

mevivs commented Jun 11, 2013

Ok. Let me know, if you can carve out a sample example to verify and look into the issue.

-Vivek

@bejayoharen
Copy link
Author

Is @MappedSuperclass supported?

@mevivs
Copy link
Collaborator

mevivs commented Jun 11, 2013

Not yet.
#56

@bejayoharen
Copy link
Author

Thanks. That may be my issue. I can't tell with current error messages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants