views:

513

answers:

2

Hello,

We have a project that uses JPA/Hibernate on the server side, the mapped entity classes are in their own Library-Project and use Annotations to be mapped to the database. I want to use these classes in an Android-Project - is there any way to ignore the annotations within Android, to use these classes as standard POJOs?

+2  A: 

The compiler will not care as long as you have the jar with the JPA annotation classes in your classpath. And if a runtime instrumentation system (such as Hibernate) is not present, the annotations are just extra info that are there but not used. The only issue is insuring the inclusion of the JPA jar in your distribution.

And that might be a problem. I don't really want to bundle all the hibernate-JARs into the Android-Project.
dasmaze
If you can not bundle the required classes, then the only solution that I can think of is using a custom class loader that strips out the annotations from the bytecode. Its a non-trivial task but doable.
p.s. The bytecode transformation doesn't necessarily has to happen on load. The other option is to run a process over the server libs and sanitize them for android by generating a new set of classfiles.
+2  A: 

The actual JPA annotations are part of Java SE 6, not hibernate. So you don't need to have the Hibernate JAR to be able to use JPA annotated classes. All you need is the classes/interfaces declaring the annotations your are referencing, if you can afford it the full JPA api jar is about 50k.

Patrick Roumanoff