-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 
Author Message
 Post subject: Exception Error in named query: login
PostPosted: Mon Aug 09, 2010 1:02 am 
Newbie

Joined: Mon Aug 09, 2010 12:48 am
Posts: 6
i am sorry i am new to hibernate
please help me out i am trying to call a stored procedure(MS sqlserver) using hibernate,IDE Net beans 6.9 whose return values are from two tables.
I have created mapping files and entity classes for both the table,

Created the mapping files and entity class for the Stored procedure,calling the store procedure using named query

Entity Class

Code:

package finalpkg;
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;
   }
}


Mapping File--Login_Validate.hbm.xml

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
  <class name="finalpkg.Login_Validate">
      <property name="id"/>
    <property name="LM_Code"/>
    <property name="LM_Name"/>
    <property name="LM_Add1"/>
    <property name="LM_Add2"/>
    <property name="LM_Add3"/>
    <property name="LM_Add4"/>
    <property name="LM_Pin"/>
    <property name="LM_Phone"/>
    <property name="LM_Fax"/>
    <property name="LM_Email"/>
<property name="LM_Usertype"/>
<property name="Unit_Code"/>
<property name="Pre_Issue_LM"/>
<property name="Post_Issue_LM"/>
<property name="Lm_Type"/>
      </class>

      <sql-query name="login"  callable="true">
<return alias="login"  class="finalpkg.Login_Validate">
    <return-property name="id" column="id"/>
    <return-property name="LM_Code" column="LM_Code"/>
    <return-property name="LM_Name" column="LM_Name"/>
    <return-property name="LM_Add1" column="LM_Add1"/>
    <return-property name="LM_Add2" column="LM_Add2"/>
    <return-property name="LM_Add3" column="LM_Add3"/>
    <return-property name="LM_Add4" column="LM_Add4"/>
    <return-property name="LM_Pin" column="LM_Pin"/>
    <return-property name="LM_Phone" column="LM_Phone"/>
    <return-property name="LM_Fax" column="LM_Fax"/>
    <return-property name="LM_Email" column="LM_Email"/>
<return-property name="LM_Usertype" column="LM_Usertype"/>
<return-property name="Unit_Code" column="Unit_Code"/>
<return-property name="Pre_Issue_LM" column="Pre_Issue_LM"/>
<return-property name="Post_Issue_LM" column="Post_Issue_LM"/>
<return-property name="Lm_Type" column="Lm_Type"/>
</return>

exec BRLM_Login_Validate :username,:pass

    </sql-query>

</hibernate-mapping>


Hibernate Config file
Code:
<?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>
    <property name="hibernate.connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
    <property name="hibernate.connection.url">jdbc:sqlserver://..;databaseName=general</property>
    <property name="hibernate.connection.username"></property>
    <property name="hibernate.connection.password"></property>
    <mapping resource="Lead_Manager_Info.hbm.xml"/>
    <mapping resource="Lead_Manager_Master.hbm.xml"/>
    <mapping resource="Login_Validate.hbm.xml"/>
  </session-factory>
</hibernate-configuration>


