can not mapping to database table

2021-05-25 17:59:42

[ERROR]-[Thread: MQTT Call: org-19922877693696-test1234]-[cn.org.zhny.base.JBoltBaseModel._getTable()]: class cn.org.zhny.common.model.Weather can not mapping to database table,maybe application cannot connect to database. 

连接断开,可以做重连

MqttException (0) - java.lang.RuntimeException: class cn.org.zhny.common.model.Weather can not mapping to database table,maybe application cannot connect to database. 

at org.eclipse.paho.client.mqttv3.internal.CommsCallback.run(CommsCallback.java:228)

at java.lang.Thread.run(Thread.java:748)

Caused by: java.lang.RuntimeException: class cn.org.zhny.common.model.Weather can not mapping to database table,maybe application cannot connect to database. 

at cn.org.zhny.base.JBoltBaseModel._getTable(JBoltBaseModel.java:139)

at cn.org.zhny.base.JBoltBaseModel._getPrimaryKeys(JBoltBaseModel.java:174)

at cn.org.zhny.base.JBoltBaseModel._getPrimaryKey(JBoltBaseModel.java:162)

at cn.org.zhny.base.JBoltBaseModel._initPrimaryKey(JBoltBaseModel.java:196)

at cn.org.zhny.base.JBoltBaseModel.save(JBoltBaseModel.java:213)

at cn.org.zhny.mqtt.PushCallback.handleMsg(PushCallback.java:92)

at cn.org.zhny.mqtt.PushCallback.messageArrived(PushCallback.java:73)

at org.eclipse.paho.client.mqttv3.internal.CommsCallback.deliverMessage(CommsCallback.java:519)

at org.eclipse.paho.client.mqttv3.internal.CommsCallback.handleMessage(CommsCallback.java:417)

at org.eclipse.paho.client.mqttv3.internal.CommsCallback.run(CommsCallback.java:214)

... 1 more

能正常启动,在config文件的onStart方法里的语句也能连接数据库并输出

1.png

但是在另一个地方的保存就报错,不知道怎么回事???这个保存是在mqtt的回调函数里,这个应该怎么操作那??

2.png


评论区

杜福忠

2021-05-25 18:28

class cn.org.zhny.common.model.Weather can not mapping to database table,maybe application cannot connect to database.
是不是 arp.addMapping("user", User.class);
https://jfinal.com/doc/5-2
没有建立了数据库表名到Model的映射关系啊?
可以用Db + Record 保存试试。

zhengknight

2021-05-26 10:35

@杜福忠 连接断开,可以做重连
MqttException (0) - java.lang.NullPointerException
at org.eclipse.paho.client.mqttv3.internal.CommsCallback.run(CommsCallback.java:228)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NullPointerException
at com.jfinal.plugin.activerecord.Db.save(Db.java:496)
at cn.org.zhny.mqtt.PushCallback.handleMsg(PushCallback.java:99)
at cn.org.zhny.mqtt.PushCallback.messageArrived(PushCallback.java:76)
at org.eclipse.paho.client.mqttv3.internal.CommsCallback.deliverMessage(CommsCallback.java:519)
at org.eclipse.paho.client.mqttv3.internal.CommsCallback.handleMessage(CommsCallback.java:417)
at org.eclipse.paho.client.mqttv3.internal.CommsCallback.run(CommsCallback.java:214)
... 1 more
Db + Record 还是报错,应该是线程的问题,再搜搜看看怎么解决吧,谢谢

杜福忠

2021-05-26 11:26

@zhengknight mqtt是在ActiveRecordPlugin启动之后启动的吧?
如果是,那得看下是不是ClassLoader不同了

zhengknight

2021-05-26 14:10

@杜福忠 mqtt先启动的,启动了接收订阅的消息,然后处理,然后调用保存,就报错

杜福忠

2021-05-26 14:22

@zhengknight ActiveRecordPlugin 得先启动,不然咋操作数据库了

zhengknight

2021-05-26 16:32

@杜福忠 咋个先启动法啊

杜福忠

2021-05-26 19:22

@zhengknight mqtt 的启动方法,放在 onStart 里面调用吧,这种方式简单

zhengknight

2021-05-31 10:01

@杜福忠 好的,是放到onStart里好了,非常感谢!

热门反馈

扫码入社