Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Object Relational Mapping
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
paul wheaton
Jeanne Boyarsky
Ron McLeod
Sheriffs:
Paul Clapham
Liutauras Vilda
Devaka Cooray
Saloon Keepers:
Tim Holloway
Roland Mueller
Bartenders:
Forum:
Object Relational Mapping
Using Stored procedure in spring with hibernate
santosh dhulipala
Ranch Hand
Posts: 52
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
hi all,
i am trying to call a stored procedure using CreateSQLQuery method and i am getting unkone entity exception
Here is my entity class
package test; public class Login_Validate { String id; String LM_Code; String LM_Name; String LM_Add1; String LM_Add2; String LM_Add3; String LM_Add4; String LM_Pin; String LM_Phone; String LM_Fax; String LM_Email; String LM_Usertype; String Unit_Code; String Pre_Issue_LM; String Post_Issue_LM; String Lm_Type; public String getLM_Add1() { return LM_Add1; } public void setLM_Add1(String LM_Add1) { this.LM_Add1 = LM_Add1; } public String getLM_Add2() { return LM_Add2; } public void setLM_Add2(String LM_Add2) { this.LM_Add2 = LM_Add2; } public String getLM_Add3() { return LM_Add3; } public void setLM_Add3(String LM_Add3) { this.LM_Add3 = LM_Add3; } public String getLM_Add4() { return LM_Add4; } public void setLM_Add4(String LM_Add4) { this.LM_Add4 = LM_Add4; } public String getLM_Code() { return LM_Code; } public void setLM_Code(String LM_Code) { this.LM_Code = LM_Code; } public String getLM_Email() { return LM_Email; } public void setLM_Email(String LM_Email) { this.LM_Email = LM_Email; } public String getLM_Fax() { return LM_Fax; } public void setLM_Fax(String LM_Fax) { this.LM_Fax = LM_Fax; } public String getLM_Name() { return LM_Name; } public void setLM_Name(String LM_Name) { this.LM_Name = LM_Name; } public String getLM_Phone() { return LM_Phone; } public void setLM_Phone(String LM_Phone) { this.LM_Phone = LM_Phone; } public String getLM_Pin() { return LM_Pin; } public void setLM_Pin(String LM_Pin) { this.LM_Pin = LM_Pin; } public String getLM_Usertype() { return LM_Usertype; } public void setLM_Usertype(String LM_Usertype) { this.LM_Usertype = LM_Usertype; } public String getLm_Type() { return Lm_Type; } public void setLm_Type(String Lm_Type) { this.Lm_Type = Lm_Type; } public String getPost_Issue_LM() { return Post_Issue_LM; } public void setPost_Issue_LM(String Post_Issue_LM) { this.Post_Issue_LM = Post_Issue_LM; } public String getPre_Issue_LM() { return Pre_Issue_LM; } public void setPre_Issue_LM(String Pre_Issue_LM) { this.Pre_Issue_LM = Pre_Issue_LM; } public String getUnit_Code() { return Unit_Code; } public void setUnit_Code(String Unit_Code) { this.Unit_Code = Unit_Code; } public String getId() { return id; } public void setId(String id) { this.id = id; } }
DAO class
package test; import java.sql.SQLException; import java.util.List; import org.hibernate.HibernateException; import org.hibernate.Session; import org.springframework.orm.hibernate3.HibernateCallback; import org.springframework.orm.hibernate3.support.HibernateDaoSupport; public class LoginDAO extends HibernateDaoSupport { public List ValidateProcedure(final String unameName,final String pass) { List list= (List) getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session sn) throws HibernateException, SQLException { String qu="exec general..BRLM_Login_Validate 'unameName',pass'"; return sn.createSQLQuery(qu).addEntity(Login_Validate.class).list(); // throw new UnsupportedOperationException("Not supported yet."); } }); System.out.println("DAO"+list.size()); return list; } }
My spring class
import java.util.List; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.xml.XmlBeanFactory; import org.springframework.core.io.ClassPathResource; public static void main(String args[]) { BeanFactory factory= new XmlBeanFactory(new ClassPathResource("XMLConfig.xml")); LoginDAO ldao=(LoginDAO)factory.getBean("loginDAO"); List list =(List)ldao.ValidateProcedure("sbicaps","karvy@1$"); System.out.println("size"+list.size()); System.out.println("I Succed"+list.size()); System.out.println("I Succed"); // System.out.println("name"+l.getLM_Name() ); // System.out.println("ucode"+l.getLM_Phone()); } }
Thanks & Regards
Santosh Kumar.D
santosh dhulipala
Ranch Hand
Posts: 52
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
spring configuretion xML file
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:flow="http://www.springframework.org/schema/webflow-config" xmlns:jms="http://www.springframework.org/schema/jms" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:lang="http://www.springframework.org/schema/lang" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.6.SEC01.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.6.SEC01.xsd http://www.springframework.org/schema/webflow-config http://www.springframework.org/schema/webflow-config/spring-webflow-config-2.0.xsd http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms-2.5.6.SEC01.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.6.SEC01.xsd http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-2.5.6.SEC01.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.6.SEC01.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.6.SEC01.xsd "> <bean id="dataSource" class="org.apache.tomcat.dbcp.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver" /> <property name="url" value="jdbc:sqlserver://URL" /> <property name="username" value="UNAME" /> <property name="password" value="PASS" /> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="configLocation" value="hibernate.cfg.xml" /> <property name="configurationClass" value="org.hibernate.cfg.AnnotationConfiguration" /> <property name="hibernateProperties"> <props> <prop key="hibernate.query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</prop> <prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop> <prop key="hibernate.hbm2ddl.auto">create</prop> <prop key="hibernate.show_sql">true</prop> </props> </property> </bean> <bean name="loginDAO" class="test.LoginDAO"> <property name="sessionFactory" ref="sessionFactory" /> </bean> </beans>
hibernate configuration file
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> </session-factory> </hibernate-configuration>
Stack TRACE
run: Mar 11, 2011 4:55:54 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions INFO: Loading XML bean definitions from class path resource [XMLConfig.xml] Mar 11, 2011 4:55:54 PM org.hibernate.cfg.annotations.Version <clinit> INFO: Hibernate Annotations 3.3.1.GA Mar 11, 2011 4:55:54 PM org.hibernate.cfg.Environment <clinit> INFO: Hibernate 3.2.5 Mar 11, 2011 4:55:54 PM org.hibernate.cfg.Environment <clinit> INFO: hibernate.properties not found Mar 11, 2011 4:55:54 PM org.hibernate.cfg.Environment buildBytecodeProvider INFO: Bytecode provider name : cglib Mar 11, 2011 4:55:54 PM org.hibernate.cfg.Environment <clinit> INFO: using JDK 1.4 java.sql.Timestamp handling Mar 11, 2011 4:55:54 PM org.hibernate.cfg.Configuration configure INFO: configuring from url: file:/C:/sphib/build/classes/hibernate.cfg.xml Mar 11, 2011 4:55:54 PM org.hibernate.cfg.Configuration doConfigure INFO: Configured SessionFactory: null Mar 11, 2011 4:55:54 PM org.hibernate.cfg.AnnotationConfiguration secondPassCompile INFO: Hibernate Validator not found: ignoring Mar 11, 2011 4:55:54 PM org.springframework.orm.hibernate3.LocalSessionFactoryBean buildSessionFactory INFO: Building new Hibernate SessionFactory Mar 11, 2011 4:55:54 PM org.hibernate.connection.ConnectionProviderFactory newConnectionProvider INFO: Initializing connection provider: org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider Mar 11, 2011 4:55:55 PM org.hibernate.cfg.SettingsFactory buildSettings INFO: RDBMS: Microsoft SQL Server, version: 9.00.4053 Mar 11, 2011 4:55:55 PM org.hibernate.cfg.SettingsFactory buildSettings INFO: JDBC driver: Microsoft SQL Server 2005 JDBC Driver, version: 1.0.809.102 Mar 11, 2011 4:55:55 PM org.hibernate.dialect.Dialect <init> INFO: Using dialect: org.hibernate.dialect.SQLServerDialect Mar 11, 2011 4:55:55 PM org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory INFO: Transaction strategy: org.springframework.orm.hibernate3.SpringTransactionFactory Mar 11, 2011 4:55:55 PM org.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup INFO: No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended) Mar 11, 2011 4:55:55 PM org.hibernate.cfg.SettingsFactory buildSettings INFO: Automatic flush during beforeCompletion(): disabled Mar 11, 2011 4:55:55 PM org.hibernate.cfg.SettingsFactory buildSettings INFO: Automatic session close at end of transaction: disabled Mar 11, 2011 4:55:55 PM org.hibernate.cfg.SettingsFactory buildSettings INFO: Scrollable result sets: enabled Mar 11, 2011 4:55:55 PM org.hibernate.cfg.SettingsFactory buildSettings INFO: JDBC3 getGeneratedKeys(): enabled Mar 11, 2011 4:55:55 PM org.hibernate.cfg.SettingsFactory buildSettings INFO: Connection release mode: auto Mar 11, 2011 4:55:55 PM org.hibernate.cfg.SettingsFactory buildSettings INFO: Default batch fetch size: 1 Mar 11, 2011 4:55:55 PM org.hibernate.cfg.SettingsFactory buildSettings INFO: Generate SQL with comments: disabled Mar 11, 2011 4:55:55 PM org.hibernate.cfg.SettingsFactory buildSettings INFO: Order SQL updates by primary key: disabled Mar 11, 2011 4:55:55 PM org.hibernate.cfg.SettingsFactory buildSettings INFO: Order SQL inserts for batching: disabled Mar 11, 2011 4:55:55 PM org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory INFO: Query translator: org.hibernate.hql.classic.ClassicQueryTranslatorFactory Mar 11, 2011 4:55:55 PM org.hibernate.cfg.SettingsFactory buildSettings INFO: Query language substitutions: {} Mar 11, 2011 4:55:55 PM org.hibernate.cfg.SettingsFactory buildSettings INFO: JPA-QL strict compliance: disabled Mar 11, 2011 4:55:55 PM org.hibernate.cfg.SettingsFactory buildSettings INFO: Second-level cache: enabled Mar 11, 2011 4:55:55 PM org.hibernate.cfg.SettingsFactory buildSettings INFO: Query cache: disabled Mar 11, 2011 4:55:55 PM org.hibernate.cfg.SettingsFactory createCacheProvider INFO: Cache provider: org.hibernate.cache.NoCacheProvider Mar 11, 2011 4:55:55 PM org.hibernate.cfg.SettingsFactory buildSettings INFO: Optimize cache for minimal puts: disabled Mar 11, 2011 4:55:55 PM org.hibernate.cfg.SettingsFactory buildSettings INFO: Structured second-level cache entries: disabled Mar 11, 2011 4:55:55 PM org.hibernate.cfg.SettingsFactory buildSettings INFO: Echoing all SQL to stdout Mar 11, 2011 4:55:55 PM org.hibernate.cfg.SettingsFactory buildSettings INFO: Statistics: disabled Mar 11, 2011 4:55:55 PM org.hibernate.cfg.SettingsFactory buildSettings INFO: Deleted entity synthetic identifier rollback: disabled Mar 11, 2011 4:55:55 PM org.hibernate.cfg.SettingsFactory buildSettings INFO: Default entity-mode: pojo Mar 11, 2011 4:55:55 PM org.hibernate.cfg.SettingsFactory buildSettings INFO: Named query checking : enabled Mar 11, 2011 4:55:55 PM org.hibernate.impl.SessionFactoryImpl <init> INFO: building session factory Mar 11, 2011 4:55:55 PM org.hibernate.impl.SessionFactoryObjectFactory addInstance INFO: Not binding factory to JNDI, no JNDI name configured Mar 11, 2011 4:55:55 PM org.hibernate.tool.hbm2ddl.SchemaExport execute INFO: Running hbm2ddl schema export Mar 11, 2011 4:55:55 PM org.hibernate.tool.hbm2ddl.SchemaExport execute INFO: exporting generated schema to database Mar 11, 2011 4:55:55 PM org.hibernate.tool.hbm2ddl.SchemaExport execute INFO: schema export complete Exception in thread "main" org.springframework.orm.hibernate3.HibernateSystemException: Unknown entity: test.Login_Validate; nested exception is org.hibernate.MappingException: Unknown entity: test.Login_Validate at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:676) at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412) at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:424) at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:339) at test.LoginDAO.ValidateProcedure(LoginDAO.java:23) at test.Testing.main(Testing.java:23) Caused by: org.hibernate.MappingException: Unknown entity: test.Login_Validate at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:550) at org.hibernate.loader.custom.sql.SQLQueryReturnProcessor.getSQLLoadable(SQLQueryReturnProcessor.java:312) at org.hibernate.loader.custom.sql.SQLQueryReturnProcessor.processRootReturn(SQLQueryReturnProcessor.java:353) at org.hibernate.loader.custom.sql.SQLQueryReturnProcessor.processReturn(SQLQueryReturnProcessor.java:332) at org.hibernate.loader.custom.sql.SQLQueryReturnProcessor.process(SQLQueryReturnProcessor.java:148) at org.hibernate.loader.custom.sql.SQLCustomQuery.<init>(SQLCustomQuery.java:64) at org.hibernate.engine.query.NativeSQLQueryPlan.<init>(NativeSQLQueryPlan.java:43) at org.hibernate.engine.query.QueryPlanCache.getNativeSQLQueryPlan(QueryPlanCache.java:114) at org.hibernate.impl.AbstractSessionImpl.getNativeSQLQueryPlan(AbstractSessionImpl.java:137) at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142) at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:152) at test.LoginDAO$1.doInHibernate(LoginDAO.java:27) at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:419) ... 3 more Java Result: 1 BUILD SUCCESSFUL (total time: 23 seconds)
Thanks & Regards
Santosh Kumar.D
Paul Sturrock
Bartender
Posts: 10336
I like...
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
This doesn't look like its anything to do with the SP, you just have not mapped test.Login_Validate, either as part of your Hibernate config file of using annotations.
JavaRanch FAQ
HowToAskQuestionsOnJavaRanch
santosh dhulipala
Ranch Hand
Posts: 52
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
it is excuting when i remove the
addEntity
method in LoginDAO.
but generating class cast exception
Thanks & Regards
Santosh Kumar.D
A lot of people cry when they cut onions. The trick is not to form an emotional bond. This tiny ad told me:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Unable to read the parameter in action class which was passed from the JSP in struts...please help??
Hibernate and JPA entity with spring framework
StoredProcedure outParameters oracle
Controlling Hibernate Session with Spring
commit data in hibernate template through spring
More...