-->
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.  [ 1 post ] 
Author Message
 Post subject: Problems deleting a transient object mapped with entity-name
PostPosted: Thu Sep 07, 2006 5:39 am 
Newbie

Joined: Tue Aug 29, 2006 3:07 am
Posts: 2
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.