zhangjingl02 / activejdbc

Automatically exported from code.google.com/p/activejdbc
0 stars 0 forks source link

NullPointerException at ModelFinder.findModels() #179

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago

> What steps will reproduce the problem?
1. Delete activejdbc_models.properties
2. Run ActiveJDBC

> What is the expected output? 

         throw new InitException("you are trying to work with models, but no models are found. Maybe you have " +
                    "no models in project, or you did not instrument the models. It is expected that you have " +
                    "a file activejdbc_models.properties on classpath");

> What do you see instead?

Exception caught: org.javalite.activejdbc.InitException: 
java.lang.NullPointerException
org.javalite.activejdbc.InitException: java.lang.NullPointerException
    at org.javalite.activejdbc.Registry.init(Registry.java:157)
    at org.javalite.activejdbc.Model.getMetaModel(Model.java:58)
    at org.javalite.activejdbc.Model.getMetaModelLocal(Model.java:952)
......
    at org.javalite.activejdbc.Model.set(Model.java:202)
Caused by: java.lang.NullPointerException
    at org.javalite.activejdbc.ModelFinder.findModels(ModelFinder.java:38)
    at org.javalite.activejdbc.Registry.init(Registry.java:131)
    ... 37 more

> What version of the product are you using? On what operating system?

1.4.5 on Windows 7 Starter

>  Please provide any additional information below.

       if (models.size() != 0) {

should read

        if (models != null && models.size() != 0) {

Original issue reported on code.google.com by abc6...@gmail.com on 30 Oct 2012 at 7:03

GoogleCodeExporter commented 9 years ago
ha, thanks for solution :), will make the fix soon.

Original comment by i...@polevoy.org on 30 Oct 2012 at 3:03

GoogleCodeExporter commented 9 years ago
������ ����������������!

Yeah, that solution took me a lot of  brainstorming :-) I  did not have the
line number, so instead I just copied and pasted what I had on my box. It
was past midnight.

Question: with ActiveRecord pattern, where do you keep the business logic?
I feel a bit hesitant to mix business logic with database logic, even if
the latter is fairly abstracted away. So I use activeJDBC models as a
wrapper around my business object. Though I've only been playing with
ActiveJDBC for 2 days, so that may change.

���

Original comment by abc6...@gmail.com on 30 Oct 2012 at 3:45

GoogleCodeExporter commented 9 years ago
we have been using AJ for over 3 years, and a general pattern is to add static 
methods to models to wrap more complicated DB access than stock AJ API 
provides. When a complex interaction  is necessary, we create a simple Java 
service class (Facade pattern) and write that interaction in this class(es). 
Internally it is like a service and interacts potentially with multiple models. 
So, the rule of thumb: 
1. If you need complex interactions against a single table (or at most two), 
create a static method on model
2. If you need more complex interactions, business rules, operations on 
multiple models, write a service class - just plain Java code. 
hope this helps, 
thanks

Original comment by i...@polevoy.org on 30 Oct 2012 at 8:04