Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Generic Hibernate dao

843793Feb 9 2009 — edited Apr 3 2009
Hi, I have been working with a generic HibernateDao to which I pass the entity type through a constructor parameter, and it works perfectly. I ran into a [SpringSource team blog|http://blog.springsource.com/2006/09/29/exploiting-generics-metadata/] by Rob Harrop that explained how to determine the actual type of the parameter at runtime. I also found a [page on the Hibernate documentation|http://www.hibernate.org/328.html] that explained the same concept. I used Robs version for my own GenericDao:
public class HibernateDao<E> implements GenericDao<E> {

    private SessionFactory sessionFactory;
    private Class<E> entityClass;

    public HibernateDao() {
        entityClass = extractTypeParameter(getClass());
    }

   // All sorts of DAO  methods 
   ...

   private Class extractTypeParameter(Class<? extends GenericDao> genericDaoType) {
        Type[] genericInterfaces = genericDaoType.getGenericInterfaces();
        // find the generic interface declaration for GenericDao<E>
        ParameterizedType genericInterface = null;
        for (Type t : genericInterfaces) {
            if (t instanceof ParameterizedType) {
                ParameterizedType pt = (ParameterizedType)t;
                if (GenericDao.class.equals(pt.getRawType())) {
                    genericInterface = pt;
                    break;
                }
            }
        }
        if(genericInterface == null) {
            throw new IllegalArgumentException("Type '" + genericDaoType
               + "' does not implement GenericDao<E>.");
        }
        return (Class)genericInterface.getActualTypeArguments()[0];
    }
}
and ran into a ClassCastException: sun.reflect.generics.reflectiveObjects.TypeVariableImpl cannot be cast to java.lang.Class for the line with the return statement. It seems they both implement the Type interface, but they are no subclasses of each other. These articles must have been read and tried by numerous people and I found other sites that implement the same thing, what am I doing wrong to get this exception?

Edited by: Peetzore on 9-feb-2009 14:45

Comments

John Thorton

4130935 wrote:

Hello

I just did an upgrade from 12.1 to 12.2 using dbua however I realized that compatible parameter is still set 12.1.0.2.0 although it was upgraded to 12.2

Why didnt dbua change this parameter ? Is it because the flashback was on ?

Oracle  did NOT change COMPATIBLE parameter because it assumed that since you explicitly set it (as opposed to taking Oracle default), that you wanted it set to 12.1.0.2 & left it for you to change it. Problem Exists Between Keyboard And Chair.

TK03

Hi John,

Does it mean that any upgrades with dbua, the compatible parameter will always be same ? DBUA will never change that parameter

John Thorton

4130935 wrote:

Hi John,

Does it mean that any upgrades with dbua, the compatible parameter will always be same ? DBUA will never change that parameter

IMO, you are asking the WRONG question.

What does DBUA do when COMPATIBLE is NOT set to any value & the upgrade is performed?

TK03

Compatible is set to 12.1.0.2

After the upgrade with dbua

It is still same.

I thought dbua will change it 12.2.0.1 once the upgrade is finished

John Thorton

4130935 wrote:

Compatible is set to 12.1.0.2

After the upgrade with dbua

It is still same.

I thought dbua will change it 12.2.0.1 once the upgrade is finished

Oracle & reality demonstrated that you thought wrongly.

yoonas

Hi,

You should have spent little more time reading upgrade guide, it has well depth of information.

When to Set the COMPATIBLE Initialization Parameter in Oracle Database

When to Set the COMPATIBLE Initialization Parameter in Oracle Database

Oracle recommends increasing the COMPATIBLE parameter only after you have completed testing the upgraded database.

After the upgrade is complete, you can increase the setting of the COMPATIBLE initialization parameter to the maximum level for Oracle Database 12c. However, after you increase the COMPATIBLE parameter, you cannot subsequently downgrade the database.

Regards,

Yoonas

TK03

1-) does it mean that once i increase the COMPATIBLE parameter, I can never downgrade the database ?

2-) Assume I enabled flashback database before the upgrade and after the upgrade I increased the COMPATIBLE parameter.  Can i still flashback database to before upgrade state ?

dvohra21

To downgrade, first decrease the COMPATIBLE parameter.

John Thorton

dvohra21 wrote:

To downgrade, first decrease the COMPATIBLE parameter.

What happens when a feature that exists in the higher version (& has been used)  does NOT exist in the lower version & attempt a downgrade?

TK03

Hi John,

so once i increase the COMPATIBLE parameter, there is no way to downgrade ?

yoonas

What Is Oracle Database Compatibility?

Downgrading Oracle Database to an Earlier Release

6 Downgrading Oracle Database to an Earlier Release

For supported releases of Oracle Database, you can downgrade a database to the release from which you last upgraded. For example, if you recently upgraded from release 11.2.0.4 to Oracle Database 12c, and you did not change the compatible initialization parameter to 12.1 or higher, then you can downgrade to release 11.2.0.4. If your Oracle Database 12c is release 12.1.0.2, and you did not change the compatible initialization parameter to 12.1.0.2, then you can downgrade to release 12.1.0.1 and so forth.

dvohra21

Seems like not.

"You cannot downgrade a database once you have set the compatible initialization parameter to 12.1.0.2."

1 - 12
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on May 1 2009
Added on Feb 9 2009
4 comments
699 views