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.  [ 8 posts ] 
Author Message
 Post subject: Working with "entity-name"
PostPosted: Wed Aug 17, 2005 6:30 am 
Newbie

Joined: Mon Aug 15, 2005 8:03 am
Posts: 14
Location: Germany
Hi togehter,

hibernate supports the definition of entity-names for e.g. mapping an object on different tables.

I did it and it works very good by saving objects. I defined several hbm files and gave the same class in different files different entity-name and different table names.

By saving objects, I only need to call saveOrUpdate(ALIAS, object)., where ALIAS is the entity-name depend on the value of an attribute of the object to be saved.

Because instances of the same object are stored in different tables, I need the same machanism by deleting them, but I don't know any way to specify an ALIAS by deleting.

How can I solve the problem?

Thanks,
Reza


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 17, 2005 9:16 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
session.delete(entityname,object) is there...if not upgrade to later version ;)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 17, 2005 10:08 am 
Newbie

Joined: Mon Aug 15, 2005 8:03 am
Posts: 14
Location: Germany
Hi max,

we are using hibernate 3.0.5. It doesn't support session(name, object). The only method for deleting objects supported by session is delete(object) :-(

Any other idea?

finding objects works correctly.

I don't know, how can say hibernate to get correct table by deleting objects.

Regards,
Reza


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 17, 2005 10:29 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
You'll have to use Hibernate 3.1beta2

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 17, 2005 11:30 am 
Newbie

Joined: Mon Aug 15, 2005 8:03 am
Posts: 14
Location: Germany
hi emmanuel,

first thanks for the hint.

I tried it also with hibernate 3.1 b2. It still doesn't work.

Here is the code for deleting objects:

Code:
public class GenericInstrumentDaoImpl extends HibernateDaoSupport {
public void save(Instrument instrument) {
  if (InstrumentType.BOND.equals(instrument.getInstrumentType())) {
    getHibernateTemplate().saveOrUpdate("BOND", instrument);
  } else if (InstrumentType.WARRANT.equals(instrument.getInstrumentType()))
{
    getHibernateTemplate().saveOrUpdate("WARRANT", instrument);
  } else {
    getHibernateTemplate().saveOrUpdate(instrument);
  }
}

public void delete(Instrument instrument) {
  if (InstrumentType.BOND.equals(instrument.getInstrumentType())) {
    getSession().delete("BOND", instrument);
  } else if (InstrumentType.WARRANT.equals(instrument.getInstrumentType()))
{
    getSession().delete("WARRANT", instrument);
  } else {
    getHibernateTemplate().delete(instrument);
  }
}
}


Saving works well and I don't any trouble with it.

Deleting throws no exception and my unit tests work. But after calling
delete no object is deleted on the database side.

Any idea?

Thanks,
Reza


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 17, 2005 11:44 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Dunno,
transaction?
check org.hibernate.test.typedmanytoone.TypedManyToOneTest.testCreateQuery() to see how your sample differs

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 18, 2005 7:46 am 
Newbie

Joined: Mon Aug 15, 2005 8:03 am
Posts: 14
Location: Germany
Hi again,

thanks. The problem has been solved.

Reza


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 18, 2005 8:51 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Telling people how you solved it, will help future users like you :-)

_________________
Emmanuel


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