Forums Register Login

using annotation wiith Spring Please help

+Pie Number of slices to send: Send
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;
}


}
+Pie Number of slices to send: Send
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
Live a little! The night is young! And we have umbrellas in our drinks! This umbrella has a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 2254 times.
Similar Threads
HibernateException: No Hibernate Session bound to thread
unsatisfied Dependancy exception
Hibernate : Empty Table recreated when spring starts
using ehcache with hibernate please answer this
Hibernate - Spring integration problem
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 07:04:27.