{"issue":{"created_at":"2011-11-27T14:56:27Z","state":"open","updated_at":"2011-11-27T21:00:44Z","user":{"gravatar_id":"a8ee6ea52b89dfa1388b592a260c60a6","id":1141970,"url":"https://api.github.com/users/ragunathjawahar","login":"ragunathjawahar","avatar_url":"https://secure.gravatar.com/avatar/a8ee6ea52b89dfa1388b592a260c60a6?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png"},"comments":1,"body":"I start the Mapping Session in my Activity's **onCreate** method. Once I back out of the application and restart it once again I get the following exception:\r\n\r\n    11-27 17:55:53.448: E/AndroidRuntime(754): Caused by: org.orman.mapper.exception.MappingSessionAlreadyStartedException: Mapping session has already been started. Do not use start method more than once.\r\n\r\nThe app then crashes, but the next time I open the app, it works fine.\r\n\r\n```Java\r\npublic static void initOrmanMappingSession(Class<?>[] entityClasses,  Database database) {\r\n        System.gc();\r\n\t\t \r\n        MappingSession.getConfiguration().setCreationPolicy(SchemaCreationPolicy.CREATE_IF_NOT_EXISTS);\r\n        MappingSession.registerDatabase(database);\r\n        for(Class<?> clazz : entityClasses) {\r\n            MappingSession.registerEntity(clazz);\r\n        }\r\n        \r\n        MappingSession.startSafe();\r\n}\r\n```\r\n\r\n","assignee":null,"id":2360178,"number":39,"pull_request":{"patch_url":null,"html_url":null,"diff_url":null},"labels":[],"title":"Android - MappingSessionAlreadyStartedException","closed_at":null,"html_url":"https://github.com/ahmetalpbalkan/orman/issues/39","milestone":null,"url":"https://api.github.com/repos/ahmetalpbalkan/orman/issues/39"},"action":"created","comment":{"created_at":"2011-11-27T21:00:44Z","updated_at":"2011-11-27T21:00:44Z","user":{"gravatar_id":"55857f34d4be142f5977572bdfb01447","id":159209,"url":"https://api.github.com/users/ahmetalpbalkan","login":"ahmetalpbalkan","avatar_url":"https://secure.gravatar.com/avatar/55857f34d4be142f5977572bdfb01447?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png"},"body":"Well, you are using `startSafe` method which is okay, however somehow this `initOrmanMappingSession` method is called twice, I think.\r\n\r\nTherefore it tries to register entity classes after the session is statically started. That causes the exception. I thought that I have created a public method called `isSessionStarted()` but clearly I was wrong. There's a `sessionStarted` variable in [`MappingSession.java`](https://github.com/ahmetalpbalkan/orman/blob/master/src/org/orman/mapper/MappingSession.java) and it is private at this moment.\r\n\r\nThe only way to make it work before I fix this is just put a huge try...catch around this code which catches the `MappingSessionAlreadyStartedException` and immediately quits. I think this is safe. As I stated before, this happens because your method is created twice. I also have encountered this issue in Android, probably it is because static scope is not hundred percent cleaned up by garbage collector after relaunching the app in a short time. Thanks for noticing this issue.\r\n\r\n","id":2890058,"url":"https://api.github.com/repos/ahmetalpbalkan/orman/issues/comments/2890058"}}