【问题标题】:Can' t Get column names of the Table using Hibernate无法使用 Hibernate 获取表的列名
【发布时间】:2014-02-10 12:11:37
【问题描述】:

我正在使用 Hibernate 获取表的列名。我创建了一个方法,并将我的 表名 传递给该方法在执行时我遇到了这个异常: 没有 JDBC 类型的方言映射:-1 谁能帮帮我。谢谢

在我的代码下面:

道类:

public class Dao {
        public static void main(String[] args) {
            Dao o=new Dao();
             ArrayList list=o.getTableDesc("examtype");
        System.out.println ("listlistlist"+list);
        }
    public  ArrayList<String>  getTableDesc(String tableName) {
            System.out.println("getFieldNames:start" + tableName);
            Object[] a;
            List<Object[]> fieldNames = new ArrayList<Object[]>();
            ArrayList<String> tabFieldNames = new ArrayList<String>();
            Session ses = HibernateUtil.getSessionFactory().openSession();
            try {
                String queryStr = "DESCRIBE "  + tableName;                 
                fieldNames = (List<Object[]>) ses.createSQLQuery(queryStr).list();
                System.out.println("fieldNamesfieldNames"+fieldNames);
                for (int i = 0; i < fieldNames.size(); i++) {
                    a = fieldNames.get(i);
                    tabFieldNames.add(a[0].toString());
                }
            } catch (Exception e) {
                e.printStackTrace();
                System.out.println("exception " + e);
            } finally {
                ses.close();
            }
            System.out.println("getFieldNames:end" + tabFieldNames.toString());
            return tabFieldNames;
        }  
    }

Hibernate.cfg.xml:

    <hibernate-configuration>
        <session-factory>
            <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
            <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
            <property name="hibernate.connection.url">jdbc:mysql://localhost:3306treamisdemo</property>
            <property name="hibernate.connection.username">root</property>
            <property name="hibernate.connection.password"></property>
            <property name="hibernate.format_sql">true</property>
            <property name="hibernate.connection.pool_size">30</property>
            <property name="hibernate.jdbc.batch_size">100</property>
            <!--<property name="hibernate.hbm2ddl.auto">update</property>-->
            <property name="hibernate.connection.isolation">2</property>
            <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>       
        </session-factory>
    </hibernate-configuration>

【问题讨论】:

  • 我不是 MySQL 专家,但这可能会对您有所帮助 link

标签: hibernate


【解决方案1】:

更改方言的属性名称如下:

name="方言" 将其更改为 name="hibernate.dialect"

并且还应该添加映射资源=“path where the individual(entity class related as if Person entity-->Person.hbm.xml) hbm.xml file present”

并运行它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-10-25
    • 1970-01-01
    • 1970-01-01
    • 2020-10-10
    • 1970-01-01
    • 1970-01-01
    • 2015-11-21
    • 1970-01-01
    相关资源
    最近更新 更多