-->
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.  [ 5 posts ] 
Author Message
 Post subject: Annotation based mapping
PostPosted: Wed Dec 19, 2007 7:44 am 
Newbie

Joined: Wed Dec 19, 2007 7:28 am
Posts: 9
I am doing a web application using annotations to map a class and a table instead of using*.hbm.xml file.
The class is like the following:

@Table(name="userprofile")

public class UserDescriptor {
private String user = new String();
private String password = new String();
private String name = new String();
private String email = new String();

public UserDescriptor() {

}
public void setUser(String string) {
user = string;
}

public void setPassword(String string) {
password = string;
}
public void setName(String string) {
name = string;
}

public void setEmail(String string) {
email = string;
}

@Id
@Column(name="user_id")
public String getUser() {
return user;
}

@Column(name="password")
public String getPassword() {
return password;
}

@Column(name="display_name")
public String getName() {
return name;
}

@Column(name="email")
public String getEmail() {
return email;
}
}

And there is a function like the following:

public void insertUser(String user, String password, String name, String email) {
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
Session session = sessionFactory.openSession();
session.beginTransaction();
UserDescriptor userDescriptor = new UserDescriptor();
userDescriptor.setUser(user);
userDescriptor.setPassword(password);
userDescriptor.setName(name);
userDescriptor.setEmail(email);
session.save(userDescriptor);
session.getTransaction().commit();
}

But the problem is that there is an error when calling the above function.The error is

nested exception is org.hibernate.MappingException: Unknown entity: org.springframework.samples.imagedb.UserDescriptor


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 19, 2007 9:11 am 
Regular
Regular

Joined: Sat Nov 25, 2006 11:37 am
Posts: 72
Your entity must also contain the @Entity annotation. @Table alone is not enough.


Top
 Profile  
 
 Post subject: My Mistake on copy paste
PostPosted: Thu Dec 20, 2007 12:07 am 
Newbie

Joined: Wed Dec 19, 2007 7:28 am
Posts: 9
Hi,
I am sorry .Actually it is a problem with copy paste ( missed @Entity at the time of copy paste ).Actually my code contains @Entity before @Table annotation. With @Entity the same error occurs.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 20, 2007 2:02 am 
Regular
Regular

Joined: Sat Nov 25, 2006 11:37 am
Posts: 72
Do you have a persistence.xml file and does that tell Hibernate how to find the entities?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 20, 2007 2:15 am 
Newbie

Joined: Wed Dec 19, 2007 7:28 am
Posts: 9
No I dont have persistence.xml file.From this, I guess I have to import some other packages instead of packages that I have imported in my project.

import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Table;

I imported the above classes .In this case of with out using persistence.xml, please tell me what will be the packages / classes I have to import and what will be the modifications I have to made. Or please tell me what can i do with persistence.xml, how it will be created, its details etc.


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