Main Class
Code:
public class Main {
static SessionFactory sf=null;
static
{
    sf=HibernateUtil.getSessionFactory();
}
    public static void main(String[] args) {
        // TODO code application logic here
       /* Session s=sf.openSession();
                Lead_Manager_Info l=(Lead_Manager_Info)s.get(Lead_Manager_Info.class,2);
System.out.println("Unit code"+l.getUnit_code());
s.close();
Session ss=sf.openSession();
Lead_Manager_Master lm=(Lead_Manager_Master)ss.get(Lead_Manager_Master.class,10);
System.out.println("LM"+lm.getLm_Id());
ss.close();*/
Session sss=sf.openSession();
Transaction t=sss.beginTransaction();
Query q=sss.getNamedQuery("login");
q.setParameter("username","username");
q.setParameter("pass","***" );
List<Login_Validate> ll=(List<Login_Validate>)q.list();

for(int i=0;i<ll.size();i++)
  {
    Login_Validate lv=ll.get(i);
    System.out.println("Proc === == "+lv.getLM_Name());

}
t.commit();
sss.close();


    }


Last edited by santoshdhulipala on Mon Aug 09, 2010 3:02 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Exception Error in named query: login
PostPosted: Mon Aug 09, 2010 1:03 am 
Newbie

Joined: Mon Aug 09, 2010 12:48 am
Posts: 6
And the Stack Trace is

Code:
run:
Aug 9, 2010 10:13:45 AM org.hibernate.cfg.annotations.Version <clinit>
INFO: Hibernate Annotations 3.3.1.GA
Aug 9, 2010 10:13:45 AM org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.2.5
Aug 9, 2010 10:13:45 AM org.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
Aug 9, 2010 10:13:45 AM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: Bytecode provider name : cglib
Aug 9, 2010 10:13:45 AM org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
Aug 9, 2010 10:13:45 AM org.hibernate.cfg.Configuration configure
INFO: configuring from resource: /hibernate.cfg.xml
Aug 9, 2010 10:13:45 AM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: Configuration resource: /hibernate.cfg.xml
Aug 9, 2010 10:13:46 AM org.hibernate.cfg.Configuration addResource
INFO: Reading mappings from resource : Lead_Manager_Info.hbm.xml
Aug 9, 2010 10:13:46 AM org.hibernate.cfg.Configuration addResource
INFO: Reading mappings from resource : Lead_Manager_Master.hbm.xml
Aug 9, 2010 10:13:46 AM org.hibernate.cfg.Configuration doConfigure
INFO: Configured SessionFactory: null
Aug 9, 2010 10:13:46 AM org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: finalpkg.Lead_Manager_Info -> Lead_Manager_Info
Aug 9, 2010 10:13:46 AM org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: finalpkg.Lead_Manager_Master -> Lead_Manager_Master
Aug 9, 2010 10:13:46 AM org.hibernate.cfg.AnnotationConfiguration secondPassCompile
INFO: Hibernate Validator not found: ignoring
Aug 9, 2010 10:13:46 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Using Hibernate built-in connection pool (not for production use!)
Aug 9, 2010 10:13:46 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Hibernate connection pool size: 20
Aug 9, 2010 10:13:46 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: autocommit mode: false
Aug 9, 2010 10:13:46 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: using driver: com.microsoft.sqlserver.jdbc.SQLServerDriver at URL: jdbc:sqlserver://192.168.48.101:1433;databaseName=general
Aug 9, 2010 10:13:46 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: connection properties: {user=karisma, password=****}
Aug 9, 2010 10:13:46 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: RDBMS: Microsoft SQL Server, version: 9.00.4053
Aug 9, 2010 10:13:46 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC driver: Microsoft SQL Server 2005 JDBC Driver, version: 1.0.809.102
Aug 9, 2010 10:13:46 AM org.hibernate.dialect.Dialect <init>
INFO: Using dialect: org.hibernate.dialect.SQLServerDialect
Aug 9, 2010 10:13:46 AM org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory
INFO: Using default transaction strategy (direct JDBC transactions)
Aug 9, 2010 10:13:46 AM org.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
INFO: No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
Aug 9, 2010 10:13:46 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic flush during beforeCompletion(): disabled
Aug 9, 2010 10:13:46 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic session close at end of transaction: disabled
Aug 9, 2010 10:13:46 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Scrollable result sets: enabled
Aug 9, 2010 10:13:46 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC3 getGeneratedKeys(): enabled
Aug 9, 2010 10:13:46 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Connection release mode: auto
Aug 9, 2010 10:13:46 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default batch fetch size: 1
Aug 9, 2010 10:13:46 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Generate SQL with comments: disabled
Aug 9, 2010 10:13:46 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL updates by primary key: disabled
Aug 9, 2010 10:13:46 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL inserts for batching: disabled
Aug 9, 2010 10:13:46 AM org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory
INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
Aug 9, 2010 10:13:46 AM org.hibernate.hql.ast.ASTQueryTranslatorFactory <init>
INFO: Using ASTQueryTranslatorFactory
Aug 9, 2010 10:13:46 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query language substitutions: {}
Aug 9, 2010 10:13:46 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JPA-QL strict compliance: disabled
Aug 9, 2010 10:13:46 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Second-level cache: enabled
Aug 9, 2010 10:13:46 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query cache: disabled
Aug 9, 2010 10:13:46 AM org.hibernate.cfg.SettingsFactory createCacheProvider
INFO: Cache provider: org.hibernate.cache.NoCacheProvider
Aug 9, 2010 10:13:46 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Optimize cache for minimal puts: disabled
Aug 9, 2010 10:13:46 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Structured second-level cache entries: disabled
Aug 9, 2010 10:13:46 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Statistics: disabled
Aug 9, 2010 10:13:46 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Deleted entity synthetic identifier rollback: disabled
Aug 9, 2010 10:13:46 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default entity-mode: pojo
Aug 9, 2010 10:13:46 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Named query checking : enabled
Aug 9, 2010 10:13:46 AM org.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
Aug 9, 2010 10:13:47 AM org.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: Not binding factory to JNDI, no JNDI name configured
Aug 9, 2010 10:13:47 AM org.hibernate.impl.SessionFactoryImpl <init>
SEVERE: Error in named query: login
org.hibernate.MappingException: Unknown entity: finalpkg.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.SessionFactoryImpl.checkNamedQueries(SessionFactoryImpl.java:446)
        at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:352)
        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1294)
        at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:859)
        at finalpkg.HibernateUtil.<clinit>(HibernateUtil.java:24)
        at finalpkg.Main.<clinit>(Main.java:20)
