Reputation: 311
i am using Hibernate to get Column names of the table.I Created one Method and I am passing my Table Name to that Method While executing I am Getting This Exception : No Dialect mapping for JDBC type: -1 Could any one Help me out.Thanks
Below Mycode:
Dao class:
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>
Upvotes: 0
Views: 1554
Reputation: 26
Change the property name of dialect as follows:
name="dialect" change it to name="hibernate.dialect"
and should also add the mapping resource="path where the respective(entity class related as if Person entity-->Person.hbm.xml) hbm.xml file presents"
and run it.
Upvotes: 1