-->
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.  [ 6 posts ] 
Author Message
 Post subject: Need Help 'Mapping Exception: Unknown Entity'
PostPosted: Fri Feb 06, 2009 5:07 am 
Beginner
Beginner

Joined: Thu Dec 11, 2008 2:30 am
Posts: 47
Im using Hibernate with Annotations.

This is my entity class;
===============

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;


@Entity
@Table(name="ORDER_OF_SALE")
public class OrderOfSale implements Serializable {

getters and setters goes here.

}


This is my hibernate utilization;
====================

public String hibInsert(Object tblObj) throws Exception{
Session session = null;

AnnotationConfiguration ac = new AnnotationConfiguration();
session = ac.configure().buildSessionFactory().openSession();


if (tblObj != null) {
try {
Transaction beginTransaction = session.beginTransaction();
session.save(tblObj);
beginTransaction.commit();

if (beginTransaction.wasCommitted()) {
return "1210";
//response.sendRedirect("index.jsp");
} else {
return "Operation failed";
}
} catch (HibernateException hbe) {
return "Operation failed " + hbe.toString();
} finally {
session.flush();
session.close();
}
} else {
return "Required fields are not filled";
}
}

;;;;;;;;;;;;;;;;;;;;;

In above function tblObj is saved as POJO. The attribute values want to set to above 'OrderOfSale' class.

Everything is ok, but executing 'session.save(tblObj);' it gives this error message.

'Operation failed org.hibernate.MappingException: Unknown entity: com.aura.data.trn.OrderOfSale'

I think my Entity class has defined well, but i cannot solve this problem.
Please help me.

Thanks,
Dilan Alex


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 06, 2009 7:58 am 
Regular
Regular

Joined: Thu Sep 06, 2007 2:22 am
Posts: 108
Location: Noida,India
Could you please post Hibernate Configuration( hibernate.cfg.xml) also.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 06, 2009 8:03 am 
Regular
Regular

Joined: Fri Jan 30, 2009 10:10 am
Posts: 74
Location: London
I think that it is because in your OrderOfSale class you are using the JPA (javax.persistence) classes, but in your other code you are accessing the native Hibernate Session etc.

If you use JPA, then you should be using an EntityManager instead.


--
Stephen Souness


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 06, 2009 9:10 am 
Regular
Regular

Joined: Thu Sep 06, 2007 2:22 am
Posts: 108
Location: Noida,India
My understanding is that you have added this entity class in Hibernate Configuration file by using <mapping resource="entity class path"/> element.


As you have annotate the entity class by @Entity, you should map it using <mapping class="full entity class path"> in Hibernate Configuration file.
___________________________________________________

If it helps you, please rate the post


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 10, 2009 12:08 am 
Beginner
Beginner

Joined: Thu Dec 11, 2008 2:30 am
Posts: 47
Thank you all of you for reply. I didn't add mapping for the appropriate class.
That is the reason for this problem.

I added mapping for the 'OrderOfSale' class in 'hibernate.cfg.xml'. And problem solved.

regards,
Dilan.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 10, 2009 12:09 am 
Beginner
Beginner

Joined: Thu Dec 11, 2008 2:30 am
Posts: 47
Thank you all of you for reply. I didn't add mapping for the appropriate class.
That is the reason for this problem.

I added mapping for the 'OrderOfSale' class in 'hibernate.cfg.xml'. And problem solved.

regards,
Dilan.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.