Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Spring Framework | Web Services | BioInformatics | Java Server Faces | Jboss 3.0 tutorial | Hibernate 3.0 | XML

Tutorial Categories: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML


 

Java Tutorials


 

 

Struts Tutorials

Struts Resources

Visit Forum! Post Questions!
Jobs At RoseIndia.net!

Hibernate Exception, Hibernate Hibernateannotations Index

User Comments
Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl
  Blink   Furl   Simpy   Y! MyWeb 

;
 
Java Examples for Beginners
Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

1 comments so far (post your own) View All Comments Latest 10 Comments:

This is my Annotations Classs

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.NamedQuery;
import javax.persistence.Table;







/**
*
* @author sachin
*/
@Entity
@Table(name = "Username")
@NamedQuery(name="USERNAME",query="from Username where NAME= :name")
public class Username implements Serializable {
/**
*This is a Persistence class for table Username
*
*/
@Id
@GeneratedValue
private int Id;
public int getId() {
return Id;
}

public void setId(int Id) {
this.Id = Id;
}

@Column(name="NAME", length=40)
private String NAME;
public String getNAME() {
return NAME;
}

public void setNAME(String NAME) {
this.NAME = NAME;
}

}


this is my class for get USERNAME Value

pub statioc void main (String s[])
{
Query q = null;
int obi = 0;
try
{

config = new AnnotationConfiguration();
sessionFactory = config.configure().buildSessionFactory();
Session s = sessionFactory.openSession();
Transaction tr = s.beginTransaction();
q = (Query) s.getNamedQuery("USERNAME").setString("name", Sachin).uniqueResult();


ArrayList list = (ArrayList) q.list();
Iterator it = list.iterator();
while(it.hasNext())
{
Username log = (Username)it.next();
Id = log.gettId();

}
System.out.println(" Id ::::::::::::::::::::::: " + obi);
tr.commit();
}catch(Exception e)
{
e.printStackTrace();
System.out.println("Check Exception");

}
finally
{
s.close();
}

}


My Hibernate.cfg.xml file is


<?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.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:3306/databasel</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">root</property>
<property name="hibernate.connection.pool_size">1</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<property name="hibernate.current_session_context_class">thread</property>
<property name="hibernate.hbm2ddl.auto">none</property>
<mapping class="com.Username" package="com.Username"/>
</session-factory>
</hibernate-configuration>




When i run his code i got
org.hibernate.MappingException: Named query not known: NAME
org.hibernate.impl.AbstractSessionImpl.getNamedQuery(AbstractSessionImpl.java:70)
at org.hibernate.impl.SessionImpl.getNamedQuery(SessionImpl.java:1260)exception please tell me where i wrong

thanks in advance

Posted by sachinajmani on Tuesday, 08.11.09 @ 17:40pm | #89948

Ask programming questions?

 

 

Back to Tutorial
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification

Tell A Friend
Your Friend Name

 

 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright 2007. All rights reserved.