• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

using annotation wiith Spring Please help

 
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
i am trying to convert my app which was using hbm.xml config files to annotation. the following is the application context.xml file
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource"><ref local="dataSource"/></property>

<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
</props>
</property>

<property name="annotatedClasses">
<list>
<value>com.hyderabad.model.Category</value>
</list>
</property>
</bean>
As you can see i am using annotaion session factory bean and specificying my annotated classes. when I run the project and try to get category objects its giving the following error.
Category is not mapped [from Category category where category.parentCategoryId = 0]; nested exception is org.hibernate.hql.ast.QuerySyntaxException: Category is not mapped [from Category category where category.parentCategoryId = 0]

What am i doing wrong,
my Category class is listed below, please also chekc if i am using hte correct hiberate packages, i went through many threads, is there some other configuration i need to do. I dont think i need hibernate.cfg.xml anymore since i am trying to put everything in the spring application context file.

/*
* Category.java
*
* Created on June 3, 2008, 4:11 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/

package com.hyderabad.model;

import java.util.List;
import java.io.*;
import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import org.hibernate.annotations.Entity;

@Entity
@Table(name="category")
public class Category implements Serializable {

/** Creates a new instance of Category */
public Category() {
}


private int categoryId = 0;
private String categoryName = null;
private int parentCategoryId = 0;


@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="category_id")
public int getCategoryId() {
return categoryId;
}

public void setCategoryId(int categoryId) {
this.categoryId = categoryId;
}

@Column(name="category_name")
public String getCategoryName() {
return categoryName;
}

public void setCategoryName(String categoryName) {
this.categoryName = categoryName;
}

@Column(name="parent_category_id")
public int getParentCategoryId() {
return parentCategoryId;
}

public void setParentCategoryId(int parentCategoryId) {
this.parentCategoryId = parentCategoryId;
}


}
 
Darvesh Niz
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok guys sorted out. just for anyone else who is struggling with this here is the answer.
i pasted the application-context.xml file below
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource"><ref local="dataSource"/></property>

<property name="configLocation">
<value>WEB-INF/hibernate.cfg.xml</value>
</property>
<property name="configurationClass">
<value>org.hibernate.cfg.AnnotationConfiguration</value>
</property>
<property name="annotatedClasses">
<list>
<value>com.hyderabad.model.Category</value>
</list>
</property>
</bean>

My hibernate.cfg.xml file is empty it has nothing in it. You can try to remove the configlocation property setter and try it if it works or not.


Thanks
Rashid
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic