NutzCN Logo
问答 无法自动创建关联表
发布于 3237天前 作者 爱犯贱的熊猫 1737 次浏览 复制 上一个帖子 下一个帖子
标签:

1111_png
新建了一个 圈子表、重启tomcat 后、该表成功创建

222_png
在用户 实体中配置了用户关注圈子 用户 VS 圈子的关联表、重启tomcat 后并没有自动创建该表、

请问什么地方还需要配置吗?@wendal

9 回复

截图不回.

  • @One(target=UserProfile.class, field="id", key="userId")
  • protected UserProfile profile;
  • //用户关注圈子
  • @ManyMany(from="u_id", relation="t_user_circle", target=Circle.class, to="circle_id")
  • protected List circles;
    没有创建关联表
  • //圈子
  • @Table("t_circle")
  • public class Circle extends BasePojo{
  • /**
  • */
  • private static final long serialVersionUID = 1L;
  • @Id
  • protected int id;
  • //名称
  • @Column
  • @ColDefine(width=100)
  • protected String name;
  • //版块
  • @Column("sec")
  • protected int section;
  • //说明
  • @Column("des")
  • @ColDefine(width=512)
  • protected String describe;

@wendal 圈子表已经成功创建了、现在就是 表"t_user_circle" 没有自动创建呢

主表存在的话不会建关联表

这种要求顺序的表,先调用dao.create,然后批量建表就好了

报错信息

2018-01-19 19:54:36 Get Connection from DataSource for JdbcExpert, if you lock at here, check your database server and configure
2018-01-19 19:54:36 Remove object 'myDao' from [app] 
2018-01-19 19:54:36 Remove object 'dataServiceImpl' from [app] 
2018-01-19 19:54:36 Remove object 'testCustomRealmMd5' from [app] 
2018-01-19 19:54:36 Error@/naxxm/login :
org.nutz.ioc.IocException: IocBean[testCustomRealmMd5] throw Exception when creating
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:150)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:216)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:245)
	at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:116)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.EncodingProcessor.process(EncodingProcessor.java:27)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.UpdateRequestAttributesProcessor.process(UpdateRequestAttributesProcessor.java:15)
	at org.nutz.mvc.impl.NutActionChain.doChain(NutActionChain.java:44)
	at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:67)
	at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
	at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:202)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:123)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:61)
	at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108)
	at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137)
	at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
	at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66)
	at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)
	at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)
	at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
	at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
	at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383)
	at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)
	at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606)
	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
	at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.RuntimeException: IocBean[testCustomRealmMd5] fail at field=[dataService]
	at org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:40)
	at org.nutz.ioc.weaver.DefaultWeaver.fill(DefaultWeaver.java:56)
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:136)
	... 40 more
Caused by: org.nutz.ioc.IocException: IocBean[dataServiceImpl] throw Exception when creating
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:150)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:216)
	at org.nutz.ioc.impl.NutIoc.getByType(NutIoc.java:407)
	at org.nutz.ioc.val.ReferTypeValue.get(ReferTypeValue.java:66)
	at org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:32)
	... 42 more
Caused by: java.lang.RuntimeException: IocBean[dataServiceImpl] fail at field=[myDao]
	at org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:40)
	at org.nutz.ioc.weaver.DefaultWeaver.fill(DefaultWeaver.java:56)
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:136)
	... 46 more
Caused by: org.nutz.ioc.IocException: IocBean[myDao] throw Exception when creating
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:150)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:216)
	at org.nutz.ioc.val.ReferTypeValue.get(ReferTypeValue.java:60)
	at org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:32)
	... 48 more
Caused by: org.nutz.lang.InvokingException: Fail to invoke [com.naxxm.MyDataSource].myDao() by args:
 
For the reason: null
	at org.nutz.lang.Invoking.invoke(Invoking.java:195)
	at org.nutz.lang.Mirror.invoke(Mirror.java:1120)
	at org.nutz.ioc.impl.ObjectMakerImpl$1.born(ObjectMakerImpl.java:78)
	at org.nutz.ioc.weaver.DefaultWeaver.born(DefaultWeaver.java:67)
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:115)
	... 51 more
Caused by: java.lang.NullPointerException
	at com.naxxm.MyDataSource.getConnection(MyDataSource.java:51)
	at org.nutz.trans.Trans.getConnectionAuto(Trans.java:263)
	at org.nutz.dao.jdbc.Jdbcs.getExpert(Jdbcs.java:106)
	at org.nutz.dao.impl.DaoSupport.setDataSource(DaoSupport.java:187)
	at org.nutz.dao.impl.DaoSupport.setDataSource(DaoSupport.java:178)
	at org.nutz.dao.impl.NutDao.<init>(NutDao.java:105)
	at com.naxxm.MyDataSource.myDao(MyDataSource.java:34)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:497)
	at org.nutz.lang.Invoking$NullArgInvoker.invoke(Invoking.java:77)
	at org.nutz.lang.Invoking.invoke(Invoking.java:192)
	... 55 more

MyDataSource类

package com.naxxm;

import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.logging.Logger;

import javax.servlet.http.HttpServletRequest;
import javax.sql.DataSource;

import org.nutz.dao.Dao;
import org.nutz.dao.impl.NutDao;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.lang.Lang;
import org.nutz.log.Log;
import org.nutz.log.Logs;
import org.nutz.mvc.Mvcs;

import com.naxxm.bean.system.SysCompany;

@IocBean
public class MyDataSource implements DataSource {
	private static final Log log = Logs.get();
	@Inject
	Dao dao; // 注入主库
	@Inject
	DataSource dataSource; // 注入主库的数据源

	@IocBean(name = "myDao")
	// 通过@IocBean工厂方法,声明一个用于操作子库的Dao实例
	public Dao myDao() {
		return new NutDao(this);
	}

	/**
	 * 这是唯一会被NutDao调用的方法
	 */
	public Connection getConnection() throws SQLException {
		Connection conn = null;;

		HttpServletRequest req = Mvcs.getReq();
		if (req == null) { // 非request上下文? 那就用主库的连接
			return dataSource.getConnection();
		}
		// 通过自定义逻辑拿到数据库信息(maybe需要做个map缓存一下)

		SysCompany companyDB = (SysCompany) Mvcs.getSessionAttrSafe("companyDB");

		String[] DBInfo = companyDB.getDBInfo().split(",");
		// String driverClassName = "net.sourceforge.jtds.jdbc.Driver";
		String jdbcUrl = DBInfo[0];
		String username = DBInfo[1];
		String password = DBInfo[2];
		System.out.println("------------------------------------------------------------------------------------------------");
		System.out.println(companyDB.getMc() + "---" + DBInfo[0] + "---" + DBInfo[1] + "---" + DBInfo[2]);
		System.out.println("------------------------------------------------------------------------------------------------");
		// Lang.loadClass(driverClassName);

			try {
				conn = DriverManager.getConnection(jdbcUrl, username, password);
				System.out.println("--->系统数据库:公司信息正常!");
				
			} catch (RuntimeException e) {
				System.out.println("--->系统数据库:公司信息不存在" + e.getMessage());
			}
			
		return conn;
		
	}

	public void setDriverClassName(String driverClassName) throws ClassNotFoundException {
		Lang.loadClass(driverClassName);
	}

	// 加载Nutz所支持的数据库的驱动!!
	static {
		String[] drivers = { "org.h2.Driver", "com.ibm.db2.jcc.DB2Driver", "org.hsqldb.jdbcDriver", "oracle.jdbc.OracleDriver", "org.postgresql.Driver", "net.sourceforge.jtds.jdbc.Driver",
				"com.microsoft.sqlserver.jdbc.SQLServerDriver", "org.sqlite.JDBC", "com.mysql.jdbc.Driver", "com.beyondb.jdbc.BeyondbDriver" };
		for (String driverClassName : drivers) {
			try {
				Class.forName(driverClassName);
			} catch (Throwable e) {
			}
		}
	}

	public PrintWriter getLogWriter() throws SQLException {
		throw Lang.noImplement();
	}

	public void setLogWriter(PrintWriter out) throws SQLException {
		throw Lang.noImplement();
	}

	public void setLoginTimeout(int seconds) throws SQLException {
		throw Lang.noImplement();
	}

	public int getLoginTimeout() throws SQLException {
		throw Lang.noImplement();
	}

	public <T> T unwrap(Class<T> iface) throws SQLException {
		throw Lang.noImplement();
	}

	public boolean isWrapperFor(Class<?> iface) throws SQLException {
		throw Lang.noImplement();
	}

	public Connection getConnection(String username, String password) throws SQLException {
		throw Lang.noImplement();
	}

	public Logger getParentLogger() {
		throw Lang.noImplement();
	}
}

添加下麦呢这段就报错

@IocBean(name = "myDao")
	// 通过@IocBean工厂方法,声明一个用于操作子库的Dao实例
	public Dao myDao() {
		return new NutDao(this);
	}

怎么发到这个帖子来了?

是不是这一行报错了? 判断一下嘛,没有信息就返回主库的连接


String[] DBInfo = companyDB.getDBInfo().split(",");

发错地方了,哈哈,我试试先

添加回复
请先登陆
回到顶部