Unable to set the specific Table name

514 views
Skip to first unread message

Marian

unread,
Oct 6, 2011, 2:21:17 AM10/6/11
to ActiveJDBC Group
I am trying to set a specific table name and not go with the default
auto-generated one.

------- Member.java


@Table("Member")
@IdName("member_id")
public class Member extends Model {

}
------- Main.java
List<Member> members = Member.where("username = ?" , "marian");
for(Member member: members){
System.out.println(member.get("username"));
}

----- FULL stack trace


ERROR server comment - invoke(onConnect):
org.javalite.activejdbc.DBException: java.lang.NullPointerException:
org.javalite.activejdbc.Registry.init(Registry.java:156)
org.javalite.activejdbc.DBException: java.lang.NullPointerException
at org.javalite.activejdbc.Registry.init(Registry.java:156)
at
org.javalite.activejdbc.Registry.getMetaModelByClassName(Registry.java:
106)
at org.javalite.activejdbc.Model.getDaClass(Model.java:2091)
at org.javalite.activejdbc.Model.getMetaModel(Model.java:58)
at org.javalite.activejdbc.Model.find(Model.java:1605)
at org.javalite.activejdbc.Model.where(Model.java:1582)
at com.chatv2.db.model.Member.where(Member.java)
at com.chatv2.module.VideoChatBase.onConnect(VideoChatBase.java:32)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.wowza.wms.module.ModuleFunction.invoke(Unknown Source)
at com.wowza.wms.module.ModuleFunctions.invokeSpecial(Unknown Source)
at com.wowza.wms.module.ModuleFunctions.onConnect(Unknown Source)
at com.wowza.wms.module.ModuleConnect.connect(Unknown Source)
at
com.wowza.wms.request.RequestProcessFunctions.processFunctions(Unknown
Source)
at com.wowza.wms.request.RTMPRequestAdapter.service(Unknown Source)
at com.wowza.wms.server.ServerHandler.serviceRequest(Unknown Source)
at com.wowza.wms.server.ServerHandler.handleMessageReceived(Unknown
Source)
at com.wowza.wms.server.ServerHandler.messageReceived(Unknown Source)
at com.wowza.wms.server.ServerHandlerThreadedSession.run(Unknown
Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown
Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: org.javalite.activejdbc.InitException:
java.lang.NullPointerException
... 25 more
Caused by: java.lang.NullPointerException
at
org.javalite.activejdbc.Registry.discoverOne2ManyAssociationsFor(Registry.java:
356)
at
org.javalite.activejdbc.Registry.discoverAssociationsFor(Registry.java:
310)
at org.javalite.activejdbc.Registry.init(Registry.java:147)
... 24 more
-----------------


It seems that the code gets a null pointer exception in
discoverOne2ManyAssociationsFor at this line:
targetMM != sourceMM && targetMM.hasAttribute(sourceFKName) where both
targetMM and sourceMM are null.

Marian

unread,
Oct 6, 2011, 2:32:37 AM10/6/11
to ActiveJDBC Group
Ok, i found the issue:
It seems that in getMetaModel, the table name gets converted to
lowercase or uppercase and it's not preserved in it's original format.
In my case, Member is converted to member or Member but the
metaModelsByTableName hashmap contains

Member=MetaModel: Member, class com.chatv2.db.model.MemberModel,
people=MetaModel: people, class org.javalite.ehcache_test.Person

Is there an existing workaround for this?

Marian

unread,
Oct 6, 2011, 2:34:07 AM10/6/11
to ActiveJDBC Group
Sorry i mean Member is converted to member or MEMBER

ipolevoy

unread,
Oct 6, 2011, 10:39:06 AM10/6/11
to activejd...@googlegroups.com
can you please post DDL for table, or just a structure  for it?
Getting an NPE in this case is very strange, and I would like to investigate this. Did you run instrumentation by the way?
thanks
igor

ipolevoy

unread,
Oct 6, 2011, 10:41:11 AM10/6/11
to activejd...@googlegroups.com
Also, what database are you using?

ipolevoy

unread,
Oct 6, 2011, 10:48:19 AM10/6/11
to activejd...@googlegroups.com
I think I know what the issue is. I logged a new defect, will be fixed today.
In the mean time, you can avoid this by using either upper case or lower case for your table name:

@Table("member")
or
@Table("MEMBER")

thanks

ipolevoy

unread,
Oct 6, 2011, 10:48:48 AM10/6/11
to activejd...@googlegroups.com

Marian

unread,
Oct 6, 2011, 10:58:08 AM10/6/11
to ActiveJDBC Group
I solved the issue by with this patch:
MetaModel getMetaModel(String tableName) {
+ MetaModel mm = metaModelsByTableName.get(tableName);
+ if(mm != null) return mm;
Connection con = ConnectionsAccess.getConnection(dbName);

//try upper case table name first - Oracle uses upper case
- ResultSet rs = con.getMetaData().getColumns(null, null,
table.toUpperCase(), null);
+ ResultSet rs = con.getMetaData().getColumns(null, null,
table, null);
String dbProduct =
con.getMetaData().getDatabaseProductName().toLowerCase();
Map<String, ColumnMetadata> columns = getColumns(rs,
dbProduct);
rs.close();
+
+ if(columns.size() == 0){
+ rs = con.getMetaData().getColumns(null, null,
table.toUpperCase(), null);
+ dbProduct =
con.getMetaData().getDatabaseProductName().toLowerCase();
+ columns = getColumns(rs, dbProduct);
+ rs.close();
+ }


Then, things went jut fine.




On Oct 6, 4:48 pm, ipolevoy <ipole...@gmail.com> wrote:
> Defect URL:http://code.google.com/p/activejdbc/issues/detail?id=117

ipolevoy

unread,
Oct 6, 2011, 1:53:18 PM10/6/11
to activejd...@googlegroups.com
thank you for contribution, this has been fixed, please get the latest snapshot

igor
Reply all
Reply to author
Forward
0 new messages