hppys 发表于 2023-12-13 16:29:25

OA连接mycat时 Table 'CPT_COMPONENT' already exists

oa报错内容如下:


itComponents, message:get entityManager for class com.x.component.core.entity.Component error., exception:java.lang.IllegalStateException.
java.lang.IllegalStateException: get entityManager for class com.x.component.core.entity.Component error.
      at com.x.base.core.container.factory.EntityManagerContainerFactory.createEntityManager(EntityManagerContainerFactory.java:115) ~
      at com.x.base.core.container.EntityManagerContainerBasic.get(EntityManagerContainerBasic.java:36) ~
      at com.x.base.core.container.EntityManagerContainer.listEqualOrIn(EntityManagerContainer.java:584) ~
      at com.x.component.assemble.control.schedule.InitComponents.init(InitComponents.java:38) ~
      at com.x.component.assemble.control.schedule.InitComponents.schedule(InitComponents.java:28) ~
      at com.x.base.core.project.schedule.AbstractJob.execute(AbstractJob.java:25) ~
      at org.quartz.core.JobRunShell.run(JobRunShell.java:202) ~
      at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573) ~
Caused by: org.apache.openjpa.persistence.PersistenceException: Table 'CPT_COMPONENT' already exists {stmnt 1800081967 CREATE TABLE CPT_COMPONENT (xid VARCHAR(64) NOT NULL, xcreateTime DATETIME, xsequence VARCHAR(128), xupdateTime DATETIME, xdistributeFactor INTEGER, xiconPath VARCHAR(255), xname VARCHAR(255), xorderNumber INTEGER, xpath VARCHAR(255), xtitle VARCHAR(255), xtype VARCHAR(16), xvisible BIT, UNIQUE CPT_COMPONENT_DUC (xid, xcreateTime, xupdateTime, xsequence)) ENGINE = innodb}
      at org.apache.openjpa.jdbc.meta.MappingTool.record(MappingTool.java:625) ~
      at org.apache.openjpa.jdbc.meta.MappingTool.record(MappingTool.java:488) ~
      at org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory.synchronizeMappings(JDBCBrokerFactory.java:173) ~
      at org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory.synchronizeMappings(JDBCBrokerFactory.java:178) ~
      at org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory.newBrokerImpl(JDBCBrokerFactory.java:134) ~
      at org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:213) ~
      at org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(DelegatingBrokerFactory.java:166) ~
      at org.apache.openjpa.persistence.EntityManagerFactoryImpl.doCreateEM(EntityManagerFactoryImpl.java:282) ~
      at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:201) ~
      at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:188) ~
      at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:178) ~
      at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:64) ~


2.config下数据路连接配置如下:

[
      {
                "url":"jdbc:mysql://192.168.221.150:8066/TRY?autoReconnect=true&useSSL=false&useUnicode=true&characterEncoding=UTF-8&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8",
                "username" : "root",
                "password" :"123456",
                "includes": [],
                "excludes": [],
                "enable" : true,
                "driverClassName" : "com.mysql.cj.jdbc.Driver"
      }
]



启蒙星 发表于 2023-12-14 13:44:00

你用mycat做分库分表吗?mycat对应几个数据库?你要先直连mysql通过平台的jpa把表都建好了然后连mycat再试试

hppys 发表于 2023-12-14 14:39:46

本帖最后由 hppys 于 2023-12-14 14:42 编辑

启蒙星 发表于 2023-12-14 13:44
你用mycat做分库分表吗?mycat对应几个数据库?你要先直连mysql通过平台的jpa把表都建好了然后连mycat再试 ...
我主要想做mycat的读写分离,mycat对应mysql中master的一个数据库,然后mycat从mysql从库中读取数据,mysql做了主从,我现在先直连mysql已经把jpa表都建好,然后再用mycat直连还是报这个错误,直接连接mysql不管主还是从就不会有这报错;我用mycat新库没有任何数据直接连接oa,第一次就不会有报错,然后停止服务之后再次建立连接就会出现这个错误,请问是哪里需要修改吗

访问oa网页时会报500错误,大概是如下:

启蒙星 发表于 2023-12-15 10:15:36

你有没有测试过通过mycat可以正常的jdbc连接并能正常的增加和查询数据

hppys 发表于 2023-12-15 11:04:53

本帖最后由 hppys 于 2023-12-15 18:43 编辑

启蒙星 发表于 2023-12-15 10:15
你有没有测试过通过mycat可以正常的jdbc连接并能正常的增加和查询数据
就是第一次连接mycat时,启动不会出现错误,然后打开他网页端,他就会出现 Table 'PP_E_APPLICATION' already exist这些错误,第二次连接是启动时候就会出现Table 'PP_E_APPLICATION' already exist错误,然后网页端也打不开;第一次连接时,我修改oa传到mycat中的表,然后可以实现读写分离

启蒙星 发表于 2023-12-18 10:21:23

你确定两个数据库报错之前都有PP_E_APPLICATION这个表吗,如果都有估计要关闭openjpa的自动建表功能(关闭自动建表需要确保业务所有表都已经建了,可以通过直连数据库在控制台操作ctl -dd来保证创建所有的表),这需要修改源码:

hppys 发表于 2023-12-18 10:40:49

启蒙星 发表于 2023-12-18 10:21
你确定两个数据库报错之前都有PP_E_APPLICATION这个表吗,如果都有估计要关闭openjpa的自动建表功能(关闭 ...

那几个后端数据库都有这个表,只是这个表没有数据,关闭openjpa自动建表功能,指的是oa自带的表建好,不能自动创建,还是以后往oa添加表单,出现表也不会自动创建;

启蒙星 发表于 2023-12-19 09:40:39

后续都不会自动创建,如果需要得手工创建
页: [1]
查看完整版本: OA连接mycat时 Table 'CPT_COMPONENT' already exists