Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: 3.1.2
I have problems to delete an object instanciated out of Session.
I create an instance of EnCustomer and set it the id (in DB exist a row with this id).
When I call managerDao.delete(customer) in another Session,
Hibernate thrown a MappingException Unknown entity.
If I delete entity-name="EnCustomer" from EnCustomer.hbm.xml file then the deleting operation is performed successfully.
Why I can't use entity-name in my mapping file ?
Mapping documents: EnCustomer.hbm.xml
<hibernate-mapping>
<class name="com.prova.sibo.EnCustomer" table="EN_CUSTOMER" schema="HSIM" entity-name="EnCustomer">
<id name="id" type="integer">
<column name="EN_CUS_ID" precision="22" scale="0" />
<generator class="native">
<param name="sequence">EN_CUS_SEQ</param>
</generator>
</id>
<property name="description" type="string">
<column name="EN_CUS_DESCRIPTION" length="1024" />
</property>
<property name="modificationDate" type="date">
<column name="EN_CUS_MODIFICATION_DATE" length="7" />
</property>
</class>
</hibernate-mapping>
Code :
public class CustomerManagerDao {
private static SessionFactory sessionFactory;
static {
sessionFactory = new Configuration().configure().buildSessionFactory();
}
public static void main(String[] args) throws Exception {
Session session = null;
Transaction tx = null;
try {
// Create a transient instance
EnCustomer customer = new EnCustomer();
customer.setId(10);
session = sessionFactory.openSession();
tx = session.beginTransaction();
session.delete(customer);
tx.commit();
} catch (HibernateException e) {
tx.rollback();
e.printStackTrace();
} finally {
if (session != null)
session.close();
}
// Close the SessionFactory
sessionFactory.close();
}
Full stack trace of exception that occurs:
org.hibernate.MappingException: Unknown entity: com.prova.sibo.EnCustomer
at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:514)
at org.hibernate.impl.SessionImpl.getEntityPersister(SessionImpl.java:1302)
at org.hibernate.event.def.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:59)
at org.hibernate.impl.SessionImpl.fireDelete(SessionImpl.java:761)
at org.hibernate.impl.SessionImpl.delete(SessionImpl.java:739)
at com.prova.sibo.CustomerManagerDao.main(CustomerManagerDao.java:32)
Name and version of the database : Oracle 10
Problems with Session and transaction handling?
Read this:
http://hibernate.org/42.html