Initial SessionFactory creation failed.org.hibernate.HibernateException: Errors in named queries: login
java.lang.ExceptionInInitializerError
        at finalpkg.HibernateUtil.<clinit>(HibernateUtil.java:28)
        at finalpkg.Main.<clinit>(Main.java:20)
Caused by: org.hibernate.HibernateException: Errors in named queries: login
        at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:365)
        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1294)
        at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:859)
        at finalpkg.HibernateUtil.<clinit>(HibernateUtil.java:24)
        ... 1 more
Could not find the main class: finalpkg.Main.  Program will exit.
Exception in thread "main" Java Result: 1
BUILD SUCCESSFUL (total time: 2 seconds)


Top
 Profile  
 
 Post subject: Re: Exception Error in named query: login
PostPosted: Mon Aug 09, 2010 1:07 am 
Regular
Regular

Joined: Fri Aug 06, 2010 1:49 am
Posts: 102
Location: shynate26@gmail.com
Could not find the main class: finalpkg.Main. Program will exit.

could you check whether the Main class is in right package.

_________________

Cheers!
Shynate
mailto:shynate26@gmail.com
www.CSSCORP.com


Top
 Profile  
 
 Post subject: Re: Exception Error in named query: login
PostPosted: Mon Aug 09, 2010 1:29 am 
Newbie

Joined: Mon Aug 09, 2010 12:48 am
Posts: 6
Thank you for repling,
Both the classes are in same finalpkg package,but getting same error


Top
 Profile  
 
 Post subject: Re: Exception Error in named query: login
PostPosted: Mon Aug 09, 2010 3:58 am 
Regular
Regular

Joined: Fri Aug 06, 2010 1:49 am
Posts: 102
Location: shynate26@gmail.com
Hi santhoush,

See this forum discussion, hope it helps.


viewtopic.php?f=1&t=954800&start=0

---

_________________

Cheers!
Shynate
mailto:shynate26@gmail.com
www.CSSCORP.com


Top
 Profile  
 
 Post subject: Re: Exception Error in named query: login
PostPosted: Mon Aug 09, 2010 5:51 am 
Newbie

Joined: Mon Aug 09, 2010 12:48 am
Posts: 6
Thank you all

i sucessfully got the out put, i have been trying this from last four days and at last it is done..
especially Thank you Synate26
Thank you all once again


Top
 Profile  
 
 Post subject: Re: Exception Error in named query: login
PostPosted: Mon Aug 09, 2010 6:19 am 
Regular
Regular

Joined: Fri Aug 06, 2010 1:49 am
Posts: 102
Location: shynate26@gmail.com
Hi Santhoush,

Post the solution. So that it will be useful in future for others.

thanks.

_________________

Cheers!
Shynate
mailto:shynate26@gmail.com
www.CSSCORP.com


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.