-->
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.  [ 2 posts ] 
Author Message
 Post subject: Change a superclass to a subclass using joined-subclas(xdocl
PostPosted: Tue Apr 25, 2006 8:19 am 
Newbie

Joined: Tue Apr 25, 2006 7:52 am
Posts: 1
I have a joined-subclass where I want to "upgrade" the superclass to the subclass. I cannot delete the superclass because of constaints and I also cannot evict the superclass and persist the subclass because the subclass is in the database already

One solution is to update using plain sql, but the sql is never commited.
I can see that posgres is prepering the insert statement
See code below.

Does anybody hav an idea how to upgrade the subclass? or why I cannot commit?

I am using xdoclet which is limiting my mapping options
I am using jboss4.0.3SP1
Hibernate version:
3.1
Mapping documents:
xdoclet-hibernate-module 1.2.3
Code between sessionFactory.openSession() and session.close():


Code:
   
        getSession().flush();
       
       
       
        try {
            Session mySession = getSession().getSessionFactory().openSession();
            Transaction transaction = mySession.beginTransaction();
            Connection conn = mySession.connection();
            Statement stmt = conn.createStatement();
            String  sql =  "insert into the_table(id, description, category_name) values(444444,'de','na')";

            int rows = stmt.executeUpdate(sql);

            conn.commit();
            transaction.commit();
            stmt.close();
            mySession.flush();
            mySession.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
       
       

Full stack trace of any exception that occurs:

Name and version of the database you are using:
PostgreSQL\8.1
The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:

[code]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 26, 2006 12:35 am 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
If you ever need to change the class of an object in this way, then you shouldn't be using inheritance. Switch to delegation, and get rid of all subclassing.

I don't know whether or not hibernate actually allows you to do this, but if it doesn't then I'll be happy. You simply should not try to change the class of anything, in an object-oriented application. Classes model the "is-a" relationship: a thing is-a Car or it is-a BufferedInputStream. No amount of fiddling around with your car is going to make it a BufferedInputStream.

Delegation models the has-a relationship. A thing may have-a Car and have-a BufferedInputStream at the same time, no worries. (No, I don't know what you'd use a Car and BufferedInputStream together for, but at least you're not trying to change your Car into a BufferedInputStream.)


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