i new hibernate , java. i'm trying execute native sql query have been stuck. can can me out or check i'm doing mistake?
my java code is :
try { trns = session.begintransaction(); string sql = "select principle,interest salaryinfo empid = " + selectedempid + ""; sqlquery query = session.createsqlquery(sql); list<object[]> rows = query.list(); (object[] row : rows) { salaryinfo si= new salaryinfo(); si.setprinciple(float.parsefloat(row[0].tostring())); si.setinterest(float.parsefloat(row[1].tostring())); sis.add(si); }
error trace:
severe: org.hibernate.mappingexception: no dialect mapping jdbc type: 7 @ org.hibernate.dialect.typenames.get(typenames.java:56) @ org.hibernate.dialect.typenames.get(typenames.java:81) @ org.hibernate.dialect.dialect.gethibernatetypename(dialect.java:192) @ org.hibernate.loader.custom.customloader.gethibernatetype(customloader.java:161) @ org.hibernate.loader.custom.customloader.autodiscovertypes(customloader.java:131) @ org.hibernate.loader.loader.getresultset(loader.java:1678) @ org.hibernate.loader.loader.doquery(loader.java:662) @ org.hibernate.loader.loader.doqueryandinitializenonlazycollections(loader.java:224) @ org.hibernate.loader.loader.dolist(loader.java:2145) @ org.hibernate.loader.loader.listignorequerycache(loader.java:2029) @ org.hibernate.loader.loader.list(loader.java:2024) . . . .
i did debug program , found program breaking on line sqlquery query = session.createsqlquery(sql);
hibernate config file :
<hibernate-configuration> <session-factory> <property name="hibernate.bytecode.use_reflection_optimizer">false</property> <property name="hibernate.connection.driver_class">com.mysql.jdbc.driver</property> <property name="hibernate.connection.password">****</property> <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/empdata</property> <property name="hibernate.connection.username">****</property> <property name="hibernate.dialect">org.hibernate.dialect.mysqlinnodbdialect</property> <property name="hibernate.show_sql">false</property> <property name="hibernate.format_sql">false</property> <property name="hibernate.cache.use_query_cache">true</property> <property name="hibernate.c3p0.acquire_increment">1</property> <property name="hibernate.c3p0.idle_test_period">10</property> <!-- seconds --> <mapping resource="hibernate/salaryinfo.hbm.xml" /> </session-factory> </hibernate-configuration>
you need put addscalar();
in native sqlquery syntax. avoid overhead of using resultsetmetadata, or more explicit in returned, 1 can use addscalar()
.
like this:
sqlquery query = session.createsqlquery(sql) .addscalar("principle", new floattype()) .addscalar("interest", new floattype());
Comments
Post a Comment