Datastax java driver 3.0.0 Enumerated annotation not found

。_饼干妹妹 提交于 2019-12-22 10:59:12

问题


Hope I am reading the docs well: http://docs.datastax.com/en/developer/java-driver/3.0/java-driver/reference/crudOperations.html.

The Enumerated annotation

If your class contains an enum type field, you use the Enumerated annotation.

I have a Java enum and I want to use the @Enumerated annotation, but I can't seem to find it in 3.0.0 version of the driver, it was present in 2.1.9.

$ find . -type f -name \*.jar|while read i; do echo ====== $i =====; jar -tf $i|grep Enumerated; done
====== ./cassandra-driver-core/2.1.4/cassandra-driver-core-2.1.4-javadoc.jar =====
====== ./cassandra-driver-core/2.1.4/cassandra-driver-core-2.1.4-sources.jar =====
====== ./cassandra-driver-core/2.1.4/cassandra-driver-core-2.1.4.jar =====
====== ./cassandra-driver-core/2.1.5/cassandra-driver-core-2.1.5.jar =====
====== ./cassandra-driver-core/2.1.7.1/cassandra-driver-core-2.1.7.1.jar =====
====== ./cassandra-driver-core/2.1.9/cassandra-driver-core-2.1.9.jar =====
====== ./cassandra-driver-core/3.0.0/cassandra-driver-core-3.0.0-sources.jar =====
====== ./cassandra-driver-core/3.0.0/cassandra-driver-core-3.0.0.jar =====
====== ./cassandra-driver-dse/2.1.5/cassandra-driver-dse-2.1.5.jar =====
====== ./cassandra-driver-extras/3.0.0/cassandra-driver-extras-3.0.0.jar =====
====== ./cassandra-driver-mapping/2.1.4/cassandra-driver-mapping-2.1.4-javadoc.jar =====
com/datastax/driver/mapping/annotations/class-use/Enumerated.html
com/datastax/driver/mapping/annotations/Enumerated.html
====== ./cassandra-driver-mapping/2.1.4/cassandra-driver-mapping-2.1.4-sources.jar =====
com/datastax/driver/mapping/annotations/Enumerated.java
====== ./cassandra-driver-mapping/2.1.4/cassandra-driver-mapping-2.1.4.jar =====
com/datastax/driver/mapping/annotations/Enumerated.class
====== ./cassandra-driver-mapping/2.1.7.1/cassandra-driver-mapping-2.1.7.1.jar =====
com/datastax/driver/mapping/annotations/Enumerated.class
====== ./cassandra-driver-mapping/2.1.9/cassandra-driver-mapping-2.1.9.jar =====
com/datastax/driver/mapping/annotations/Enumerated.class
====== ./cassandra-driver-mapping/3.0.0/cassandra-driver-mapping-3.0.0-sources.jar =====
====== ./cassandra-driver-mapping/3.0.0/cassandra-driver-mapping-3.0.0.jar =====

Has this changed in the new release? If yes, the docs should probably be updated too.

It does seem to be gone from the sources: https://github.com/datastax/java-driver/tree/3.0/driver-mapping/src/main/java/com/datastax/driver/mapping/annotations


回答1:


It looks like support for @Enumerated has been removed. Now, enums support is provided by the codecs in drivers-extras. Check out these two tickets for addtional info: JAVA-605 and JAVA-846.

An example of what your enums code might look like is:

[Use] EnumOrdinalCodec and EnumNameCodec:

 java    
 enum Foo {...}
 enum Bar {...}

 // register the appropriate codecs
 CodecRegistry.DEFAULT_INSTANCE
     .register(new EnumOrdinalCodec<Foo>(Foo.class))
     .register(new EnumNameCodec<Bar>(Bar.class))

 // the following mappings are handled out-of-the-box
 @Table
 public class MyPojo {
     private Foo foo;
     private List<Bar> bars;
     ...
 }

We are in the process of fixing the documentation.



来源:https://stackoverflow.com/questions/35132643/datastax-java-driver-3-0-0-enumerated-annotation-not-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!