ahmetb / orman

lightweight and minimalist ORM for Java/Android. works with SQLite & MySQL. (not actively maintained)
Other
249 stars 47 forks source link

problem mapping entities on android project #27

Open beirigo opened 13 years ago

beirigo commented 13 years ago

I don't know if this is the right place for this... I'm trying to create a simple android project using orman but can't get my entities mapped. I have all my entities under the "br.com.jera.shoplist.model" package and when i try to start the session i get this error:

org.orman.mapper.exception.AnnotatedClassNotFoundInPackageException: Could not find any entity marked class in "br.com.jera.shoplist.model"

Before anybody asks, all my entities have the @Entity annotation. I'm using this in my activty to start the session:

//database
Database db = new SQLiteAndroid(getApplicationContext(), "shoplist.db");
MappingSession.getConfiguration().setCreationPolicy(SchemaCreationPolicy.CREATE);
MappingSession.registerPackage("br.com.jera.shoplist.model");
MappingSession.registerDatabase(db);
MappingSession.start();

Any idea? am I missing something?

ahmetb commented 13 years ago

I'm not sure what's going on right now. There may be several problems regarding this issue, let's work on it:

  1. Your package name might not be exactly that one. Please make hundred percent sure.
  2. Your package might not be loaded since it might not be in your classpath.
  3. Our system might have bugs. Can you please download latest build from here and try again please.

If none of the above solves your problem, can you simplify your source code and send us your environment so that we can debug? If you want to debug it yourself, clone project to your computer and then include in your classpath and add breakpoints to PackageEntityInspector.java.

It is very unlikely that this problem is Android-specific, I think.

ahmetb commented 13 years ago

I've created a new project now it couldn't find packages automatically or detect classes by specifying package name.

The whole thing is broken for some reason now. @0ffffffffh can you investigate please?

beirigo commented 13 years ago

It seems broken, i built the jar from source but the problem persists. I'd recomend creating tags for stable releases so one can use it if something goes wrong on master branch. This might be useful: I tried to use MappingSession.registerEntity(MyClass.class) and got the following error:


E/AndroidRuntime(25103): Uncaught handler: thread main exiting due to uncaught exception
E/AndroidRuntime(25103): java.lang.NoSuchMethodError: java.util.LinkedList.descendingIterator
E/AndroidRuntime(25103):    at org.orman.mapper.EntityDependencyGraph.getDestroySchedule(EntityDependencyGraph.java:186)
E/AndroidRuntime(25103):    at org.orman.mapper.MappingSession.constructSchema(MappingSession.java:432)
E/AndroidRuntime(25103):    at org.orman.mapper.MappingSession.startNoCheck(MappingSession.java:316)
E/AndroidRuntime(25103):    at org.orman.mapper.MappingSession.start(MappingSession.java:237)
ahmetb commented 13 years ago

It looks like there's a problem with Android SDK in this issue, it is different than entity search process (it creates dependency graph to create entities in correct order, that's when the error occurs).

http://developer.android.com/reference/java/util/LinkedList.html#descendingIterator() says that this method is implemented. That's totally weird.

JakeWharton commented 13 years ago

Since API 9 only, however. What version are you running it on?

ahmetb commented 13 years ago

@JakeWharton oops I missed that part (under jetlag) and just focused to LinkedList exists since API 1. We shouldn't rely on that and create our own iterator.

@marcosbeirigo, thanks for noticing this bug.

beirigo commented 13 years ago

What's the MinSDK version to run orman on android? Couldn't find it on the wiki...

ahmetb commented 13 years ago

Since it is written in pure Java SE, we didn't even checked for what's min version actually. That exception was really a surprise for me. It should throw compilation error before you create APK since the method does not exist, but apparently it doesn't.

I'm fixing it right now. It should work on API≥3.

JakeWharton commented 13 years ago

It will only produce an error if you compile against the lowest API level you support. Most apps compile against higher API levels even though they support older ones.

ahmetb commented 13 years ago

I didn't know that. NoSuchMethodError exception is fixed with 239de3ac6f573638a2a8. You can now clone and rake.

0ffffffffh commented 13 years ago

@marcosbeirigo, i will investigate this issue. thanks for bug report.

almozavr commented 13 years ago

Have another problem with mapping on Android: Occurs: when trying to register db Error: ERROR/AndroidRuntime(14805): Caused by: org.orman.mapper.exception.AnnotatedClassNotFoundInPackageException: Could not find any entity marked class in 'dalvik'

When I map entities by hand everything works fine: MappingSession.registerEntity(Sample.class);

I'm using last library built from git clone rep, built by rake.

ahmetb commented 13 years ago

@0ffffffffh is working on it already. It is a dalvik vm classloading policy issue. He'll push his work when he's done with it. thanks for your patience.

almozavr commented 13 years ago

Thanks for your work, guys! When it would be critical bugs free, it would be awesome framework for Android.

ahmetb commented 13 years ago

Is there any update on merging the development branch with master that this bug is fixed @0ffffffffh? Thanks.

0ffffffffh commented 13 years ago

yes. I will commit an update soon. Currently, I'm developing an eclipse plugin. Of course, that is related with this issue. (You can see at https://github.com/0ffffffffh/OrmanEclipseDevPlugin). Dalvik classloader issue is a stringent problem to resolve. I'm still working on it.

Antpachon commented 13 years ago

Same issue @0ffffffffh here. Waiting for the update.

ragunathjawahar commented 12 years ago

I had the same issue, while registering packages and when searching automatically for entities. Registering the entities one by one seems to work.

Database db = new SQLiteAndroid(getApplicationContext(), "mydatabase.db");
MappingSession.getConfiguration().setCreationPolicy(SchemaCreationPolicy.CREATE_IF_NOT_EXISTS);
MappingSession.registerEntity(MyEntity.class); //Works
MappingSession.registerPackage("my.package.name"); //Doesn't work
MappingSession.registerDatabase(db);
MappingSession.start();
ahmetb commented 12 years ago

@ragunathjawahar we are aware of the issue. Unfortunately classloading mechanism is kind of different in Dalvik VM than JVM. Therefore we are having issues, @0ffffffffh is working on it. Until that time, try to use //Works line if it is not a big deal.

ragunathjawahar commented 12 years ago

@ahmetalpbalkan, anyways great job, I'll keep following orman closely.