0

I have a big problem using datastax java-driver-mapping within karaf 4.1.0-SNAPSHOT, I need to get the annotation @Table from cassandra entity in this case:

@Table(name = "clients")
public class Client implements Serializable {

    @PartitionKey
    @Column(name = "client_id")
    private String clientId;
    @Column(name = "client_secret")
    private String clientSecret;

    //getters and setters ...
}

This entity is in a models bundle, I have a bundle for services and one to persistence, when I try to do this in my persistence bundle:

@Override
public void save(Serializable obj, Class clazz) {
    System.out.println(((Table)clazz.getAnnotations()[0]).name());
}

I get this error in the line of System.out.println:

java.lang.ClassCastException: com.sun.proxy.$Proxy110 cannot be cast to com.datastax.driver.mapping.annotations.Table
    at io.twim.cassandra.TwimCassandraImpl.save(TwimCassandraImpl.java:159) [216:twim-cassandra:1.0.0.SNAPSHOT]
    at Proxyc0a03eb5_6454_4ea2_a12f_daddf586d502.save(Unknown Source) [?:?]
    at io.twim.core.users.TwimServiceUserImpl.saveApplicationClient(TwimServiceUserImpl.java:50) [218:twim-core:1.0.0.SNAPSHOT]
    at Proxy60a7b95f_6d2d_4487_bd18_dfd7c359a958.saveApplicationClient(Unknown Source) [?:?]
    at io.twim.rest.register.ClientRegistrationImpl.init(ClientRegistrationImpl.java:69) [223:twim-rest:1.0.0.SNAPSHOT]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
    at java.lang.reflect.Method.invoke(Method.java:497) ~[?:?]
    at org.apache.aries.blueprint.utils.ReflectionUtils.invoke(ReflectionUtils.java:299) [12:org.apache.aries.blueprint.core:1.7.0]

What should I do to fix this problem? Anyone have any idea?

EDITED

Debug

christmo
  • 351
  • 2
  • 18

1 Answers1

0

In java any annotation is represented as a Proxy at runtime. So you can sometimes hit this problem.

You can try to use clazz.getAnnotation(Table.class).name instead.

Christian Schneider
  • 19,420
  • 2
  • 39
  • 64
  • I added a image from debugger, your advice gets a null value, but if I get the annotations method it shows an annotation of type Proxy, What do you think about it? – christmo Oct 06 '16 at 16:51