I am using mysql, I wrote a piece of code:
public class User {
private long userID;
private String userName;
private String password;
private String emailAddress;
...
}
public class HiTest {
public static void main(String[] args) throws Exception {
SessionFactory sf = cfg.buildSessionFactory();
Session session = sf.openSession();
Transaction tx = session.beginTransaction();
User user = new User();
user.setID(1);
user.setName("Somebody");
user.setPassword("password");
user.setEmailAddress("email@email.com");
session.save(user);
}
and have the exception:
.....
16:22:17,524 INFO SettingsFactory:203 - Query cache: disabled
16:22:17,534 INFO SettingsFactory:214 - Statistics: disabled
16:22:17,534 INFO SettingsFactory:218 - Deleted entity synthetic identifier rol
lback: disabled
16:22:17,534 INFO SettingsFactory:232 - Default entity-mode: pojo
16:22:17,844 INFO SessionFactoryImpl:140 - building session factory
16:22:17,864 INFO SessionFactoryObjectFactory:82 - Not binding factory to JNDI,
no JNDI name configured
16:22:17,864 INFO SessionFactoryImpl:366 - Checking 0 named queries
Exception in thread "main" org.hibernate.MappingException: Unknown entity: User
at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFacto
ryImpl.java:489)
at org.hibernate.impl.SessionImpl.getEntityPersister(SessionImpl.java:10
21)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId
(AbstractSaveEventListener.java:83)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGene
ratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:184)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrR
equestedId(DefaultSaveEventListener.java:33)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTran
sient(DefaultSaveOrUpdateEventListener.java:173)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(
DefaultSaveEventListener.java:27)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpda
te(DefaultSaveOrUpdateEventListener.java:69)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:429)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:424)
at HiTest.main(HiTest.java:40)
Is it due to configuration or coding?
|